Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxheap.py #597

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

maxheap.py #597

wants to merge 3 commits into from

Conversation

hemishv111
Copy link

Since Python's heapq implementation does not have built in support for max heap, we can just invert the values stored into the heap so it functions as a max heap. Max heap is better than min heap because we don't actually have to store all N points into the heap, we just need to keep K min points.

Time Complexity: O(N Log(K))
Space Complexity: O(K)

@xlogix xlogix self-assigned this Oct 24, 2019
@xlogix xlogix added Hacktoberfest Not assigned to an issue PR has to be assigned to an issue. labels Oct 24, 2019
@xlogix xlogix added this to the Hacktoberfest milestone Oct 24, 2019
@xlogix
Copy link
Member

xlogix commented Oct 24, 2019

Please raise a new issue or link an existing issue to this PR. Read our contribution guidelines!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Not assigned to an issue PR has to be assigned to an issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants