






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
algorithms and complexity full course
Typology: Lecture notes
1 / 30
This page cannot be seen from the preview
Don't miss anything!























2, 56, 4, -7, 0, 78, -45, 10 -45, 56, 4, -7, 0, 78, 2, 10 -45, 56, 4, -7, 0, 78, 2, 10 -45, -7, 4, 56, 0, 78, 2, 10 -45, -7, 4, 56, 0, 78, 2, 10 -45, -7, 0, 4, 56, 78, 2, 10 …
Algorithme
Pour i2 à n faire
ji; tantque (j>1) et (T[j]<T[j-1]) faire échanger(T[j], T[j-1]); jj-1; fait; fait;
Comme les bulles, les plus grands éléments remontent en fin de liste. 2, 56, 4, -7, 0, 78, -45, 10 2, 4, -7, 0, 56, -45, 10, 78 2, -7, 0, 4, -45, 10, 56, 78 -7, 0, 2, -45, 4, 10, 56, 78 -7, 0, -45, 2, 4, 10, 56, 78 -7, -45, 0, 2, 4, 10, 56, 78 -45, -7, 0, 2, 4, 10, 56, 78
Exemple: 2, 56, 4, 7, 40, 78, 65, 45 2, 4, 7, 40, 56, 65, 45, 78 2, 4, 7, 40, 56, 45, 65, 78 2, 4, 7, 40, 45, 56, 65, 78 2, 4, 7, 40, 45, 56, 65, 78 2, 4, 7, 40, 45, 56, 65, 78 2, 4, 7, 40, 45, 56, 65, 78
boolvrai; /* quand il n’y a aucun échange le tableau est trié*/ i1; Tantque (bool=vrai) faire boolfaux; Pour j :=1 à n-i faire Si (A[j]> A[j+1]) alors échanger(A[j], A[j+1]); boolvrai; Fsi ; Fait ; ii+1; Fait ;
Tri fusion et tri Rapide
MergeSort QuickSort
5 3 2 9 4 6 5 3 2 9 4 6
2 3 4 5 6 9 2 3 4 5 6 9
5 3 2 9 4 6 5
2 3 5 4 6 9
3 2 4 9 6
2 3 4 5 6 9
= pivot - Mettre ensemble: ≤pivot + (pivot) + ≥pivot
Fonction partition(E/T:tableau[n] entiers, d, f : entier):entier
i, j, pivot : entier;
Début pivot T[d]; id; jf;
Tantque (i < j) faire
Tantque (i ≤ f) et (T[i] ≤ pivot) faire ii+1; fait; Tantque (j>d) et (T[j] > pivot) faire jj-1; fait; si (i < j) alors permuter(T, i, j); ii+1; jj-1; fsi; fait; si (d≠j) alors permute(T, d, j); fsi; retourner j;
Fin;
Tri Rapide (QuickSort)
pivot T[d]; id; jf; tantque (i < j) faire tantque (i ≤ f) et (T[i] ≤ pivot) faire ii+1; fait; tantque (j>d) et (T[j] > pivot) faire jj-1; fait; si (i < j) alors permuter(T, i, j); ii+1; jj-1; fsi; fait; si (d≠j) alors permute(T, d, j); fsi; retourner j; Fin;
Arbre binaire de recherche (ABR) le parcours en
infixé permet d’afficher les valeurs dans l’ordre
croissant (ou décroissant) O(nlogn).
Inconvénient : espace mémoire occupé
Tri Dénombrement