Question: in pseudocode Problem 3. (20p) Sorting-related problenm Consider the following problem. The input is an array A of size n of integers and some k
in pseudocode
Problem 3. (20p) Sorting-related problenm Consider the following problem. The input is an array A of size n of integers and some k n. The output is the k largest elements of A. For simplification you can assume that it is only required to print output on the screen rather than collecting and returning as an array. The order of the out put is not important. Example: A|2,5,6, 10,1,3]. 3 largest elements: 5,6,10 3.1 (5p) Solution using heaps. Design an algorithm that runs in O(n k log n) time. What is the asymptotic upper bound on k for which your algorithm is still linear in n? 3.2 (5p) Solution using a partition similar to the quickSelect problem. Write the algorithm Show time efficiency of this algorithm. Note. Remember that the algorithm running time depends on the instance. 3.3 (5p) Solution using BSTs. Write the algorithm. Show time efficiency of this algorithm 3.4 (5p) What is the most efficient solution? Think about different instances. Analyze and give examples of best- and worse- cases
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
