Question: Given an input array A of length nand a positive integer k >0, design an algorithm that outputs the largest k elements in sorted order
Given an input array
A of length nand a positive integer k >0, design an algorithm that
outputs the largest k elements in sorted
order . Goal( n + klogk)
Question: Given a max heap time complexity is klogn. Can I use a max heap and get T(n)=O(n+ klogk) to retrieve the k largest elements in sorted order? If not, why not. Please provide pseudocode and time complexity analysis as to why building a max heap doesnt result in (n + klogk). I know a max heap of this sort is klogn. I want to understand why max heap doesn't result in O(n+klogk) given that the rooot of a max heap is the highest element in the array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
