Documente Academic
Documente Profesional
Documente Cultură
1 3 5 7
2
bool cautaInformatieAVL(PNODAVL rad, int informatie){
bool temp = false;
if(!rad) return temp;
// cout << rad->informatie;
if(rad->informatie == informatie) temp = true;
if(!temp) temp = temp | cautaInformatieAVL(rad->ss, informatie);
if(!temp) temp = temp | cautaInformatieAVL(rad->sd, informatie);
return temp;
}
08.12.21 Curs 1 - Introducere. Structuri de date - noţiuni generale 2
Curs 4 – Arbori binari de căutare echilibraţi
Arbore Arbore
iniţial dezechilibrat
+2
x
h h+2
+1 +2
x x +1/-1
h h+1 h h+2 y
A h+1/h
A D A D
B C
Rotire stânga
08.12.21 Curs 1 - Introducere. Structuri de date - noţiuni generale 3
Curs 4 – Arbori binari de căutare echilibraţi
• Caz 1 – rotire simplă stânga
x->sd = y->ss;
+2 0
x y y->ss = x;
h h+2 h+1 h+1 -------------------------------
+1
y x 0 PNODAVL temp;
B C A B
B1 B2
B2 C A B1 B2 C
x->sd = sRotireDreapta(y);
------------------------------- rad = sRotireStanga(rad);
08.12.21 rad->sd Introducere. Structuri de date - noţiunireturn
Curs 1=- sRotireDreapta(rad->sd); generalerad; 6
Curs 4 – Exemplu arbori binari de căutare
echilibraţi - 1, 2, 3, 4, 5, 6, 7
2 6
1 3 5 7
+2
1 2
2 +1 1 3
+1
1 3
4
IV – rotire simplă stânga
2 +1
2
+2
1 3 1 +1
4
+1
4 3 5
5
08.12.21 Curs 1 - Introducere. Structuri de date - noţiuni generale 9
Curs 4 – Exemplu arbori binari de căutare
echilibraţi - 1, 2, 3, 4, 5, 6, 7
V – rotire simplă stânga
+2
2
1 +1
4
+1
3 5
6 4
2 5
1 3 6
2 +2
5
+1
1 3 6
4 0
7
2 6
1 3 5 7
+1
2 6 2 6
1 3 5 7 1 3 7
5 6 -1
2 6 2 7
1 3 7 1 3
2 +1 7 6 3 0
3 7 2 6
1 3 +1
2 4 1 4 7
4
-1
2 6
1 4 +1 7