StreakPeaked· Practice

ExamsGATETechnical

We have a binary heap on n elements and wish to insert n more elements (not necessarily one after another) into this heap. The total time required for this is

  1. Θ(log n)
  2. Θ(n)
  3. Θ(n log n)
  4. Θ(n²)

Correct answer: Θ(n)

Solution

Inserting n elements not necessarily one-by-one means placing all 2n elements and running build-heap (heapify), which is Theta(n). So the total time is Theta(n).

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →