07 Trees
07 Trees
Chapter 6
Trees
Trees with some ordering e.g., Binary Search Trees (BST) provide moderate
access/search (quicker than Linked List and slower than arrays).
Like Linked Lists and unlike Arrays, Trees don’t have an upper limit on
number of nodes as nodes are linked using pointers.
Decision trees
• Here the height of a tree is the maximum number of nodes on the root
to leaf path.
• Height of a tree with a single node is considered as 1.
• A tree has maximum nodes if all levels have maximum nodes.
• So maximum number of nodes in a binary tree of height h is 1 + 2 + 4
+ .. + 2h. This is a simple geometric series with h terms and sum of
this series is 2h– 1.
Department of Electronics And Electrical Engineering, IIT Guwahati
Binary Tree: Properties
3) In a Binary Tree with N nodes, minimum possible height
or the minimum number of levels is Log2(N+1)
Structural Ordering
10 2
8 7 3 4
6 4 3 2 6 7 10 8
Max Heap
Insert every element as it is
24 12
11 25 8 35
11 25 8 35 11 24 8 12
11 24 8 12 11 24 8 12
35
25 14
11 24 8 12
25 14
11 24 8 12
11 24
7
8
BST behaves 8
like linked list 7 9