Académique Documents
Professionnel Documents
Culture Documents
ArbreDErecherche 2
ArbreDErecherche 2
ARBRES DE RECHERCHE
PLAN
Arbres binaires de recherche
Arbre h-quilibrs
EXEMPLE
11
15
8
cl min 5
10
6
12
30
21
35 cl max
25
3
ABR:
Arbre binaire a
a.g = sous-arbre de gauche de racine(a)
a.d = sous-arbre de droite de racine(a)
class ABR {
private int cle;
private String element;
private ABR gauche;
private ABR droit;
public ABR(int a, String s, ABR g, ABR d) {
cle = a;
element = s;
gauche= g;
droit=d;
}
//les mthodes
Recherche :
descente de larborescence avec
comparaison en chaque nud
EXEMPLE
11
recherche de 21
15
8
10
5
6
12
30
21
35
25
6
complexit: O(h(a))7
ajout de 14
11
15
8
10
5
6
complexit: O(h(a))
12
30
14 21
place
25
35
10
10
EXEMPLE
15
12
11
c3-2
14
30
21
35
c3-1
17
16
23
19
18
20
11
10
EXEMPLE
8
15
3
2
12
11
30
14
21
17
16
35
23
19
18
20
12
10
EXEMPLE
15
3
2
12
30
14
21
17
16
35
23
19
18
20
13
10
EXEMPLE
16
3
2
12
30
14
21
17
35
23
19
18
20
14
10
EXEMPLE
17
3
2
12
30
14
21
19
18
35
23
20
15
o'
cas 2
o
o'
b
o'
o
a
b
C. Carrez
16
Cas 3.2
o'
o'
o"
o
a
a
b
o"
b
c
c
C. Carrez
17
18
cas 3
a a 2 fils:
19
20
quilibre
arbre non quilibr:
arbre quilibr:
r
a
22
arbre AVL:
arbre binaire de recherche
H-quilibr
h
h-1
(en O(log(n))
(ou+ou- 1)
23
si h(a.g) = h(a.d)
si h(a.g) = h(a.d)-1
si h(a.g) = h(a.d)-2
si h(a.g) = h(a.d)+1
si h(a.g) = h(a.d)+2
10 =
4-
17
12
=
6
++
14
24
1 7
exemple de rotation
3 0
2 1
1 9
1 8
++
3 5
2 3
2 0
1 7
2 1 =
1 9
R-quilibrage 1
1 8
2 0
3 0
2 3
3 5
25
o++
o' +
D
h-1
h
h-3
h-3
h-2
dsquilibre(A)=2, et
dsquilibre(A.g))=1 ou 0
o
rotation
droite
A '
'
=
h
h -1
h -2
h
D
D
C. Carrez
h -2
h -3
h -3
26
4 0 ++
17
12
50
30
14
21
19
45
52
35
23
27
17 - 12
40
30
14
21
19
35
50
45
52
23
+ +
4 0
2
1 7
50
1 2
3 0
4 5
5 2
+ +
4 0
3 0
1 4
2 1
3 5
3 5
1 7
1 9
2 3
1 2
R-quilibrage 2
1 7
3 0
4 0
1 9
2 3
2 3
3 5
2 1
1 4
1 9
1 4
1 2
2 1
5 0
4 5
5 2
29
rotation gauche-droite
A
o
++
o'
h
o"
h -1
h -2
h -3
h -3
h - 3 ( +/- 1 )
h - 3 ( + /- 1 )
o" =
o'
h -1
h -2
C. Carrez
h -3
h -3
(+ / - 1 )
h -3
( + / -1 )
E
h -3
30
adjonction et suppression
mme principe que dans un arbre binaire de
recherche mais en rquilibrant par rotations aprs
l'opration si c'est ncessaire (si a n'est plus H
quilibr)
Dans les arbres AVL
recherche
adjonction
suppression
en (log2n)
On constate exprimentalement:
en moyenne 1 rotation pour 2 adjonctions
en moyenne 1 rotation pour 5 suppressions
31
Exemple
71
83
44
37
61
32
Exemple
71 ++
83
44 37
61
50
33
Exemple
71 ++
83
44 37
61
50
71
61
83
44
37
50
34
Exemple
71 ++
83
44 37
61
50
71
61
61
83
71
44
puis
AVL
44
83
37
37
50
50
35