Incorrect (?) time complexities for Heap operations
See original GitHub issueAccess 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:
- Created 6 years ago
- Reactions:3
- Comments:10 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Thanks @EugenHotaj and I see what you mean @yangshun I’ll merge your PR now. Thanks for the contribution!