UGC-NET Jun 2011 · Queues

MCQ · 2 marks · Problem PROG-DSTR-0020

When the priority queue is represented by max heap, the insertion and deletion of an element can be performed in (queue containing $n$ elements)
  1. A
    $\theta(n)$ and $\theta(1)$ respectively
  2. B
    $\theta(n)$ and $\theta(n)$ respectively
  3. C
    $\theta(1)$ and $\theta(1)$ respectively
  4. D
    None of the above

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionIn a binary max-heap of \(n\) elements: insertion places the new key at the end and sifts it up the height of the heap, \(\Theta(\lg n)\) in the worst case; deletion of the maximum moves the last key to the root and sifts it down, \(\Theta(\lg n)\).\[\text{insert}=\Theta(\lg n),\qquad\text{delete}=\Theta(\lg n).\]None of (A), (B), (C) gives this pair.Answer: D

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com