0
0
Data Structures Theoryknowledge~10 mins

Complete vs full vs perfect binary trees in Data Structures Theory - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Complete vs full vs perfect binary trees
Start with Binary Tree
Are all levels except the last fully filled?
Is last level filled left to right?
Complete Tree
All nodes have 0 or 2 children?
Full Tree
This flow shows how to classify a binary tree by checking if all levels except the last are fully filled, if the last level is filled left to right, and if all nodes have 0 or 2 children.
Execution Sample
Data Structures Theory
Tree:
      1
     / \
    2   3
   / 
  4  
This tree is complete but not full or perfect because last level is not fully filled and node 2 has only one child.
Analysis Table
StepCheckConditionResultClassification
1Check if all levels except last are fully filledLevels 0 and 1 fully filledTrueContinue
2Check if last level is filled left to rightNode 4 is left child, no gapsTrueContinue
3Check if all nodes have 0 or 2 childrenNode 2 has only one childFalseNot Full
4Check if all levels fully filledLast level not fully filledFalseNot Perfect
5Conclusion--Tree is Complete but not Full or Perfect
💡 Last level is filled left to right but not fully filled, and node 2 has only one child, so tree is Complete only.
State Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
All levels except last fully filledUnknownTrueTrueTrueTrue
Last level filled left to rightUnknownUnknownTrueTrueTrue
All nodes have 0 or 2 childrenUnknownUnknownUnknownFalseFalse
Tree classificationUnknownUnknownUnknownNot FullComplete only
Key Insights - 3 Insights
Why is the tree not considered full even though most nodes have two children?
Because node 2 has only one child, violating the full tree rule that every node must have 0 or 2 children (see execution_table step 3).
Why is the tree classified as complete if the last level is not fully filled?
Because the last level is filled from left to right without gaps, which satisfies the complete tree condition (see execution_table step 2).
What makes a tree perfect compared to complete?
A perfect tree has all levels fully filled with no missing nodes, unlike a complete tree which allows the last level to be partially filled left to right (see execution_table steps 1 and 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step do we find the tree is not full?
AStep 4
BStep 3
CStep 2
DStep 1
💡 Hint
Check the 'All nodes have 0 or 2 children' condition in execution_table step 3.
According to variable_tracker, what is the final classification of the tree?
AComplete only
BFull and Perfect
CPerfect only
DNot Complete
💡 Hint
Look at the 'Tree classification' row in variable_tracker final column.
If node 2 had two children, how would the classification change?
ATree remains Complete only
BTree becomes Perfect
CTree becomes Full and Complete
DTree becomes Not Complete
💡 Hint
Refer to key_moments about full tree condition and execution_table step 3.
Concept Snapshot
Complete Binary Tree:
- All levels fully filled except possibly last
- Last level filled left to right

Full Binary Tree:
- Every node has 0 or 2 children

Perfect Binary Tree:
- All levels fully filled
- Tree is both full and complete
Full Transcript
This visual execution trace compares complete, full, and perfect binary trees. It starts by checking if all levels except the last are fully filled, then if the last level is filled left to right, and finally if every node has either zero or two children. The example tree is complete because its last level is filled left to right without gaps, but not full because one node has only one child. It is also not perfect because the last level is not fully filled. Key moments clarify why the tree is not full and how perfect trees differ from complete ones. The quizzes test understanding of these conditions and classifications.