Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We say that an array A is c - nice for a constant c if for all 1 < = i < j < =
We say that an array A is cnice for a constant c if for all i j n such that j i c we have that Ai Aj For example, a nice array is completely sorted in ascending order In this problem we will sort such cnice arrays A using various sorting algorithms and compare the results. You may assume that A has n distinct elements.
a For an element at position i in the array, what is the best lower bound you can give on its rank? What is the best upper bound?
bIn asymptotic notation remember that c is a constant what is the worstcase running time of InsertionSort on a cnice array?
Now consider a run of Quicksort on a cnice array, where the pivot element is chosen deterministically as the last element of the array.
c Argue that after partitioning, the two subarrays A q and Aq n to the left and to the right of the pivot, respectively, are both cnice.
dFrom the lecture you already know that the running time of quicksort on sorted arrays is Theta n Let Bn denote the bestcase running time of Quicksort on cnice array with n elements. Using your results from a and c derive a recurrence for Bn and solve it
eAsymptotically which is faster on cnice arrays: the worstcase running time of insertion sort or the bestcase running time of quicksort?
fNow use minheaps in a slightly clever way to get an algorithm with the following specification. It takes as input an array A and a integer value b in n and always runs in time On log b time. The output is always a permutation of the elements of A However, if the input A is cnice for some c b the output is the sorted version of A
g When you are sorting arrays, you will not know what c is Heres a general guessing strategy:
NiceButWeirdSortA
let i
let bi
B SortNiceA b
if B is not sorted, set i i goto line
Suppose the array is cnice. Give the best runtime bound you can give for this algorithm in terms of n and log c
h Change your choice for b to ensure that the algorithm above runs in time On log c
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