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

added beginning of rotations

parent aee71b31
No related branches found
No related tags found
No related merge requests found
Pipeline #15938 passed
......@@ -1343,7 +1343,7 @@ graph TD;
## Cas 2a
* `v1`, `v2`, `u`, `w` ont la même hauteur.
* `v1`, `v2`, `u`, `w` même hauteur.
* déséquilibre en `C` après insertion dans `v2`
![Après insertion](figs/cas2a_gauche.png)
......@@ -1397,3 +1397,115 @@ graph TD;
:::
# Le facteur d'équilibre (balance factor)
## Définition
```
fe(arbre) = hauteur(droite(arbre)) - hauteur(gauche(arbre))
```
## Valeurs possibles?
. . .
```
fe = {-1, 0, 1} // arbre AVL
fe = {-2, 2} // arbre déséquilibré
```
![Illustration du `fe`](figs/facteur_equilibre.png){width=40%}
# Algorithme d'insertion
* Insérer le noeud comme d'habitude.
* Mettre à jour les facteurs d'équilibre jusqu'à la racine (ou au premier
noeud déséquilibré).
* Rééquilibrer le noeud si nécessaire.
## Cas possibles
::: columns
:::: column
## Sous-arbre gauche (avant)
```
fe(P) = 1
fe(P) = 0
fe(P) = -1
```
::::
:::: column
## Sous-arbre gauche (après)
. . .
```
=> fe(P) = 0
=> fe(P) = -1
=> fe(P) = -2 // Rééquilibrer P
```
::::
:::
# Algorithme d'insertion
* Insérer le noeud comme d'habitude.
* Mettre à jour les facteurs d'équilibre jusqu'à la racine (ou au premier
noeud déséquilibré).
* Rééquilibrer le noeud si nécessaire.
## Cas possibles
::: columns
:::: column
## Sous-arbre droit (avant)
```
fe(P) = 1
fe(P) = 0
fe(P) = -1
```
::::
:::: column
## Sous-arbre droit (après)
. . .
```
=> fe(P) = 0
=> fe(P) = +1
=> fe(P) = +2 // Rééquilibrer P
```
::::
:::
# Rééquilibrage
## Lien avec les cas vus plus tôt
```
fe(P) = -2 && fe(gauche(P)) = -1 => cas 1a
fe(P) = -2 && fe(gauche(P)) = +1 => cas 2a
fe(P) = +2 && fe(gauche(P)) = -1 => cas 1b
fe(P) = +2 && fe(gauche(P)) = +1 => cas 2b
```
## Dessiner les différents cas, sur le dessin ci-dessous
![On verra un peu après les rotations.](figs/rotation_gauche_droite.png)
slides/figs/cas1b_gauche.png

71 KiB | W: | H:

slides/figs/cas1b_gauche.png

78.3 KiB | W: | H:

slides/figs/cas1b_gauche.png
slides/figs/cas1b_gauche.png
slides/figs/cas1b_gauche.png
slides/figs/cas1b_gauche.png
  • 2-up
  • Swipe
  • Onion skin
slides/figs/cas2a_gauche.png

90.4 KiB | W: | H:

slides/figs/cas2a_gauche.png

99.7 KiB | W: | H:

slides/figs/cas2a_gauche.png
slides/figs/cas2a_gauche.png
slides/figs/cas2a_gauche.png
slides/figs/cas2a_gauche.png
  • 2-up
  • Swipe
  • Onion skin
slides/figs/cas2b_droite.png

85.2 KiB | W: | H:

slides/figs/cas2b_droite.png

93.3 KiB | W: | H:

slides/figs/cas2b_droite.png
slides/figs/cas2b_droite.png
slides/figs/cas2b_droite.png
slides/figs/cas2b_droite.png
  • 2-up
  • Swipe
  • Onion skin
slides/figs/cas2b_gauche.png

91.1 KiB | W: | H:

slides/figs/cas2b_gauche.png

100 KiB | W: | H:

slides/figs/cas2b_gauche.png
slides/figs/cas2b_gauche.png
slides/figs/cas2b_gauche.png
slides/figs/cas2b_gauche.png
  • 2-up
  • Swipe
  • Onion skin
slides/figs/facteur_equilibre.png

35.9 KiB

slides/figs/rotation_gauche_droite.png

56.9 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment