Question: 3 VoodooSort Here s a simple recursive sorting algorithm that we will call VoodooSort: / / Sort array A [ ] between indices p and

3 VoodooSort
Heres a simple recursive sorting algorithm that we will call VoodooSort:
// Sort array A[] between indices p and r inclusive.
//
VoodooSort (A, p, r){
// Base Case: use InsertionSort
//
if (r - p <12){
InsertionSort(A, p, r) ;
return ; // add return statement to base case
}
// Break the array into 1st quarter, 2nd quarter and second half
//
n = r - p +1 ; // number of items in A[p..r] inclusive
q1= p -1+ n/4 ; // end of 1st quarter
q2= q1+ n/4 ; // end of 2nd quarter
// Sort the 3 pieces
// using VoodooSort, HeapSort and VoodooSort
//
VoodooSort (A, p, q1) ;
HeapSort (A, q1+1, q2) ;
VoodooSort (A, q2+1, r) ;
// Merge the 3 sorted arrays into 1 sorted array
//
Merge (A, p, q1, q2) ; // Merge 1st & 2nd quarter
Merge (A, p, q2, r) ; // Merge 1st & 2nd halves
return ;
}
In the following, you may assume without providing any proof that the worst case running times
of InsertionSort, HeapSort and Merge are \Theta (n
2
),\Theta (n log n) and \Theta (n), respectively.
1. Write down a recurrence relation for the worst case running time of VoodooSort. Briefly
justify your answer.
2. Prove the best upper bound you can on the worst case running time of VoodooSort.
3. Prove the best lower bound you can on the worst case running time of VoodooSort.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!