Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 5: Consider the following recursive algorithm. Assume that n is a power of 3 , that is, n=3k for an integer k. The subroutine,
Question 5: Consider the following recursive algorithm. Assume that n is a power of 3 , that is, n=3k for an integer k. The subroutine, Thirds, takes list A as input and arranges the elements such that the smallest n/3 items in A are in locations 0..3n1 and the largest n/3 items in A are in locations 32n..n1. Thirds requires 2n significant operations to do this. (a) Prove that Algorithm Magicsort correctly sorts the elements in the array A. (b) Write the recurrence in terms of n describing the number of significant operations done with an initial call of Magicsort(A[0n1],n). Hint: write a recurrence whose general form is R(n)=aR(n/b)+f(n) where a,b are rational numbers and f(n) is a function of n. Justify why your recurrence is correct. Be sure to include the base case of your recursion. (c) Using this recurrence, prove that R(n)=2nlog3n when n1 using induction
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started