Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4dd76ecf9e | |||
| 977ddbd804 | |||
| 1b37a3ec15 | |||
| b040a0aa68 | |||
| bb22575487 | |||
| 2fe5a1582d | |||
| 9c5c965e95 | |||
| 06d4e9cb97 | |||
| d84b0017a7 |
+25
@@ -0,0 +1,25 @@
|
|||||||
|
def tri_par_selection(tableau):
|
||||||
|
n = len(tableau)
|
||||||
|
for i in range(n):
|
||||||
|
min_index = i
|
||||||
|
for j in range(i + 1, n):
|
||||||
|
if tableau[j] < tableau[min_index]:
|
||||||
|
min_index = j
|
||||||
|
tableau[i], tableau[min_index] = tableau[min_index], tableau[i]
|
||||||
|
return tableau
|
||||||
|
|
||||||
|
def triJL(tableau):
|
||||||
|
for i in range(len(tableau)):
|
||||||
|
tableau[i] = tri_par_selection(tableau[i])
|
||||||
|
|
||||||
|
for i in range(len(tableau)):
|
||||||
|
for j in range(i + 1, len(tableau)):
|
||||||
|
if sum(tableau[j]) < sum(tableau[i]):
|
||||||
|
tableau[i], tableau[j] = tableau[j], tableau[i]
|
||||||
|
|
||||||
|
return tableau
|
||||||
|
|
||||||
|
tableau = [[0, 3, 2], [9, 4, 5], [4, 1, 3]]
|
||||||
|
print("tableau avant triage : ", tableau)
|
||||||
|
resultat = triJL(tableau)
|
||||||
|
print("Tableau trié :", resultat)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
## Exo 2
|
||||||
|
function 1 = O(n*m) car elle parcourt chaque élément du tableau 1 puis du tableau 2
|
||||||
|
function 2 = O(x) car c'est une boucle while qui décrémente jusqu'a 0 et ou il n'y a que une complexité de O(1)
|
||||||
|
function 3 = O(1) car chaque condition est exécutée une seule fois ou l'opération n'a qu'une complexité de O(1)
|
||||||
|
## Exo 3
|
||||||
|
Soit N = nombre itération pour grades_number et ou sa complexité est O(1) donc O(N)
|
||||||
|
Soit E = nombre itération pour copier les notes des étudiants et ou sa compléxité est O(1) donc O(E)
|
||||||
|
|
||||||
|
On appelle BubbleSort, qui a une compléxité de O(E²), car il est appelé pour trier le tableau et est aussi appelé dans find_rank_student
|
||||||
|
Chaque appel a find_rank_student fait un tri avec BubbleSort O(E²) dans le tableau trié O(E)
|
||||||
|
Ce qui donnerait E*O(E²)=O(E^3)?
|
||||||
|
Donc au total avec la boucle N, cela nous donnerait O(E^3 * N)
|
||||||
|
|
||||||
|
## Exo 4
|
||||||
|
Chaque sous-tableau de N éléments est trié en ordre croissant avec un tri par sélection, qui a une compléxité de O(N²).
|
||||||
|
Comme il y a M nombre de sous tableau, alors la compléxité est de O(N²*M)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user