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

Evelynn #20

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

Evelynn #20

wants to merge 6 commits into from

Conversation

evelynnkaplan
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Binary search trees care both about the order of a parent-child relationship and a sibling relationship between nodes. In heaps, only the parent-child relationship matters. Siblings are never compared to one another.
Could you build a heap with linked nodes? Yes, you can. I think one advantage of using an array as the underlying data structure is that you could easily look up the children or parent of any node, because look-up time in an array is O(1). Another reason might be that storing pointers for a linked list takes up more space, and pointers are unnecessary for heaps, because looking up the children is always (index + 1) * 2 or (index + 2) * 2.
Why is adding a node to a heap an O(log n) operation? Adding a node to a heap, in the worst-case scenario, requires swapping a node up the tree with parent nodes until you reach the root node. This only takes as many swaps as there are levels of the tree.
Were the heap_up & heap_down methods useful? Why? Yes, very useful, because they put elements in order and it was a good look at recursion.

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.

Great work. You hit all the learning goals here. Well done. Take a look at my comments and let me know if you have any questions.

Comment on lines +5 to +6
# Space Complexity: O(n) where n is the number of items in the list because you are creating a new heap that needs to store n number of items.

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(log n) where n is the number of elements in the heap
# Space Complexity: O(1)

Choose a reason for hiding this comment

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

heap_up is recursive and you have to consider that and it's affect on the call stack in terms of space complexity.

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