The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
0 votes
For searching an element from heap,then delete it from heap

Why will it take O(n+log n) time and not O(n log n) time?
asked in Algorithms by Veteran (112k points) | 115 views

1 Answer

+1 vote
you just need to search it first, O(n) & then delete(swap it with last element and call heapify which will take log(n).

T(n) = O(n + log(n))
answered by Active (2.9k points)
but why not nlogn?

I mean + means OR

but here both n and logn required. So, why not nlogn ?

For searching an element from heap,then delete it from heap

searching take O(n) in heap and deletion take O(logn) right for single element.

O(n+logn)= O(n)

search one for loop one function + heapify another function inside main


we are searching and deleting only a single element

Read question  an element.

and + means addition here, it is not RE.

deleting n elements will take O(nlogn) ?
Deleting $n$ elements will take $n \ * \ O(n+logn) \ = O(n^{2})$
oh yes, thanks

Related questions

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
49,782 questions
54,511 answers
75,107 users