DAA Class Notes
DAA Class Notes
DAA Class Notes
Quick Sort
Bestcase
example:
[3 1 2 5 4]
[1 2] 3 [4 5]
1 [2]
4
[5]
-----------------------1
2 3 4 5
Worst Case
[1 2 3 4 5]
1 [5 4 3 2]
[4 3 2] 5
[ 3 2] 4
[ 2] 3
--------------------1
2 3 4 5
NOTE: Cost of a tree = Cost of its Left Sub Tree + Cost of its Right Sub Tree + Sum
of all probabilities in that tree. ie. Cost of t(0,3) = Cost of t(0,1) + Cost of t(2,3) +
w(0,3)
Similarly,
Cost of t(0,1)=Cost of t(0,0) + Cost of t(1,1) + w(0,1)