Data Str &amp; Algorithm HW Solutions 49

# Data Str & Algorithm HW Solutions 49 - 49 26401357 7.9...

This preview shows page 1. Sign up to view the full content.

49 26401357 7.9 (a) Each call to qsort costs Θ( i log i ) . Thus, the total cost is n X i =1 i log i =Θ( n 2 log n ) . (b) Each call to qsort costs Θ( n log n ) for length(L) = n , so the total cost is Θ( n 2 log n ) . 7.10 A l ltha tweneedtodoisrede f ne the comparison test to use strcmp. The quicksort algorithm itself need not change. This is the advantage of paramer- izing the comparator. 7.11 For n = 1000 , n 2 =1 , 000 , 000 , n 1 . 5 = 1000 1000 32 , 000 ,and n log n 10 , 000 . So, the constant factor for Shellsort can be anything less than about 32 times that of Insertion Sort for Shellsort to be faster. The constant factor for Shellsort can be anything less than about 100 times that of Insertion Sort for Quicksort to be faster. 7.12 (a) The worst case occurs when all of the sublists are of size 1, except for one list of size i k +1 . If this happens on each call to SPLITk, then the total cost of the algorithm will be Θ( n 2 )
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/27/2011 for the course MAP 2302 taught by Professor Bell,d during the Fall '08 term at UNF.

Ask a homework question - tutors are online