recategorized by
1,107 views

2 Answers

Best answer
6 votes
6 votes

a) Priority queue is implemented efficiently .For minheap we can say priority of a node is inversely proportional to the weight of a node and similarly for maxheap priority is directly proportional to the weight of a node..

And we know deletion and insertion operation in binary heap(min heap or max heap) takes  O(logn) time..Hence it is an efficient data structure for priority queue implementation assuming almost equal number of insertion and deletion occurs.

If say no of insertion operation is much higher than no of deletion , then unsorted array would be the best data structure for priority queue implementation since insertion in unsorted array does not require finding the appropriate place for insertion hence it will take O(1) time for insertion.

b) Maxheap  can  be used efficiently to find kth minimum..Let us see how..Let we have n elements.

 Steps :

1) Build a Max-Heap MH of the first k elements (arr[0] to arr[k-1]) of the given array. O(k)

2) For each element, after the k’th element (arr[k] to arr[n-1]), compare it with root of MH.
……a) If the element is less than the root then make it root and call heapify for MH
……b) Else ignore it.
// The step 2 is O((n-k)*logk)

3) Finally, root of the MH is the kth smallest element.

Time complexity of this solution is O(k + (n-k)*Logk)

In this way we can use the maxheap data structure easily to find kth minimum

Reference : http://www.geeksforgeeks.org/kth-smallestlargest-element-unsorted-array/

Hence option C should be the correct option.

selected by
1 votes
1 votes
I think both i and ii

to find kth largest and smallest element from an array we can do:

sort the array which takes O(nlogn) time and find the largest/smallest: TC= O(nlogn)

Build the max heap and extract largest element : O(n) + O(1) = O(n) time

Build the min heap and extract the smallest element : O(n) + O(1) = O(n) time
Answer:

Related questions

0 votes
0 votes
0 answers
1
iarnav asked Jun 24, 2018
255 views
The number of possible min-heaps containing each value from {1,1,1,1,1,1,1} exactly once is _______This is a variance of Gate 2018 question and how will we deal if all va...
0 votes
0 votes
0 answers
2
Balaji Jegan asked Jun 17, 2018
220 views
What is the recurrence relation / math expression for the number of binary min heaps possible with "n" elements on which "k" elements are repeated "t" times where t=2 to ...
2 votes
2 votes
1 answer
3
Balaji Jegan asked Mar 3, 2018
1,055 views
How many Binary Max-Heaps can be constructed from the elements {1,1,2,2,3,3,4,4} ?
7 votes
7 votes
2 answers
4
Warlock lord asked Dec 5, 2017
1,109 views
From an array of size n , we need to find the k bigger elements. What is the data structure we should use to find k bigger element in best asymptotic complexity? 1.A max ...