Skip to content
Snippets Groups Projects
Commit 60556cd7 authored by Kinadinova Dariya's avatar Kinadinova Dariya
Browse files

tri_sort

parent c05172cb
No related branches found
No related tags found
No related merge requests found
...@@ -2,101 +2,101 @@ taille;"tri séléction";"tri insertion" ...@@ -2,101 +2,101 @@ taille;"tri séléction";"tri insertion"
0; 0.00; 0.00 0; 0.00; 0.00
1; 0.00; 0.00 1; 0.00; 0.00
2; 1.00; 1.00 2; 1.00; 1.00
3; 3.00; 2.54 3; 3.00; 2.66
4; 6.00; 4.94 4; 6.00; 4.84
5; 10.00; 7.74 5; 10.00; 8.02
6; 15.00; 10.94 6; 15.00; 10.46
7; 21.00; 15.12 7; 21.00; 15.74
8; 28.00; 18.32 8; 28.00; 19.30
9; 36.00; 24.46 9; 36.00; 25.44
10; 45.00; 28.74 10; 45.00; 28.44
11; 55.00; 36.26 11; 55.00; 34.82
12; 66.00; 42.60 12; 66.00; 42.02
13; 78.00; 47.62 13; 78.00; 48.54
14; 91.00; 55.40 14; 91.00; 55.16
15; 105.00; 64.76 15; 105.00; 66.28
16; 120.00; 75.72 16; 120.00; 73.12
17; 136.00; 81.50 17; 136.00; 79.96
18; 153.00; 93.78 18; 153.00; 92.14
19; 171.00; 99.70 19; 171.00; 99.98
20; 190.00; 108.00 20; 190.00; 112.58
21; 210.00; 121.72 21; 210.00; 122.30
22; 231.00; 136.70 22; 231.00; 136.20
23; 253.00; 148.32 23; 253.00; 149.02
24; 276.00; 154.62 24; 276.00; 159.28
25; 300.00; 177.60 25; 300.00; 171.26
26; 325.00; 185.98 26; 325.00; 188.90
27; 351.00; 195.04 27; 351.00; 196.46
28; 378.00; 214.66 28; 378.00; 213.12
29; 406.00; 228.92 29; 406.00; 224.26
30; 435.00; 243.02 30; 435.00; 245.64
31; 465.00; 263.00 31; 465.00; 259.88
32; 496.00; 278.32 32; 496.00; 279.32
33; 528.00; 300.08 33; 528.00; 290.44
34; 561.00; 313.08 34; 561.00; 317.86
35; 595.00; 332.32 35; 595.00; 333.44
36; 630.00; 347.46 36; 630.00; 336.84
37; 666.00; 363.56 37; 666.00; 373.86
38; 703.00; 385.38 38; 703.00; 390.18
39; 741.00; 402.26 39; 741.00; 411.06
40; 780.00; 431.92 40; 780.00; 422.26
41; 820.00; 449.30 41; 820.00; 437.46
42; 861.00; 468.26 42; 861.00; 472.16
43; 903.00; 482.66 43; 903.00; 486.10
44; 946.00; 514.60 44; 946.00; 506.98
45; 990.00; 547.12 45; 990.00; 532.68
46; 1035.00; 558.56 46; 1035.00; 558.56
47; 1081.00; 591.68 47; 1081.00; 587.18
48; 1128.00; 596.86 48; 1128.00; 606.10
49; 1176.00; 638.16 49; 1176.00; 631.00
50; 1225.00; 662.70 50; 1225.00; 669.22
51; 1275.00; 682.62 51; 1275.00; 687.82
52; 1326.00; 707.10 52; 1326.00; 716.20
53; 1378.00; 754.44 53; 1378.00; 744.82
54; 1431.00; 758.76 54; 1431.00; 779.66
55; 1485.00; 804.98 55; 1485.00; 784.60
56; 1540.00; 815.14 56; 1540.00; 817.60
57; 1596.00; 856.56 57; 1596.00; 841.68
58; 1653.00; 857.58 58; 1653.00; 884.94
59; 1711.00; 914.12 59; 1711.00; 911.00
60; 1770.00; 921.60 60; 1770.00; 952.36
61; 1830.00; 983.40 61; 1830.00; 969.26
62; 1891.00; 987.16 62; 1891.00; 1016.92
63; 1953.00; 1037.34 63; 1953.00; 1033.92
64; 2016.00; 1086.56 64; 2016.00; 1061.48
65; 2080.00; 1084.88 65; 2080.00; 1082.60
66; 2145.00; 1158.24 66; 2145.00; 1148.86
67; 2211.00; 1172.10 67; 2211.00; 1151.72
68; 2278.00; 1185.94 68; 2278.00; 1189.32
69; 2346.00; 1220.80 69; 2346.00; 1247.46
70; 2415.00; 1292.92 70; 2415.00; 1249.00
71; 2485.00; 1308.74 71; 2485.00; 1312.82
72; 2556.00; 1343.22 72; 2556.00; 1338.22
73; 2628.00; 1390.08 73; 2628.00; 1382.14
74; 2701.00; 1428.48 74; 2701.00; 1416.98
75; 2775.00; 1445.40 75; 2775.00; 1463.36
76; 2850.00; 1475.92 76; 2850.00; 1515.78
77; 2926.00; 1534.34 77; 2926.00; 1552.44
78; 3003.00; 1604.52 78; 3003.00; 1592.64
79; 3081.00; 1610.94 79; 3081.00; 1626.36
80; 3160.00; 1674.74 80; 3160.00; 1655.74
81; 3240.00; 1693.34 81; 3240.00; 1672.96
82; 3321.00; 1729.02 82; 3321.00; 1740.14
83; 3403.00; 1799.78 83; 3403.00; 1761.00
84; 3486.00; 1800.70 84; 3486.00; 1806.66
85; 3570.00; 1884.10 85; 3570.00; 1870.12
86; 3655.00; 1954.98 86; 3655.00; 1906.36
87; 3741.00; 1964.98 87; 3741.00; 1950.14
88; 3828.00; 2012.42 88; 3828.00; 2011.50
89; 3916.00; 2011.72 89; 3916.00; 2083.56
90; 4005.00; 2080.66 90; 4005.00; 2085.50
91; 4095.00; 2147.18 91; 4095.00; 2159.10
92; 4186.00; 2161.90 92; 4186.00; 2186.72
93; 4278.00; 2216.44 93; 4278.00; 2220.78
94; 4371.00; 2290.34 94; 4371.00; 2287.80
95; 4465.00; 2347.26 95; 4465.00; 2303.56
96; 4560.00; 2389.54 96; 4560.00; 2357.14
97; 4656.00; 2413.08 97; 4656.00; 2434.12
98; 4753.00; 2483.92 98; 4753.00; 2458.50
99; 4851.00; 2523.12 99; 4851.00; 2548.74
100; 4950.00; 2608.62 100; 4950.00; 2597.96
...@@ -41,7 +41,7 @@ def analyser_tri(tri: Callable[[list[T], Callable[[T, T], int]], NoneType], ...@@ -41,7 +41,7 @@ def analyser_tri(tri: Callable[[list[T], Callable[[T, T], int]], NoneType],
res += compare.counter res += compare.counter
return res / nbre_essais return res / nbre_essais
def tri_comp(l:list[T], comp: Callable[[T, T], int] = compare): def tri_sort(l:list[T], comp: Callable[[T, T], int] = compare):
"""à_remplacer_par_ce_que_fait_la_fonction """à_remplacer_par_ce_que_fait_la_fonction
Précondition : Précondition :
...@@ -61,15 +61,13 @@ if (__name__ == '__main__'): ...@@ -61,15 +61,13 @@ if (__name__ == '__main__'):
TAILLE_MAX = 100 TAILLE_MAX = 100
c_select = [0.0] * (TAILLE_MAX + 1) c_select = [0.0] * (TAILLE_MAX + 1)
c_insert = [0.0] * (TAILLE_MAX + 1) c_insert = [0.0] * (TAILLE_MAX + 1)
# creating c_sort
c_sort = [0.0] * (TAILLE_MAX +1) c_sort = [0.0] * (TAILLE_MAX +1)
for t in range(TAILLE_MAX + 1): for t in range(TAILLE_MAX + 1):
c_select[t] = analyser_tri(tri_select, 1, t) c_select[t] = analyser_tri(tri_select, 1, t)
# inutile de moyenner pour le tri par sélection # inutile de moyenner pour le tri par sélection
c_insert[t] = analyser_tri(tri_insert, NB_ESSAIS, t) c_insert[t] = analyser_tri(tri_insert, NB_ESSAIS, t)
# for sorting c_sort[t] = analyser_tri(tri_sort, NB_ESSAIS, t)
c_sort[t] = analyser_tri(tri_comp, NB_ESSAIS, t)
# Sauvegarde des données calculées dans un fichier au format CSV # Sauvegarde des données calculées dans un fichier au format CSV
prem_ligne = 'taille;"tri séléction";"tri insertion"\n' prem_ligne = 'taille;"tri séléction";"tri insertion"\n'
......
...@@ -4,6 +4,10 @@ import matplotlib.pyplot as plt ...@@ -4,6 +4,10 @@ import matplotlib.pyplot as plt
from analyse_tris import tri_select from analyse_tris import tri_select
from math import sqrt from math import sqrt
from analyse_tris import analyser_tri from analyse_tris import analyser_tri
from typing import Callable
from compare import compare
from ap_decorators import count
from tris import *
# Préliminaires # Préliminaires
...@@ -20,29 +24,25 @@ def liste_alea(n: int) -> list[int]: ...@@ -20,29 +24,25 @@ def liste_alea(n: int) -> list[int]:
return l return l
# Évaluation expérimentale de la complexité en temps # Évaluation expérimentale de la complexité en temps
TAILLE_MAX = 100 compare = count(compare)
L = []
T = []
for t in range(1, TAILLE_MAX + 1): def analyser_tri(tri: Callable[[list[T], Callable[[T, T], int]], NoneType],
rlist = liste_alea(t) nbre_essais: int,
time = timeit.timeit(stmt='tri_select(l)', setup='from __main__ import tri_select, l', globals={'l': rlist}, number=5000) taille: int) -> float:
L.append(t) """
times.append(time) renvoie: le nombre moyen de comparaisons effectuées par l'algo tri
pour trier des listes de taille t, la moyenne étant calculée
plt.plot(lengths, times, label='Selection Sort') sur n listes aléatoires.
plt.xlabel('Length of List') précondition: n > 0, t >= 0, la fonc
plt.ylabel('Time (s)') """
plt.title('Selection Sort Execution Time') res = 0
plt.legend() for i in range(nbre_essais):
plt.grid(True) compare.counter = 0
plt.show() l = [k for k in range(taille)]
shuffle(l)
#3 tri(l, compare)
import timeit res += compare.counter
import matplotlib.pyplot as plt return res / nbre_essais
import random
from analyse_tris import tri_insert
Nmax = 100 Nmax = 100
number = 5000 number = 5000
...@@ -80,8 +80,3 @@ plt.legend() ...@@ -80,8 +80,3 @@ plt.legend()
plt.grid(True) plt.grid(True)
plt.show() plt.show()
tp7/tris_nbcomp.png

28.7 KiB | W: | H:

tp7/tris_nbcomp.png

28.9 KiB | W: | H:

tp7/tris_nbcomp.png
tp7/tris_nbcomp.png
tp7/tris_nbcomp.png
tp7/tris_nbcomp.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment