Question: Given an unsorted array A of n distinct integers and an integer k , you need to return the k smallest integers In the array

Given an unsorted array A of n distinct integers and an integer k, you need to return the k smallest integers In the array in sorted order, where k may be any infeger between 1 and n. Suppose that you have the following three algorithms to solve this problem.
A1: Sort the array in increasing order, then list the first k integers after sorting.
A2: Build a min-heap from these n integers, then call Extract-Min k times.
A3: Use the linear time selection algorithm to find the k-th smallest integer in the array, then partition the array about that number to obtain the k smallest numbers in the array, and finally sort the k smallest numbers.
Assume that you are using mergesort as your sorting algorithm, and use the linear time build heap algorithm to build the heap.Let T1(n, k) denote the worst-case running time of Algorithm A1.Let T2(n, k) denote the worst-case running time of Algorithm A2.Let T3(n, k) denote the worst-case running time of Algorithm A3.Analyze the worst-case running times of the algorithms.
1. What is the asymptotic notation of T1(n, K)? Justify your answer.
2. What is the asymptotic notation of T2(n, K)? Justify your answer.
3. What is the asymptotic notation of T3(n, K)? Justify your answer.
4. Assume that worst-case time complexity is the only metric in choosing algorithms. Among the three algorithms, which algorithm would you choose to solve this problem? Justify why.

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!