Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

15 points/ We have described a randomized algorithm for Selection) in class that runs in linear time. It turns out that there is a deterministic

image text in transcribed

15 points/ We have described a randomized algorithm for Selection) in class that runs in linear time. It turns out that there is a deterministic algorithm that has the same asymptotic performance. More pre- cisesly, there exists an algorithm Det-Selection(A, p,q, r) such that, given an array A, it returns the r-th smallest element in the subarray Alp,.,q] in time O(-p+1). For example, Det-Selection(A, p,q, 1) returns the smallest element in the subarray Alp,.,ql, while Det-Selection(A, p, q, 2) returns the sec- ond smallest element in the subarray Alp,...,q] Using this deterministic version of Selection procedure, give a deterministic version of the QuickSort algorithm that can sort an array in O(n log n) worst case running time. [Hint: Essentially, you need to choose the pivoting element in your Partition procedure more carefully. JYou can assume that all elements in the input array have distinct values. ] More specifically, you would need to provide pseudo-code for procedure Det-QuickSort(A,p, q) which sorts the subarray Alp,...,q] by a QuickSort like procedure (i.e, partition then recursive calls). You can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1,n) You also need to provide the worst case time complexity analysis of your algorithm. 15 points/ We have described a randomized algorithm for Selection) in class that runs in linear time. It turns out that there is a deterministic algorithm that has the same asymptotic performance. More pre- cisesly, there exists an algorithm Det-Selection(A, p,q, r) such that, given an array A, it returns the r-th smallest element in the subarray Alp,.,q] in time O(-p+1). For example, Det-Selection(A, p,q, 1) returns the smallest element in the subarray Alp,.,ql, while Det-Selection(A, p, q, 2) returns the sec- ond smallest element in the subarray Alp,...,q] Using this deterministic version of Selection procedure, give a deterministic version of the QuickSort algorithm that can sort an array in O(n log n) worst case running time. [Hint: Essentially, you need to choose the pivoting element in your Partition procedure more carefully. JYou can assume that all elements in the input array have distinct values. ] More specifically, you would need to provide pseudo-code for procedure Det-QuickSort(A,p, q) which sorts the subarray Alp,...,q] by a QuickSort like procedure (i.e, partition then recursive calls). You can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1,n) You also need to provide the worst case time complexity analysis of your algorithm

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

Step: 3

blur-text-image

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 Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Understand how to design effective service guarantees.

Answered: 1 week ago