Professional Documents
Culture Documents
Trees 1
Trees 1
TREE - DEFINITION
A tree is a finite set of one or more nodes such that:
1. There is a specially designated node called the root.
2. The remaining nodes are partitioned in n 0 disjoint sets
T1, T2, …, Tn, where each of these sets is a tree.
3. T1, T2, …, Tn are called the sub-trees of the root.
Recursive Definition
TREE
B F K
C H D L X
Q G M I N P
NODE TYPES
A
B F K
C H D L X
Q G M I N P
B F K
C H D L X
Q G M I N P
Degree 1 Degree 3
Degree 0 Degree 2
LEVEL OF A NODE
DISTANCE FROM THE ROOT
A
B F K
C H D L X
Q G M I N P
Level 0 Level 2
Level 1 Level 3
A A
B K B
C H L X C
Q M P Q
M
BINARY TREE TRAVERSAL
IN ORDER TRAVERSAL (LNR)
B K
C H L X
Q M P
Q C M B H A L K X P
BINARY TREE TRAVERSAL
PRE ORDER TRAVERSAL (NLR)
B K
C H L X
Q M P
A B C Q M H K L X P
BINARY TREE TRAVERSAL
POST ORDER TRAVERSAL (LRN)
B K
C H L X
Q M P
Q M C H B L P X K A
BINARY TREE TRAVERSAL
A
B K
C H L X
Q M P