online advertising
Loading [MathJax]/jax/output/HTML-CSS/jax.js

Wednesday, October 7, 2015

Algorithms: Design and Analysis, Part 1 - Problem Set 1 - Question 1

Problem:

3-way-Merge Sort : Suppose that instead of dividing in half at each step of Merge Sort, you divide into thirds, sort each third, and finally combine all of them using a three-way merge subroutine. What is the overall asymptotic running time of this algorithm? (Hint: Note that the merge step can still be implemented in O(n) time.)

Solution:

Step 1: Write down the recurrence

T(1)=O(1)
T(n)=3T(n3)+O(n)

Step 2: Assuming n=3k, simplify the recurrence

Let S(k)=T(3k), therefore, we have

S(0)=O(1)
S(k)=3S(k1)+O(3k)

Step 3: We solve the recurrence

S(k)=3S(k1)+O(3k)=3(3(S(k2)+O(3k1))+O(3k)=32S(k2)+O(3k)+O(3k)=32S(k2)+2O(3k)=3kS(kk)+kO(3k)=3kO(1)+kO(3k)=O(k3k)=O(nlogn)

No comments:

Post a Comment