Decision Tree Model for Sorting and Searching
The Decision tree model is used to analyze comparison-based algorithms such as sorting and
searching. In this model:
* Each internal node represents a comparison (e.g., ( ai < aj ))
* Each branch represents the outcome (yes/no)
* Each leaf represents a final result (solution)
This model helps us prove lower bounds on algorithm complexity.
Key Property of Binary Trees
For any binary tree:
Let ( l ) = number of leaves
Let ( h ) = height of the tree
Then:
Explanation:
Each level doubles the number of nodes:
Level 0 → 1 node
Level 1 → 2 nodes
Level 2 → 4 nodes
Level ( h ) → ( 2^h ) nodes
Decision Tree for Sorting
Example: Sorting 3 Elements (a, b, c)
There are:3! = 6
So the tree must have at least 6 leaves.
Decision Tree Diagram
(a < b?)
/
\
yes
no
/
\
(a < c?)
/
(b < c?)
\
/
yes
no
/
\
\
yes
/
no
\
a<b<c a<c<b b<a<c
c<b<a
```
Explanation:
* First compare ( a ) and ( b )
* Then refine using comparisons with ( c )
* Each path leads to a unique sorted order
Height Analysis
Number of leaves: l = 6
Minimum height: log26 approx. equal to 2.58
Conclusion:
Any comparison-based sorting algorithm for 3 elements needs at least 3 comparisons in the
worst case.
General Case: Sorting n Elements
* Number of permutations: n!
* Number of leaves: l = n!
No comparison-based sorting algorithm can do better in the worst case.
Decision Tree for Searching
Case 1: Unsorted Array
* Each comparison checks: ( x == ai )
* Possible outcomes: ( n+1 ) leaves
But since no order exists:
Result:
(Linear search is optimal.)
Case 2: Sorted Array (Binary Search)
* Each comparison splits the array in half
Number of leaves: n+1
Height:
Binary Search Tree Example
mid
/
\
left
right
/ \
/ \
... ... ... ...
```
Each level halves the search space.
(Binary search is optimal.)
Summary
Key Insight
Each comparison gives only **1 bit of information**
To distinguish among many possibilities, we need enough comparisons
More outcomes ⇒ more leaves ⇒ taller tree ⇒ higher time complexity
Conclusion
The decision tree model provides a powerful way to:
Prove lower bounds
Understand algorithm limits
Show optimality of algorithms like merge sort and binary search