Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C-11.3 There is a sorting algorithm, Stooge-sort, which is named after the comedy team, The Three Stooges. if the input size, n, is 1 or
C-11.3 There is a sorting algorithm, "Stooge-sort," which is named after the comedy team, "The Three Stooges." if the input size, n, is 1 or 2, then the algorithm sorts the input immediately. Otherwise, it recursively sorts the first 2n/3 elements then the last 2n/3 elements, and then the first 2n/3 elements again. The details are shown in Algorithm 11.5. Show that Stooge-sort is correct and characterize the running time, T(n), for Stooge-sort, using a recurrence equation, and use the master theorem to determine an asymptotic bound for T(n) Algorithm StoogeSort(A, i, j): Input: An array, A, and two indices, i and J, such that l-i-j-n Output: Subarray, AI.?, sorted in nondecreasing order // The size of the subarray we are sorting if n 2 then if A[i] ? ADI then Swap Al and A] else if n > 2 then StoogeSort(A, i, j-m)Sort the first par StoogeSort(A, i + m,j) II Sort the last part StoogeSort( A. i, j-m) Sort the first part again return A Algorithm 11.5: Stooge-sort C-11.3 There is a sorting algorithm, "Stooge-sort," which is named after the comedy team, "The Three Stooges." if the input size, n, is 1 or 2, then the algorithm sorts the input immediately. Otherwise, it recursively sorts the first 2n/3 elements then the last 2n/3 elements, and then the first 2n/3 elements again. The details are shown in Algorithm 11.5. Show that Stooge-sort is correct and characterize the running time, T(n), for Stooge-sort, using a recurrence equation, and use the master theorem to determine an asymptotic bound for T(n) Algorithm StoogeSort(A, i, j): Input: An array, A, and two indices, i and J, such that l-i-j-n Output: Subarray, AI.?, sorted in nondecreasing order // The size of the subarray we are sorting if n 2 then if A[i] ? ADI then Swap Al and A] else if n > 2 then StoogeSort(A, i, j-m)Sort the first par StoogeSort(A, i + m,j) II Sort the last part StoogeSort( A. i, j-m) Sort the first part again return A Algorithm 11.5: Stooge-sort
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