Data Structures and Algorithms - L6
Data Structures and Algorithms - L6
Worst-case n! leaves
evaluation path in this tree
for any algorithm 4 4
BITS Pilani, Pilani Campus
Decision-tree example
Sort a1, a2, …, an 1:2
2:3 1:3
2:3 1:3
2:3 1:3
Thus, n! 2h .
h lg(n!) (lg is mono. increasing)
lg ((n/e)n) (Stirling’s formula)
= n lg n – n lg e
= (n lg n) .
since n lg n – n lg e n lg n for all n >= n0 (take n0 to be
100) BITS Pilani, Pilani Campus
Problem Complexity
if
if