gotchaMajor
Is there a difference between perfect, full and complete tree?
Viewed 0 times
fullperfectdifferencecompletebetweenandtheretree
Problem
Is there a difference between perfect, full and complete tree? Or are these the same words to describe the same situation?
Solution
Yes, there is a difference between the three terms and the difference can be explained as:
Full Binary Tree: A Binary Tree is full if every node has 0 or 2 children. Following are examples of a full binary tree.
Complete Binary Tree: A Binary Tree is complete Binary Tree if all levels are completely filled except possibly the last level and the last level has all keys as left as possible.
Perfect Binary Tree: A Binary tree is Perfect Binary Tree in which all internal nodes have two children and all leaves are at same level.
Full Binary Tree: A Binary Tree is full if every node has 0 or 2 children. Following are examples of a full binary tree.
18
/ \
15 20
/ \
40 50
/ \
30 50Complete Binary Tree: A Binary Tree is complete Binary Tree if all levels are completely filled except possibly the last level and the last level has all keys as left as possible.
18
/ \
15 30
/ \ / \
40 50 100 40
/ \ /
8 7 9Perfect Binary Tree: A Binary tree is Perfect Binary Tree in which all internal nodes have two children and all leaves are at same level.
18
/ \
15 30
/ \ / \
40 50 100 40Code Snippets
18
/ \
15 20
/ \
40 50
/ \
30 5018
/ \
15 30
/ \ / \
40 50 100 40
/ \ /
8 7 918
/ \
15 30
/ \ / \
40 50 100 40Context
StackExchange Computer Science Q#32397, answer score: 33
Revisions (0)
No revisions yet.