Multiple choice

In a heap with n elements with the smallest element at the root, the 7th smallest element can be found in time

  1. O(n log n)

  2. O(n)

  3. O(log n)

  4. O(1)

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Here we can follow simple procedure, we can rum heap sort for 7 iterations. In each iteration the top most element is smallest, we note & then replace it with the last element, then we run min heapify algorithm, which brings next smallest element on top. This procedure take 0 (log n) time. We need to run it for 7 times. So tight bound O(7 log n) = O(log n)