Skip to content

Conversation

@piffer59
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Only needs to meet the requirements that the tree shape must be complete and the parent node must be larger than its children (max heap) or smaller than its children (min heap)
Could you build a heap with linked nodes? Yes, but it would take longer to access nodes at a specific index, take longer to add and remove nodes
Why is adding a node to a heap an O(log n) operation? Time- there are O(log n) levels of the tree that you have to evaluate, Space - Because it is recursive and will require O(log n) stack calls
Were the heap_up & heap_down methods useful? Why? Yes, they made the methods for adding and removing nodes a lot shorter.

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 all the learning goals here. Well done.

# This method returns true if the heap is empty
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n), where n is the number of nodes in the heap

Choose a reason for hiding this comment

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

Are you adding n nodes to the list, or counting them? No, you're just using .length which is an array instance variable. So this is actually O(1)

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