Question: Given an array [ a 1 , a 2 , . . . , an ] , a reversal is a pair ( i ,
Given an array a a an a reversal is a pair i j 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 is
a points What is the expected number of reversals in a random array? More formally,
consider a uniformly random permutation of n distinct elements a an: what is the
expected number of reversals? Give your answer precisely, without asymptotic notation.
Prove your answer.
b points Recall the insertion sort algorithm:
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
