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
radhwan.hassine
cours
Commits
68aea6a4
Verified
Commit
68aea6a4
authored
1 year ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
maj 2023
parent
77af922e
No related branches found
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
+30
-16
30 additions, 16 deletions
slides/cours_7.md
with
30 additions
and
16 deletions
slides/cours_7.md
+
30
−
16
View file @
68aea6a4
...
...
@@ -193,9 +193,11 @@ Le plus petit élément est -9. On commence donc par décaler les valeurs de 9.
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
| -9 | -6 | -5 | 1 | 2 | 2 | 4 | 5 | 6 |
*
Et alors?
. . .
*
The end
.
*
Et alors rien. C'est fini
.
# Pseudo-code
...
...
@@ -250,7 +252,7 @@ rien decaler(entier taille, entier tab[taille], entier val):
```
python
rien
echanger
(
entier
tab
[],
entier
tab2
[])
# échanger les
pointeurs v
er
s
les
tableaux
# échanger les
tableaux (sans copi
er les
valeurs)
```
# Un peu plus de détails (2/2)
...
...
@@ -262,7 +264,7 @@ rien alveole_0(entier taille, entier tab[taille],
entier
tab_tmp
[
taille
],
entier
pos
):
entier
k
=
0
pour
i
de
0
à
taille
-
1
:
si
g
it
(
tab
[
i
],
pos
):
si
b
it
(
tab
[
i
],
pos
):
tab_tmp
[
k
]
=
tab
[
i
]
k
=
k
+
1
```
...
...
@@ -274,7 +276,7 @@ rien alveole_0(entier taille, entier tab[taille],
```
python
rien
alveole_1
(
entier
taille
,
entier
tab
[
taille
],
entier
tab_tmp
[
taille
],
entier
pos
):
# pareil que alveole
1
mais en partant de taille
# pareil que alveole
_0
mais en partant de taille
```
<!--
```C
...
...
@@ -389,7 +391,7 @@ Ainsi, la complexité du tri par base est $\mathcal{O}(b\cdot N)$. -->
# Principe de l'algorithme
*
Soit
`taille`
la taille du tableau à trier.
*
Pour
`i = 0`
à
`entier(
\
log
_
2(taille))-1`
:
*
Pour
`i = 0`
à
`entier(log2(taille))-1`
:
*
Fusion des paires de sous-tableaux successifs de taille
`2**i`
(ou moins pour l'extrémité)
. . .
...
...
@@ -421,33 +423,45 @@ Ainsi, la complexité du tri par base est $\mathcal{O}(b\cdot N)$. -->
# Pseudo-code
```
python
rien
tri_fusion
(
entier
taille
,
entier
tab
[
taille
])
{
rien
tri_fusion
(
entier
taille
,
entier
tab
[
taille
])
entier
tab_tmp
[
taille
];
entier
nb_etapes
=
log_2
(
size
)
+
1
;
pour
etape
de
0
a
nb_etapes
-
1
:
entier
gauche
=
0
;
entier
t
aille
_tranche
=
2
**
etape
;
entier
t_tranche
=
2
**
etape
;
tant
que
(
gauche
<
taille
):
fusion
(
tab
[
gauche
..
gauche
+
taille_tranche
-
1
],
tab
[
gauche
+
taille_tranche
..
gauche
+
2
*
taille_tranche
-
1
],
tab_tmp
[
gauche
..
gauche
+
2
*
taille_tranche
-
1
]);
#bornes incluses
gauche
+=
2
*
taille_tranche
;
fusion
(
tab
[
gauche
..
gauche
+
t_tranche
-
1
],
tab
[
gauche
+
t_tranche
..
gauche
+
2
*
t_tranche
-
1
],
tab_tmp
[
gauche
..
gauche
+
2
*
t_tranche
-
1
]);
#bornes incluses
gauche
+=
2
*
t_tranche
;
echanger
(
tab
,
tab_tmp
);
```
# La fonction de fusion
\f
ootnotesize
```
python
# hyp: tab_g et tab_d sont triés
rien
fu
ct
ion
(
entier
tab_g
[],
entier
tab_d
[],
entier
res
[]):
rien
fu
s
ion
(
entier
tab_g
[],
entier
tab_d
[],
entier
res
[]):
entier
g
=
taille
(
tab_g
)
entier
d
=
taille
(
tab_d
)
entier
i_g
=
0
,
i_d
=
0
pour
i
=
0
à
g
+
d
:
si
tab_g
[
i_g
]
<
tab
[
i_d
]:
si
i_g
<
g
et
i_d
<
d
:
si
tab_g
[
i_g
]
<
tab
[
i_d
]:
res
[
i
]
=
tab_g
[
i_g
]
i_g
=
i_g
+
1
sinon
:
res
[
i
]
=
tab_d
[
i_d
]
i_d
=
i_d
+
1
sinon
si
i_g
<
g
:
res
[
i
]
=
tab_g
[
i_g
]
i_g
=
i_g
+
1
sinon
:
res
[
i
]
=
tab_
g
[
i_d
]
sinon
si
i_d
<
d
:
res
[
i
]
=
tab_
d
[
i_d
]
i_d
=
i_d
+
1
```
...
...
@@ -600,7 +614,7 @@ int partition(int size, int array[size], int first, int last) {
}
```
# Tri rapide ou quicksort (8/8)
<!--
# Tri rapide ou quicksort (8/8)
## Quelle est la complexité du tri rapide?
...
...
@@ -614,7 +628,7 @@ int partition(int size, int array[size], int first, int last) {
*
Chaque fois le tableau est séparé en $2$ parties égales.
*
On a $
\l
og_2(N)$ partitions, et $N$ boucles $
\R
ightarrow N
\c
dot
\l
og_2(N)$.
*
En moyenne: $
\m
athcal{O}(N
\c
dot
\l
og_2(N))$.
*
En moyenne: $
\m
athcal{O}(N
\c
dot
\l
og_2(N))$.
-->
# L'algorithme à la main
...
...
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