question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect (?) time complexities for Heap operations

See original GitHub issue

Access and Search

I was wondering why access and search are both O(lgn) time complexity? Taking the diagram on your README for example, finding a particular value (for example 2), will involve searching through every node in the Heap. Therefore I think access and search should be both O(n).

Remove Max / Min

As pointed out in #10, remove max / min should be O(lgn) and not O(1).

I can submit a PR to fix the above issues if you like 😄

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kdn251commented, Sep 16, 2017

Hi sorry for the late response guys… By access, I’m assuming that you’re using a heap correctly. Therefore, accessing the min or max value will be O(1) due to the properties of a heap. Search should be lg(n) as you can discard half of each subtree as you traverse the heap again due to its invariants.

0reactions
kdn251commented, Sep 17, 2017

Thanks @EugenHotaj and I see what you mean @yangshun I’ll merge your PR now. Thanks for the contribution!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Complexity analysis of various operations of Binary Min Heap
A Min Heap is a Complete Binary Tree in which the children nodes have a higher value (lesser priority) than the parent nodes,...
Read more >
Time and Space Complexity of Heap data structure operations
In Heap searching is performed linearly, which results in the time complexity of O(N) for all N elements. And, this is the case...
Read more >
What are the time complexities of heap? - Quora
The complexity for building heap is O(n) if you start applying Heapify operation from the lowest non-leaf level up to the root. In...
Read more >
How can building a heap be O(n) time complexity?
Inserting an item into a heap is O(log n), and the insert is repeated n/2 times (the remainder are leaves, and can't violate...
Read more >
Binary heap - Wikipedia
Heap operations Edit ; O(log n) time. ; O(log n). For a random heap, and for repeated insertions, the insertion operation has an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found