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

Alex - Time #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

codesrobertson
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? A heap differs from a BST in that children nodes need to be smaller than parent nodes.
Could you build a heap with linked nodes? Yes, but it's less optimal than using an array.
Why is adding a node to a heap an O(log n) operation? Because a heap has log n levels.
Were the heap_up & heap_down methods useful? Why? The heap_up and heap_down methods were useful because they enabled moving up or down the heap while maintaining order.

@codesrobertson codesrobertson changed the title Adds heap_sort and min_heap methods. Alex - Time Oct 14, 2020
Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work Alex, this is very well done. Thanks again for reminding me.

Comment on lines +1 to +3
# Time Complexity: O(n log n)
# Space Complexity: O(n)
def heap_sort(list)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +24 to 26
# Time Complexity: O(log n)
# Space Complexity: O(log n)
def remove()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +49 to 51
# Time complexity: O(1)
# Space complexity: O(1)
def empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +57 to 59
# Time complexity: O(log n)
# Space complexity: O(log n)
def heap_up(index)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end

# This helper method takes an index and
# moves it up the heap if it's smaller
# than it's parent node.
def heap_down(index)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end

# If you want a swap method... you're welcome
# Thank you, Chris

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants