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 #11

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

Alex #11

wants to merge 3 commits into from

Conversation

alexandria7
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 has less strict rules than a binary search tree. While a BST requires that every child to the left of a node must be less than the node and every child to the right of the node must be greater than the node, a heap requires that all children must be greater than the parent (min heap) or smaller than the parent (max heap).
Could you build a heap with linked nodes? Yes you could, but using an array is preferable since it helps to use an index to look up each value.
Why is adding a node to a heap an O(log n) operation? Because the heap has O(logn) levels and we only have to hit each level once.
Were the heap_up & heap_down methods useful? Why? Yes! These helper methods made adding and removing nodes from a heap much cleaner.

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. You hit the learning goals here. Well done!

Comment on lines +4 to +5
# Space Complexity: O(n) where n is the size of the list

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) where n is the length of the @store
# Space Complexity: O(1)

Choose a reason for hiding this comment

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

Since your heap_down method is recursive you have O(log n) being saved on the call stack.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(logn) where n is the length of the @store
# Space Complexity: O(1)

Choose a reason for hiding this comment

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

see below

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