Skip to content

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

👍 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