16

Is there a difference between perfect, full and complete tree? Or are these the same words to describe the same situation?

Raphael
  • 73,212
  • 30
  • 182
  • 400
Olórin
  • 859
  • 2
  • 12
  • 22

4 Answers4

34

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
blockByblock
  • 135
  • 1
  • 5
Lov Verma
  • 466
  • 5
  • 5
4

These words don't have a standard definition. A full binary tree could be one in which every node has either none or two children. A complete binary tree of height $h$ could be one in which all nodes up to level $h$ have two children. I have never heard of the adjective perfect used to describe trees.

That said, a complete binary tree of height $h$ usually means what I wrote above.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
1

A complete binary tree is on in which every level excepts possible the last level is completely filled and every node are as far left as possible but for a full binary tree every level has the maximum number of nodes in it

user23144
  • 11
  • 1
0

A full binary tree has all it's nodes with either none or two children. A complete binary tree of height h could be one in which all nodes up to level h have two children. A perfect binary tree is a tree which is both full and complete.