Starting from:

$25

CS3001301-Homework 2 Solved

Problem 2.1. ( Prove lg(๐‘›!) = Θ(๐‘› log ๐‘›) when ๐‘› is an odd number. You can

(1) try the similar approach like what we did in the lecture, or (2) find the answer based on the result for even numbers.

 

Problem 2.2.  Solve the following recurrence equations by the master theorem or any other methods that we discussed in class.

  

(b) ๐‘‡(๐‘›) = 3๐‘‡(๐‘›/9) + ๐‘›4 lg๐‘› 
  

(d) ๐‘‡(๐‘›) = ๐‘‡(๐‘› − 1) + lg๐‘› (e) ๐‘‡(๐‘›) = 2๐‘‡(๐‘›/2 − 1) 
 

Problem 2.3.  Compare the efficiency of the Quicksort code to either (1) the code you wrote for your data structure class; (2) the code written by Hoare in 1960 (page 185 or shown below). You should have some trials and report the performance difference, moreover, providing some reasons why we may have such performance difference.

 

HOARE-PARTITION(A, p, r)     x = A[p]     i = p – 1     j = r + 1     while true         repeat             j = j - 1         until A[j] ≤ x         repeat             i = i + 1 

        until A[i] ≥ x         if i < j 

            exchange A[i] with A[j]         else return j 

 

 

Problem 2.4.  In slide No. 13, confirm the performance of the improved quicksort based on MEDIAN3 and small files sorted by insertion sort. You can give your best choice of M and suggest an amount of time reduction for the choice. A figure with the performance curve is helpful.

 

More products