Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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
# Time Complexity: O(nlogn + nlogn) = O(nlogn) where n is the size of the list
# 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