The Gateway to Computer Science Excellence
0 votes
445 views
In a binary min heap with n elements, the 7th smallest element can be found in _____ ?

Answer given is O(logn)

and solution:-

Delete the 1st smallest element O(logn)

Delete the 2nd smallest element O(logn)

....

Delete the 7th smallest element O(logn).

So in total O(logn).

In this solution the data arrangement of the heap will be changed after performing these operation.

any better solution than this???
in Programming by Boss (18.2k points) | 445 views
+6
in min heap, we know that 7th minimum will be present maximum till 7th level, and there will 127 elements till 7th level, so we have to do only constant time comparison, and it will take O(1) time.
0

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,654 questions
56,169 answers
193,881 comments
94,301 users