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

Sarah Jane Olivas - Spruce - C16 #35

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

Conversation

sjolivas
Copy link

@sjolivas sjolivas commented Jul 21, 2022

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? BST is weakly ordered, heap is not
Could you build a heap with linked nodes? yes, but implementing a linked-list would make the operation less efficient since we would have to check each node for it's next link rather than accessing elements directly like when using an array.
Why is adding a node to a heap an O(log n) operation? In the worst case, we need one swap at each level of the tree. So the total number of the swaps would be equal to the height of the heap tree. The height of a balanced complete tree with n number of nodes is logn. Each swap takes O(1) time
Were the heap_up & heap_down methods useful? Why? yes, very. They are what put everything back in order.

@anselrognlie anselrognlie self-requested a review July 23, 2022 01:39
Copy link

@anselrognlie anselrognlie left a comment

Choose a reason for hiding this comment

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

💫 Overall, a nice implementation, Sarah. For the comprehension questions, we can say that a heap is weakly ordered. There is an ordering property, but it's less strict that the left-right ordering of a BST. And while we could use a linked list for our implementation, this would be much less efficient, since we could not access elements directly via index.

The implementation of heap_down appears to share some code with the instructor solution. As such, I don't feel I can fully evaluate your approach to that implementation. As a result, I am giving the overall implementation a yellow. Yellow does not require a resubmission.

Please let me know if you'd like to discuss this further, or feel free to submit a new implementation for heap_down and I'll re-evaluate.

🟡

heaps/min_heap.py Outdated Show resolved Hide resolved
heaps/min_heap.py Outdated Show resolved Hide resolved
heaps/min_heap.py Outdated Show resolved Hide resolved
heaps/min_heap.py Outdated Show resolved Hide resolved
heaps/min_heap.py Show resolved Hide resolved
heaps/min_heap.py Outdated Show resolved Hide resolved
heaps/min_heap.py Outdated Show resolved Hide resolved
heaps/min_heap.py Show resolved Hide resolved
heaps/min_heap.py Outdated Show resolved Hide resolved
heaps/heap_sort.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants