754 views
0 votes
0 votes
For a heap containing n elements,smallest element can be found in n/2 operations.I always get confused and think as logn operations.Please help me differentiating between these two times.

1 Answer

0 votes
0 votes
Just remember one simple funda.

Whenever we are dividing "n" or any given variable by 2 till it reaches to the certain value or mostly 0. Then the complexity is logn.

But in the above case, you are just finding the smallest element in the array of size n/2 and not dividing changing n again and again.

So complexity will be equal to O(n/2) = O(n).

Related questions

11.5k
views
1 answers
4 votes
Shashank Chavan asked Jan 18, 2016
11,482 views
What's the difference between Binary tree height, level and depth? Sometimes it's confusing!Does there definition change according to question also, if mentioned?
1.1k
views
1 answers
2 votes
LoveCS asked Dec 5, 2017
1,054 views
453
views
0 answers
0 votes
radha gogia asked Jan 10, 2016
453 views
A weight balanced tree is a binary tree in which for each node, the no. of nodes in the left subtree is atleast half and at most twice the no ... approach for forming a recurrence for finding the height of this weight balanced binary tree ?
1.2k
views
0 answers
1 votes
Rohit Gupta 8 asked Dec 25, 2017
1,179 views
If the average depth of a node in an $n$-node binary search tree is $O(\log{n})$, then the height of the tree is$O(n\log{n})$O(n)$O(\log{n})$O(\sqrt(n\log{n}))$