Question:medium

Let \(H\) be a binary min-heap consisting of \(n\) elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in \(H\)?

Show Hint

In a min-heap, only the minimum is efficiently accessible; finding the maximum requires scanning all leaves.
Updated On: Feb 3, 2026
  • \(\Theta(1)\)
  • \(\Theta(\log n)\)
  • \(\Theta(n)\)
  • \(\Theta(n \log n)\)
Show Solution

The Correct Option is C

Solution and Explanation

To solve this problem, we need to determine the worst-case time complexity for finding the maximum element in a binary min-heap implemented as an array.

  1. Understand the structure of a binary min-heap:
    • A binary min-heap is a complete binary tree where the key at each node is less than or equal to the keys of its children. This means the minimum element is at the root of the heap.
    • The heap is typically represented as an array where, for a node at index i, its left child is at index 2i + 1 and its right child is at index 2i + 2.
  2. Finding the maximum element in a min-heap:
    • Since the heap property only guarantees that the minimum element is at the root, finding the maximum element is not straightforward.
    • The maximum element can only be among the leaf nodes because any parent node will have a smaller value than its children. Thus, examining only the leaf nodes is necessary.
  3. Analyze the structure:
    • In a complete binary tree (such as a heap), approximately half the nodes are leaves.
    • Therefore, in the worst-case scenario, we must inspect each leaf node to determine the maximum element among them.
  4. Calculate the time complexity:
    • Since we need to check approximately half of the n elements, the operation requires \Theta(n) time in the worst case.

Given these points, the correct answer for the worst-case time complexity to find the maximum element in a binary min-heap is \Theta(n).

Was this answer helpful?
0