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

Margaret #4

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

Margaret #4

wants to merge 4 commits into from

Conversation

msfinnan
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The left child in a BST is always less than the right child, this is not true in a heap
Could you build a heap with linked nodes? Yes
Why is adding a node to a heap an O(log n) operation? You only have to hit each level of the tree once
Were the heap_up & heap_down methods useful? Why? Yes, they are helpful because when you add a node you add it at the end and need to bubble it up to its proper place. When you remove a node you need to bubble down the swapped node to the end.

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, take a look at my comments and remember the space complexity recursion incurs.

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

Choose a reason for hiding this comment

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

👍 Correct

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(log n)
# Space Complexity: constant

Choose a reason for hiding this comment

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

Since heap_up is going recursively, you will have some space complexity for the system stack.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(log n)
# Space Complexity: constant

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