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

Fire- Gessica #18

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

Fire- Gessica #18

wants to merge 2 commits into from

Conversation

GeMath18
Copy link

@GeMath18 GeMath18 commented May 5, 2021

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Heaps are a great way to store information in a semi-order and BST must be sorted.
Could you build a heap with linked nodes? It is possible but the time complexity to search for an element would be linear.
Why is adding a node to a heap an O(log n) operation? Adding a node involves placing a node in the next available leaf node and then conducting a series of swaps with its parent until heap order is achieved. Since there are Log n levels to the heap, then adding a node is a O(log n) operation.
Were the heap_up & heap_down methods useful? Why? Yes, they were very useful as helper methods to add or remove a node in a heap.

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.

Overall nice work Gessica, I had one comment on heap_down. Take a look and let me know what questions you have. Otherwise well done.

Comment on lines +4 to +6
# Time Complexity: O(nlog(n))
# Space Complexity: O(n)
def heapsort(list)

Choose a reason for hiding this comment

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

👍 , nice work!

Comment on lines +17 to 19
# Time Complexity: O(log(n))
# Space Complexity: O(log(n))
def add(key, value = key)

Choose a reason for hiding this comment

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

👍

Comment on lines +28 to 30
# Time Complexity: O(log(n))
# Space Complexity: O(log(n))
def remove()

Choose a reason for hiding this comment

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

👍

Comment on lines +60 to 62
# Time complexity: O(1)
# Space complexity: O(1)
def empty?

Choose a reason for hiding this comment

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

👍

Comment on lines +72 to 74
# Time complexity: O(log(n))
# Space complexity: O(log(n))
def heap_up(index)

Choose a reason for hiding this comment

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

👍

left_child = (index * 2) + 1
right_child = (index * 2) + 2

return @store if @store[left_child].nil? || @store[right_child].nil?

Choose a reason for hiding this comment

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

What about if the left child is NOT nil and the right child is? Could the parent need to swap with the sole left child?

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