Professional Documents
Culture Documents
Tree
Terminology of Tree
Doubly Linked List
In Doubly Linked List each node in such list
contain two pointers, one to its predecessor and
another to its successor.
The nodes in the doubly linked list consist three
fields: an info field that contains the information
stored in the node, and left and right fields that
contain pointers to the nodes on either side.
^ ^
A B C D
Insertion at right
^ ^
P
10 20 30 40
r
q= new node
q->info= x; 25
q
r=p->right
Insertion at right
^ ^
P
10 20 30 40
r
q= new node
q->info= x; 25
q
r=p->right
r->left =q
q->right=r;
Insertion at right
^ ^
P
10 20 30 40
r
q= new node
q->info= x; 25
q
r=p->right
r->left =q
q -> left = p
q->right=r;
p-> right=q
Insertion at right
^ ^
P
10 20 30 40
r
25
q
Deletion
^ ^
P
A q B C D
r
item= p->info
q= p -> left
r= p-> right
Deletion
^ ^
P
A q B C D
r
item= P->info
q= p -> left
r= p-> right
q->right =r
r-> left = q;
Deletion
^ ^
A q B D
r
item= P->info
q= p -> left
r= p-> right
q->right =r
r-> left = q;
delete p
TREE
Nature View Of A Tree
leaves
branches
root
Computer Scientist’s View
root leaves
branches
nodes
Tree
E F G H
grand children of root
I
great grand child of root
Subtrees
A
root
B C D
E F G H
I
Levels
A
Level 1
Level 2
B C D
E F G H
Level 3
I
Level 4
Caution
E F G H
Level 3
I
Level 4
Node Degree = Number Of Children
A 3
2 B 1 C 1 D
0 0 1 0
E F G H
I 0
Tree Degree = Max Node Degree
A 3
2 B 1 C 1 D
0 0 1 0
E F G H
I 0
Degree of tree = 3.