Bird
Raised Fist0
Data Structures Theoryknowledge~6 mins

Complete vs full vs perfect binary trees in Data Structures Theory - Key Differences Explained

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Imagine organizing a family tree or a tournament bracket. You want to know how balanced or filled the tree is. Different types of binary trees help us understand how nodes are arranged and how complete the structure is.
Explanation
Complete Binary Tree
A complete binary tree fills all levels fully except possibly the last one, which is filled from left to right without gaps. This means every level before the last is completely filled, and the last level has nodes as far left as possible.
A complete binary tree is filled level by level, left to right, with no gaps before the last level.
Full Binary Tree
A full binary tree is one where every node has either zero or two children. No node has only one child. This creates a tree where nodes are either leaves or have exactly two children.
In a full binary tree, every node has either two children or none.
Perfect Binary Tree
A perfect binary tree is both full and complete. All internal nodes have two children, and all leaf nodes are at the same level. This means the tree is perfectly balanced and completely filled.
A perfect binary tree is completely filled and all leaves are at the same depth.
Real World Analogy

Think of seating guests at a wedding. A complete binary tree is like filling all tables fully except maybe the last one, which is filled from left to right. A full binary tree is like every table having exactly two guests or being empty. A perfect binary tree is when all tables are fully occupied with exactly two guests each, and all tables are at the same distance from the entrance.

Complete Binary Tree → Filling tables fully except the last, which is filled left to right without gaps
Full Binary Tree → Every table has either two guests or none, no table with just one guest
Perfect Binary Tree → All tables fully occupied with two guests, and all tables are equally far from the entrance
Diagram
Diagram
Perfect Binary Tree:
      ┌───┐
      │ 1 │
      └─┬─┘
    ┌──┴──┐
    │     │
   ┌┴┐   ┌┴┐
   │2│   │3│
   └┬┘   └┬┘
  ┌─┴─┐ ┌─┴─┐
  │4 5│ │6 7│

Full Binary Tree (not complete):
      ┌───┐
      │ 1 │
      └─┬─┘
    ┌──┴──┐
    │     │
   ┌┴┐   ┌┴┐
   │2│   │3│
   └┬┘    
  ┌─┴─┐   
  │4 5│   

Complete Binary Tree (not full):
      ┌───┐
      │ 1 │
      └─┬─┘
    ┌──┴──┐
    │     │
   ┌┴┐   
   │2│   
   └┬┘   
  ┌─┴─┐  
  │4 5
This diagram shows examples of perfect, full (not complete), and complete (not full) binary trees highlighting their node arrangements.
Key Facts
Complete Binary TreeAll levels are fully filled except possibly the last, which is filled from left to right.
Full Binary TreeEvery node has either zero or two children, never one.
Perfect Binary TreeA binary tree that is both full and complete with all leaves at the same level.
Leaf NodeA node with no children.
Internal NodeA node with at least one child.
Common Confusions
Believing a full binary tree must be complete.
Believing a full binary tree must be complete. A full binary tree can have missing nodes on the last level, so it may not be complete.
Thinking a complete binary tree must have all nodes with two children.
Thinking a complete binary tree must have all nodes with two children. Complete binary trees can have nodes with only one child on the last level.
Assuming perfect binary trees are common in real applications.
Assuming perfect binary trees are common in real applications. Perfect binary trees are ideal and rare; most trees are complete or full but not perfect.
Summary
Complete binary trees fill levels fully except possibly the last, which fills from left to right.
Full binary trees have nodes with either zero or two children, no single-child nodes.
Perfect binary trees are both full and complete, with all leaves at the same depth.

Practice

(1/5)
1. Which of the following best describes a full binary tree?
easy
A. All levels are completely filled, including the last level.
B. Every node has either 0 or 2 children, no nodes have only one child.
C. All leaves are at the same level and every internal node has two children.
D. Nodes at the last level are as far right as possible.

Solution

  1. Step 1: Understand the definition of a full binary tree

    A full binary tree is defined as a tree where every node has either zero or two children, meaning no node has only one child.
  2. Step 2: Compare with other tree types

    Complete binary trees focus on filling levels left to right, and perfect binary trees are both full and complete with all leaves at the same level.
  3. Final Answer:

    Every node has either 0 or 2 children, no nodes have only one child. -> Option B
  4. Quick Check:

    Full binary tree = nodes have 0 or 2 children [OK]
