Question: Given an array $ [ a _ 1 , a _ 2 , dots , a _ n ] $ , a reversal is
Given an array $a adots an$ a reversal is a pair $ij$ such that $i j$ but $ai aj$ For example, in the array $$ there are are three reversals $$ Note that the array has no reversals if and only if it is sorted, so the number of reversals can be thought of as a measure of how wellsorted an array isbeginenumerateitem points What is the expected number of reversals in a random array? More formally, consider a random permutation of $n$ distinct elements $adots an$: what is the expected number of reversals? Give your answer precisely, without asymptotic notation. Prove your answer. item points Recall the insertion sort algorithm: beginverbatim for i to n j i while j and Aj Aj swap Aj and Aj j j endverbatim Suppose that our array has $d$ reversals. Prove that the worstcase running time of insertion sort is $Thetan d$item points What does this imply about the emphaveragecase running time of insertion sort as a function only of $n$ That is if we draw a permutation uniformly at random, what is the expected running time of insertion sort in asymptotic notation Note that this is emphnot a randomized algorithm; this is a deterministic algorithm on a random input.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
