Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aurelien.boyer
cours
Commits
080abb51
Verified
Commit
080abb51
authored
2 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
updated pseudocodes to rfench
parent
1f67f0fa
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
slides/cours_7.md
+41
-47
41 additions, 47 deletions
slides/cours_7.md
with
41 additions
and
47 deletions
slides/cours_7.md
+
41
−
47
View file @
080abb51
...
@@ -22,11 +22,11 @@ double tab[N];
...
@@ -22,11 +22,11 @@ double tab[N];
. . .
. . .
```
C
```
C
double m
oyenne
= 0.0;
double m
ean
= 0.0;
for (int i = 0; i < N; ++i) { // N assignations
for (int i = 0; i < N; ++i) { // N assignations
m
oyenne
+= tab[i]; // N additions
m
ean
+= tab[i]; // N additions
}
}
m
oyenne
/= N; // O(N)
m
ean
/= N; // O(N)
```
```
. . .
. . .
...
@@ -36,12 +36,12 @@ moyenne /= N; // O(N)
...
@@ -36,12 +36,12 @@ moyenne /= N; // O(N)
. . .
. . .
```
C
```
C
double m
oyenne
= moyenne(N, tab); // O(N)
double m
ean
= moyenne(N, tab); // O(N)
double
ecart
= 0.0;
double
dev
= 0.0;
for (int i = 0; i < N; ++i) {
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)
# Tri par insertion (1/3)
...
@@ -59,7 +59,7 @@ triés du tableau.
...
@@ -59,7 +59,7 @@ triés du tableau.
# Tri par insertion (2/3)
# 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
...
@@ -167,16 +167,14 @@ int low, high; // les indices min/max des tableaux à trier
## Pseudocode: quicksort
## Pseudocode: quicksort
```
C
```
python
void quicksort(array, low, high) {
rien
quicksort
(
entier
tableau
[],
ind_min
,
ind_max
)
if (more than 1 elems) {
si
(
longueur
(
tab
)
>
1
)
pivot_ind = partition(array, low, high);
ind_pivot
=
partition
(
array
,
ind_min
,
ind_max
)
if (something left of pivot)
si
(
longueur
(
tableau
[
0
:
ind_pivot
-
1
])
!=
0
)
quicksort(array, low, pivot_ind - 1);
quicksort
(
tableau
,
ind_min
,
pivot_ind
-
1
);
if (something right of pivot)
si
(
longueur
(
tableau
[
ind_pivot
+
1
:
ind_max
-
1
])
!=
0
)
quicksort(array, pivot_ind + 1, high);
quicksort
(
tableau
,
ind_pivot
+
1
,
ind_max
)
}
}
```
```
# Tri rapide ou quicksort (5/8)
# Tri rapide ou quicksort (5/8)
...
@@ -184,20 +182,20 @@ void quicksort(array, low, high) {
...
@@ -184,20 +182,20 @@ void quicksort(array, low, high) {
## Pseudocode: partition
## Pseudocode: partition
```
C
```
C
i
nt partition(
array, low, high) {
e
nt
ier
partition(
entier tableau[], entier ind_min, entier ind_max)
pivot = array[
high
]; // choix arbitraire
pivot = array[
ind_max
]; // choix arbitraire
i =
low
;
i =
ind_min
;
j =
high
-1;
j =
ind_max
-1;
whil
e i < j
{
tant qu
e i < j
:
en remontant i trouver le premier élément > pivot;
en remontant i trouver le premier élément > pivot;
en descendant j trouver le premier élément < pivot;
en descendant j trouver le premier élément < pivot;
swap
(array[i], array[j]);
échanger
(array[i], array[j]);
// les plus grands à droite
// les plus grands à droite
// mettre les plus petits à gauche
// mettre les plus petits à gauche
}
// on met le pivot "au milieu"
// on met le pivot "au milieu"
swap
(array[i], array[pivot]);
échanger
(array[i], array[pivot]);
return i; // on retourne l'indice pivot
ret
o
urn
e
i; // on retourne l'indice pivot
}
}
```
```
...
@@ -259,10 +257,10 @@ int partition(int size, int array[size], int first, int last) {
...
@@ -259,10 +257,10 @@ int partition(int size, int array[size], int first, int last) {
int i = first - 1, j = last;
int i = first - 1, j = last;
do {
do {
do {
do {
i
++
;
i
+= 1
;
} while (array[i] < pivot && i < j);
} while (array[i] < pivot && i < j);
do {
do {
j
--
;
j
-= 1
;
} while (array[j] > pivot && i < j);
} while (array[j] > pivot && i < j);
if (j > i) {
if (j > i) {
swap(&array[i], &array[j]);
swap(&array[i], &array[j]);
...
@@ -322,20 +320,16 @@ int partition(int size, int array[size], int first, int last) {
...
@@ -322,20 +320,16 @@ int partition(int size, int array[size], int first, int last) {
. . .
. . .
```
C
```
C
void bubble_sort(int size, int array[]) {
rien tri_a_bulles(entier tableau[])
for i in [size-1, 1] {
pour i de longueur(tableau)-1 à 1:
sorted = true;
trié = vrai
for j in [0, i-1] {
pour j de 0 à i-1:
if (array[j] > array[j+1]) {
si (tableau[j] > tableau[j+1])
swap(array[j], array[j+1]);
swap(array[j], array[j+1])
sorted = false;
trié = faux
}
}
si trié
if (sorted) {
retourner
return;
}
}
}
```
```
# Tri à bulle (4/4)
# Tri à bulle (4/4)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment