Question: In Insertion sort, we use the compare - and - swap operation to do sorting. In this question, we shall use a more general operation

In Insertion sort, we use the compare-and-swap operation to do sorting. In this question, we shall use
a more general operation flip to do sorting.
Let L:a1,a2,dots,an be a list of elements (drawn from a totally ordered set). The flip operation
flip (L,i,j) converts the list a1,a2,dots,ai-1,ai,ai+1,dots,aj-1,aj,aj+1,dots,an
toa1,a2,dots,ai-1,aj,aj-1,dots,ai+1,ai,aj+1,dots,an
i.e. filp(L,i,j) reverses the order of elements in the sublist ai,ai+1,dots,aj-1,aj.
Assuming flip (L,i,j) takes O(j-i) time.
(a) Given a list of elements a1,a2,dots,an such that aiin{0,1},1in. Present an algorithm that
sorts the list in O(nlgn) time. You are allowed to use only the flip operation to rearrange the
elements.
(b) Using the algorithm of Part (a) as a subroutine, present an O(n2lgn)-time algorithm that
sorts a list of n elements, ai,1in, drawn from a totally ordered set.
(Note: You are to reduce sorting to the problem of sorting a list of 0's and 1's. Hence,
presenting an algorithm without using Part (a) will receive a 0 mark.)
 In Insertion sort, we use the compare-and-swap operation to do sorting.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!