Consider the process of inserting an element into a Max Heap, where the Max…

2007

Consider the process of inserting an element into a Max Heap, where the Max Heap is represented by an array. Suppose we perform a binary search on the path from the new leaf to the root to find the position for the newly inserted element, the number of comparisons performed is:

Answer: B. θ(loglogn )Answer: Θ(log log n) Key idea: The path from the newly inserted leaf up to the root has length Θ(log n). If you perform a binary search on that path to find…

  1. A.

    θ(logn)

  2. B.

    θ(loglogn )

  3. C.

    θ(n)

  4. D.

    θ(nlogn)

Attempted by 296 students.

Show answer & explanation

Correct answer: B

Answer: Θ(log log n)

Key idea: The path from the newly inserted leaf up to the root has length Θ(log n). If you perform a binary search on that path to find the correct position for the new element, the number of comparisons is logarithmic in the path length.

  • Let h be the path length from the new leaf to the root. For a heap of size n, h = Θ(log n).

  • A binary search on a list of h elements requires Θ(log h) comparisons.

  • Substituting h = Θ(log n) gives Θ(log (log n)) = Θ(log log n) comparisons.

Note: This count refers to the number of comparisons between the new element and ancestor nodes. If you count element moves or swaps required to place the element after locating the position, you may still perform up to Θ(log n) moves, but the comparison count is Θ(log log n) under a binary-search-on-path strategy.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…