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

Amy M #23

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

Amy M #23

wants to merge 2 commits into from

Conversation

amyesh
Copy link

@amyesh amyesh commented Oct 3, 2019

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? A binary search tree is always a heap, but a heap isn't always a binary tree. The left child in a binary search tree is always less than the right child, whereas in a heap, it can be either greater than or less than, as long as it's consistent.
Could you build a heap with linked nodes? Yes
Why is adding a node to a heap an O(log n) operation? Because you're only traversing each level once, not each node.
Were the heap_up & heap_down methods useful? Why? They were very useful as helper methods for the add and remove methods - the heap up and down methods could then be used in other places in the code, potentially, while also making the add and remove methods more readable. A good modular and extensible approach.

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.

Well done, you hit all the learning goals here. Excellent work!

Comment on lines +4 to +5
# Time Complexity: O(nlogn)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

👍

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(logn)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

Since the additional space add causes is due to the 1 item being added to the heap and the log n recursive calls (call stack), this method's space complexity is O(log n)

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(logn)
# Space Complexity: O(n)

Choose a reason for hiding this comment

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

ditto

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