HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaMajor

Is there a difference between perfect, full and complete tree?

Submitted by: @import:stackexchange-cs··
0
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.

18
       /    \   
     15      20    
    /  \       
   40   50   
  /  \
 30  50


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.

18
       /         \  
     15           30  
    /  \         /  \
  40    50     100   40
 /  \   /
8   7  9


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.

18
       /       \  
     15         30  
    /  \        /  \
  40    50    100   40

Code Snippets

18
       /    \   
     15      20    
    /  \       
   40   50   
  /  \
 30  50
18
       /         \  
     15           30  
    /  \         /  \
  40    50     100   40
 /  \   /
8   7  9
18
       /       \  
     15         30  
    /  \        /  \
  40    50    100   40

Context

StackExchange Computer Science Q#32397, answer score: 33

Revisions (0)

No revisions yet.