Skip to content
Snippets Groups Projects
Verified Commit 080abb51 authored by orestis.malaspin's avatar orestis.malaspin
Browse files

updated pseudocodes to rfench

parent 1f67f0fa
No related branches found
No related tags found
No related merge requests found
......@@ -22,11 +22,11 @@ double tab[N];
. . .
```C
double moyenne = 0.0;
double mean = 0.0;
for (int i = 0; i < N; ++i) { // N assignations
moyenne += tab[i]; // N additions
mean += tab[i]; // N additions
}
moyenne /= N; // O(N)
mean /= N; // O(N)
```
. . .
......@@ -36,12 +36,12 @@ moyenne /= N; // O(N)
. . .
```C
double moyenne = moyenne(N, tab); // O(N)
double ecart = 0.0;
double mean = moyenne(N, tab); // O(N)
double dev = 0.0;
for (int i = 0; i < N; ++i) {
ecart += pow(tab[i] - moyenne, 2); // N tours
dev += pow(tab[i] - moyenne, 2); // N tours
}
ecart = sqrt(ecart); ecart /= N; // O(2*N) = O(N)
dev = sqrt(dev); dev /= N; // O(2*N) = O(N)
```
# Tri par insertion (1/3)
......@@ -59,7 +59,7 @@ triés du tableau.
# Tri par insertion (2/3)
## Exercice: Proposer un algorithme
## Exercice: Proposer un algorithme (en C)
. . .
......@@ -167,16 +167,14 @@ int low, high; // les indices min/max des tableaux à trier
## Pseudocode: quicksort
```C
void quicksort(array, low, high) {
if (more than 1 elems) {
pivot_ind = partition(array, low, high);
if (something left of pivot)
quicksort(array, low, pivot_ind - 1);
if (something right of pivot)
quicksort(array, pivot_ind + 1, high);
}
}
```python
rien quicksort(entier tableau[], ind_min, ind_max)
si (longueur(tab) > 1)
ind_pivot = partition(array, ind_min, ind_max)
si (longueur(tableau[0:ind_pivot-1]) != 0)
quicksort(tableau, ind_min, pivot_ind - 1);
si (longueur(tableau[ind_pivot+1:ind_max-1]) != 0)
quicksort(tableau, ind_pivot + 1, ind_max)
```
# Tri rapide ou quicksort (5/8)
......@@ -184,20 +182,20 @@ void quicksort(array, low, high) {
## Pseudocode: partition
```C
int partition(array, low, high) {
pivot = array[high]; // choix arbitraire
i = low;
j = high-1;
while i < j {
en remontant i trouver le premier élément > pivot;
en descendant j trouver le premier élément < pivot;
swap(array[i], array[j]);
// les plus grands à droite
// mettre les plus petits à gauche
}
entier partition(entier tableau[], entier ind_min, entier ind_max)
pivot = array[ind_max]; // choix arbitraire
i = ind_min;
j = ind_max-1;
tant que i < j:
en remontant i trouver le premier élément > pivot;
en descendant j trouver le premier élément < pivot;
échanger(array[i], array[j]);
// les plus grands à droite
// mettre les plus petits à gauche
// on met le pivot "au milieu"
swap(array[i], array[pivot]);
return i; // on retourne l'indice pivot
échanger(array[i], array[pivot]);
retourne i; // on retourne l'indice pivot
}
```
......@@ -259,10 +257,10 @@ int partition(int size, int array[size], int first, int last) {
int i = first - 1, j = last;
do {
do {
i++;
i += 1;
} while (array[i] < pivot && i < j);
do {
j--;
j -= 1;
} while (array[j] > pivot && i < j);
if (j > i) {
swap(&array[i], &array[j]);
......@@ -322,20 +320,16 @@ int partition(int size, int array[size], int first, int last) {
. . .
```C
void bubble_sort(int size, int array[]) {
for i in [size-1, 1] {
sorted = true;
for j in [0, i-1] {
if (array[j] > array[j+1]) {
swap(array[j], array[j+1]);
sorted = false;
}
}
if (sorted) {
return;
}
}
}
rien tri_a_bulles(entier tableau[])
pour i de longueur(tableau)-1 à 1:
trié = vrai
pour j de 0 à i-1:
si (tableau[j] > tableau[j+1])
swap(array[j], array[j+1])
trié = faux
si trié
retourner
```
# Tri à bulle (4/4)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment