edited by
29,588 views
82 82 votes

Consider a complete binary tree where the left and right subtrees of the root are max-heaps. The lower bound for the number of operations to convert the tree to a heap is

  1. $\Omega(\log n)$
  2. $\Omega(n)$
  3. $\Omega(n \log n)$
  4. $\Omega(n^2)$

7 Answers

Best answer
87 87 votes

Answer is (A).

Here, lower bound imply best algorithm which works for all cases and hence we should consider worst-case.

Max-Heapify(root).

edited by
47 47 votes

now to make it max heap it take only 2 swap and 4 comparision which is nothing but its height.

Let's level of root node is 0.

Swap: in the worst case, on every level from level-1 ::: 1 swap.

Comparission : in the worst case, on every level, 1 comparission between siblings, 1 comparission with the node from upper level.

As, height of the tree is log n, at every level constant amount of work, so $\log n$ time needed.

Option A is answer.

edited by
11 11 votes
Go ahead guys with next question without wasting your time. It's a poorly formed question. If this question repeats anywhere you will be able to answer Ω(log n) as it is the smallest. If this question repeats with Ω(1) in option then choose Ω(1) only.

Best Case $\rightarrow$ Ω(1)

Worst Case $\rightarrow$ O(log n)
1 flag:
✌ Edit necessary (Tushar Rana “Misdirectional approach.”)
8 8 votes

As to APPLY Heapify(node) to any node its lhs and rhs subtrees must  have to be  HEAP.

Lower bound for heap is its HEIGHT given by log(n)

so it's answer must be A

1 1 vote

🧠 Heapify from Root: What’s the Cost?

  • The tree is complete, so its height is log⁡n.

  • Heapifying the root involves:

    • Comparing it with its children.

    • Possibly swapping with the larger child.

    • Repeating this down the path until the heap property is restored.

So in the worst case, the root travels all the way to a leaf → Θ(log n) operations.

0 0 votes
Here we take the lower bound for the problem.

This is found by the worst case complexity of the best algorithm.

For Example: For sorting problem the lower bound is nlogn -> this means for the worst case the complexity of a sorting algorithm can't be lower than nlogn and is always higher than nlogn (best algorithm say merge sort in terms of time complexity) -> Omega(nlogn).  

Now, The Worst case Complexity of max-heapify is O(logn). So for all cases this is the lowest possible lower bound.

Therefore Option A is right.
Answer:
Position:
Show:

Related questions

106 106 votes
5 answers 5 answers
27.6k
27.6k views
go_editor asked Feb 12, 2015
27,557 views
Which one of the following hash functions on integers will distribute keys most uniformly over $10$ buckets numbered $0$ to $9$ for $i$ ranging from $0$ to $2020$?$h(i) ...
97 97 votes
12 answers 12 answers
26.3k
26.3k views
go_editor asked Feb 12, 2015
26,339 views
A Young tableau is a $2D$ array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked with $\infty$, and hence there cannot be...
52 52 votes
4 answers 4 answers
17.8k
17.8k views
go_editor asked Feb 12, 2015
17,839 views
Consider the C program below#include <stdio.h int *A, stkTop; int stkFunc (int opcode, int val) { static int size=0, stkTop=0; switch (opcode) { case -1: size = val; brea...
59 59 votes
15 answers 15 answers
43.6k
43.6k views
go_editor asked Feb 12, 2015
43,628 views
A binary tree T has $20$ leaves. The number of nodes in T having two children is ______.