359 views
0 votes
0 votes

In a max heap of n elements, the time complexity to find 10th largest element is:

a)Θ(n log n)

b)Θ(n)

c)Θ(1)

d)Θ(log n)

 

I personally think it should be Θ(n), as the 10th largest element can be anywhere in the heap, all the elements need to be traversed once to decide that.

3 Answers

Best answer
2 votes
2 votes

The answer must be O(logn). The simple time complexity to find K th largest element from a max heap is O(K*logn). For 10 it will be O(10*logn), so answer must be D. The time complexity can be O(n), but that would be a naive approach and this is a much optimised approach!
However under no circumstance can the time complexity be O(1). 
So answer must be D.

selected by
2 votes
2 votes
D is answer

extract out max 10 times , and extract max take O(log n) *10 time = O(log n)
0 votes
0 votes
Answer – C

In a max heap, the largest element is at the root, and each parent node is greater than or equal to its child nodes. Therefore, the 10th largest element in a max heap will be the 10th element when the heap is traversed in descending order.

The time complexity to find the 10th largest element in a max heap is Θ(1). This is because you can directly access the element at the 10th position in the heap without traversing the entire heap or performing any additional operations.

So, the correct option is: Θ(1)

Related questions

796
views
1 answers
0 votes
atulcse asked Jan 16, 2022
796 views
Consider the following graph:Find the total number of max-heap possible orderings with elements 12, 10, 1, 5, 7, 9, 8 such that each element is filled in ... of the above tree and element 10 occupies only the left child node of its parent.
807
views
1 answers
1 votes
srestha asked May 22, 2019
807 views
A stack based CPU executes the instruction. Memory location $500$ contain $0X 88$ and memory location $700$ contain $0X37$. The stack pointer is at $0X003F$The ... contain $0XBF$ after execution of instruction.$D)$ Both $a)$ and $c)$
1.2k
views
3 answers
3 votes
srestha asked May 6, 2019
1,156 views
There is given a infix expression: ... (assume stack is initially empty) ______________they told $5$, but is it correct? Can anyone give some explanation??
5.2k
views
4 answers
7 votes
srestha asked May 5, 2019
5,192 views
Consider a hash table with $N$ slots. It is given that the collision resolution technique used in chaining. Assume simple uniform hashing, what is the probability that the last $k$ slots are ... {r-1}$D)\left ( 1-\frac{k}{N} \right )^{r-1}$