Question
1. (10 pts total) For parts (1a) and (1b), justify your answers in terms of deterministic QuickSort, and for part (1c), refer to Randomized QuickSort.
1. (10 pts total) For parts (1a) and (1b), justify your answers in terms of deterministic QuickSort, and for part (1c), refer to Randomized QuickSort. In both cases, refer to the versions of the algorithms given in the lecture notes for Week 3. (a) (3 points) What is the asymptotic running time of QuickSort when every element of the input A is identical, i.e., for 1 i,j n, A[i] = A[j]? Prove your answer is correct. (b) (3 points) Let the input array A be [2,1,1,4,5,4,6,3,3,0]. What is the number of times a comparison is made to the element with value 3 (note the minus sign)? (c) (4 points) How many calls are made to random-int in (i) the worst case and (ii) the best case? Give your answers in asymptotic notation.
Randomized-Quicksort(A,p,r) {
if (p q = RPartition(A,p,r) Randomized-Quicksort(A,p,q-1) Randomized-Quicksort(A,q+1,r) }}. RPartition(A,p,r) { i = random-int(p,r) // NEW: choose uniformly random integer on [p..r] swap(A[i],A[r]) // NEW: swap corresponding element with last element x = A[r] // pivot is now a uniformly random element i = p-1 // code from deterministic Partition for (j=p; j<=r-1;j++) { if A[j]<=x { // same as before i++ // swap(A[i],A[j]) // }} swap(A[i+1],A[r]) // return i+1 // },
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