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

Heather #8

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

Heather #8

wants to merge 2 commits into from

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.

return output
end

# 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