Hint: Full means nodes have 0 or 2 children only [OK]
Common Mistakes:
  • Confusing full with complete trees
  • Thinking full means all levels filled
  • Assuming nodes can have one child
2. Which property must a perfect binary tree always satisfy?
easy
A. All levels except the last are completely filled, and last level nodes are left aligned.
B. Nodes at the last level can be anywhere, not necessarily left aligned.
C. Every node has at most one child.
D. Every node has either 0 or 2 children, and all leaves are at the same level.

Solution

  1. Step 1: Recall the definition of a perfect binary tree

    A perfect binary tree is both full and complete, meaning every node has 0 or 2 children and all leaves are at the same level.
  2. Step 2: Eliminate incorrect options

    All levels except the last are completely filled, and last level nodes are left aligned. describes a complete tree, not necessarily perfect. Nodes at the last level can be anywhere, not necessarily left aligned. contradicts the left alignment rule. Every node has at most one child. is incorrect as perfect trees have nodes with two children.
  3. Final Answer:

    Every node has either 0 or 2 children, and all leaves are at the same level. -> Option D
  4. Quick Check:

    Perfect tree = full + all leaves same level [OK]
Hint: Perfect = full + all leaves at same level [OK]
Common Mistakes:
  • Mixing complete and perfect tree definitions
  • Ignoring leaf level uniformity
  • Assuming last level nodes can be scattered
3. Consider the following binary tree structure:
       A
      / \
     B   C
    / 
   D 

Which type of binary tree is this?
medium
A. Complete binary tree
B. Full binary tree
C. Perfect binary tree
D. None of the above

Solution

  1. Step 1: Analyze the tree structure

    The tree has root A with two children B and C. Node B has one child D. Node C has no children.
  2. Step 2: Check properties against tree types

    Node B has exactly one child, so it is not full (full requires every node has 0 or 2 children). Levels 0 and 1 are completely filled; level 2 has D as far left as possible: complete. Leaves C (level 1) and D (level 2) not same level: not perfect.
  3. Final Answer:

    Complete binary tree -> Option A
  4. Quick Check:

    Last level left aligned but not full = complete tree [OK]
Hint: Complete trees fill left to right, full requires 0 or 2 children [OK]
Common Mistakes:
  • Assuming missing right child means not complete
  • Confusing full with complete
  • Thinking perfect applies without full and complete
4. Identify the error in the following statement:
A perfect binary tree can have nodes with only one child.
medium
A. Incorrect, perfect trees require all internal nodes to have two children.
B. Correct statement, perfect trees allow one child nodes.
C. Incorrect, perfect trees only require last level to be full.
D. Correct, as long as the tree is complete.

Solution

  1. Step 1: Understand perfect binary tree requirements

    Perfect binary trees are both full and complete, meaning every internal node must have exactly two children.
  2. Step 2: Evaluate the statement

    The statement claims nodes can have only one child, which contradicts the full tree property required for perfect trees.
  3. Final Answer:

    Incorrect, perfect trees require all internal nodes to have two children. -> Option A
  4. Quick Check:

    Perfect tree = no single-child nodes [OK]
Hint: Perfect trees never have single-child nodes [OK]
Common Mistakes:
  • Confusing complete with perfect tree rules
  • Thinking one child allowed if tree is complete
  • Ignoring full tree property in perfect trees
5. You have a binary tree with 15 nodes. It is known to be a perfect binary tree. How many leaf nodes does it have?
hard
A. 7
B. 16
C. 8
D. 15

Solution

  1. Step 1: Recall leaf count formula for perfect binary trees

    In a perfect binary tree, the number of leaf nodes is (n + 1) / 2, where n is the total number of nodes.
  2. Step 2: Calculate leaf nodes for 15 nodes

    Using the formula: (15 + 1) / 2 = 16 / 2 = 8 leaf nodes.
  3. Final Answer:

    8 -> Option C
  4. Quick Check:

    Leaf nodes = (total nodes + 1) / 2 = 8 [OK]
Hint: Perfect tree leaves = (nodes + 1) / 2 [OK]
Common Mistakes:
  • Using total nodes as leaf count
  • Confusing full and perfect tree leaf counts
  • Forgetting leaf count formula