Professional Documents
Culture Documents
Trees, Graphs, Heap
Trees, Graphs, Heap
1.> Leaf(External)(Terminal)Node:- It is a node which does not have any child nodes (eg.
D,E,F,G)
4.> Sibling Node:- Nodes that appear from the same parent
18
/ \
15 30
/ \ / \
40 50 100 40
18
/ \
15 20
/ \
40 50
/ \
30 50
18
/ \
15 30
/ \ / \
40 50 100 40
/ \ /
8 7 9
Practical example of Complete Binary Tree is Binary Heap.
1) The maximum no. of nodes at level ‘h’ of a binary tree = Total no. of nodes at level 'h' of a perfect binary
tree=2h.
2) The maximum no of nodes (n) in a perfect binary tree = Total number of nodes (n) in a perfect binary
tree = 20+21+22+…….+2h = 2h+1-1
3) Max no. of leaves in a binary tree=Total number of leaves (l) in a perfect binary tree = 2 h
4) In Binary tree where every node has 0 or 2 children, number of leaf nodes(l) = 1+ nodes with two children(i).
5) In a Binary Tree with N nodes, minimum possible height or minimum number of levels is ? Log2(N+1) ?
Q7. How to determine if a binary tree is height-balanced?
Ans:- 1.> An empty tree is height-balanced.
2.> A non-empty binary tree T is balanced if:
1) Left subtree of T is balanced
2) Right subtree of T is balanced
3) The difference between heights of left subtree and right subtree is not more than 1. (i.e
balance factor is not more than 1)