Professional Documents
Culture Documents
AV 482 Data Structures and DBMS: Instructor: B. S. Manoj 26 August 2013
AV 482 Data Structures and DBMS: Instructor: B. S. Manoj 26 August 2013
Todays plan
General updates
Quiz-1 updates Topics till last class
Tree ADT
Binary Search Trees Algorithms for Binary Search Trees
24
89
19
32
65
91
13
21
AV 482 Data Structures and DBMS, JulyDecember 2013
1
3
h=O(Log N)
5 6 8 9
Locate 21 Locate 64
else if (x == T->element)
return TRUE;
24
89
19
32
65
91
else
return(MEMBER(x, T->rightchild));
Return False
13 21
Time complexity: O(h: height of tree) Worst case: O(N) Average case: O(Log N) AV 482 Data Structures and DBMS, JulyDecember 2013
Insert: 25
45
Insert: 26 Insert: 90
89
24
19
32
65
91
else
Printf(X is already in the Tree);
13
21
25 90
}
AV 482 Data Structures and DBMS, JulyDecember 2013
26
DELETE algorithm
DELETE(elementtype x, Tree T) {
if (T!=NULL){
If(x < T->element)
DELETE(x, T->leftchild) 45
24
89 90
19
32
65
91
elseif(T->leftchild ==NULL)
T = T->rightchild;
elseif(T->rightchild == NULL
T = T->leftchild;
13
21
33
90
else
T->element = DELETEMIN(T>rightchild); 12
}}
DELETEMIN(.) algorithm
elementtype DELETEMIN(Tree T) {
if(T->leftchild == NULL)
{ temp=T->element; T=T->rightchild; return temp; }
else {
DELETEMIN(T->leftchild); }
}
AV 482 Data Structures and DBMS, JulyDecember 2013
19 19 24 32 45 89 24 32 45 89 89 45 89 45 32 24 19 24 19 32
45 45 24 19 32 89 19
AV 482 Data Structures and DBMS, JulyDecember 2013
24 32
89
Summary
Binary Trees
Search Trees Algorithms for Insert, delete, search etc.