• edited by
1,853 views
5 5 votes

33. Which of the following statements about max heap are true ?
(I) To find the kth largest element in the heap, the time required is $\mathrm{O}(\mathrm{klogn})$, where k is less than the number of element in the heap.
(II) To find the kth smallest element in the heap , the time required is $\mathrm{O}(\mathrm{n})$, where k is less than the number of element in the heap.
(III) Given a pointer to the an element in the heap, if we want to delete the element, and restore back the heap property then we require $\mathrm{O}(\log n)$ time.
( Marks: -0.66 )

  1. $\quad \checkmark$ All are correct

    Explanation:
    All given statements are correct.
    (I) Since, the given heap is a max heap, the root always holds the maximum value. To find the kth largest number in the array we, can perform k-1 heapify operations, and then find the element at the root of the heap. The element at the root of the heap now is the kth largest element.
    (II) Since the given heap is a max heap, hence the smaller element has a great chance of being at the last level in the heap. Since the number of heaps in the last level is $O(n / 2)=O(n)$, therefore we require $\mathrm{O}(\mathrm{n})$ search operations to find the kth smallest number in the heap.
    (III) The question asks that given an index of the heap, to remove that element from the heap, we require O(logn) time. This statement is correct. Suppose we are given the index, then we perform increase key operation on the index of the heap. We, increase the value in that index of the heap to infinity ( a practically high value) and perform heapify on that index. Now, this value comes to the root of the heap. Now, we perform extract min operation on the heap. In , this way we can delete an element from heap, given a pointer to the node.

    Hence, all the statements are correct.
  2. $\times \times$ Only (II) and (III) are correct.
  3. X Only (I) and (III) are correct.
  4. X Only (I) and (II) are correct.

1 Answer

Best answer
2 2 votes

yes all are correct!

In first case to find the kth largest element, do k-1 deletions from the max heap, so k-1 times max-heapify procedure will be called.

T.C (k-1)logn = O(klogn)

• selected by
Position:
Show:

Related questions

0 0 votes
2 answers 2 answers
5.5k
5.5k views
sh!va asked Feb 7, 2017
5,533 views
I. A heap is always nearly complete tree.II. Worst case complexity of heapify operation is O( log n)III. Worst case complexity of build heap operation is O( n log n)a. I ...
0 0 votes
1 1 answer
1.0k
1.0k views
saurav raghaw asked Dec 22, 2018
1,022 views
The time complexity of the most efficient algorithm to determine whether an arbitrary array of size ‘n’, is min-heap or not?(A) O(log n)(B) O(n)(C) O(n logn)(D) O(1)
1 1 vote
1 answers 1 answer
5.4k
5.4k views
Avijit Shaw asked Dec 21, 2018
5,350 views
What is the time complexity of 'deleting any random node from a max or min heap'?
1 1 vote
1 answers 1 answer
3.4k
3.4k views
gmrishikumar asked Dec 1, 2018
3,385 views
What is the time complexity to find the Kth largest element in a Min-Heap? Or equivalently, What is the time complexity to find Kth smallest element in Max-Heap?