Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 5: Consider the following recursive algorithm: Algorithm Weirdsort(A[0 . . . n - 1]): if n = 2 and A[0] > A[1]: swap A[0]
Question 5: Consider the following recursive algorithm: Algorithm Weirdsort(A[0 . . . n - 1]): if n = 2 and A[0] > A[1]: swap A[0] A[1] else if n > 2: m - [2n/3]; Weirdsort(A[0 . . . m - 1]) Weirdsort(An - m. . . n - 1]) Weirdsort( A[0 . . . m - 1]) (a) Prove that Algorithm Weirdsort correctly sorts the elements in the array A. (b) Ignoring ceilings (i.e. we can assume that n is a power of 3), write the recurrence in terms of n describing how many calls are made to Weirdsort with an initial call of Weirdsort(A[0 . . . n - 1])? 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 counting the number of recursive calls. (c) Using this recurrence, prove that R(n) is at most n' when n 2 2 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