Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

Define a copyright and identify what a copyright can protect.

Answered: 1 week ago

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago