The Gateway to Computer Science Excellence
0 votes
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 | 528 views
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.

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
52,218 questions
59,856 answers
118,103 users