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 - ALICE D #26

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

Conversation

codeandmorecode
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? A heap must have its rows filled from left to right. Also, a heap does not need to have the left side bigger or smaller than the right side.
Could you build a heap with linked nodes? Yes, but arrays are the preferred class for practicality.
Why is adding a node to a heap an O(log n) operation? If you add the node at the bottom, you must heap the node up, if you apply the node at the top, you must heap the node down. Both the heap up and heap down methods have log n time complexity.
Were the heap_up & heap_down methods useful? Why? Yes, I used them for add, remove, and in turn for heap_sort indirectly.

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 Alice, you hit the learning goals here. Well done.

Comment on lines +16 to +21
list.length.times do
removed = heap.remove()
heapsorted_array << removed
end

return heapsorted_array

Choose a reason for hiding this comment

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

Indentation

Suggested change
list.length.times do
removed = heap.remove()
heapsorted_array << removed
end
return heapsorted_array
list.length.times do
removed = heap.remove()
heapsorted_array << removed
end
return heapsorted_array

Comment on lines +4 to +6
# Time Complexity: O(n log 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.

👍

Comment on lines +17 to 19
# Time Complexity: O(log n)
# Space Complexity: O(1)
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.

👍 , but the space complexity is O(log n) because of heap_up's recursion.

Comment on lines +27 to 29
# Time Complexity: O(log n)
# Space Complexity: O(1)
def remove()

Choose a reason for hiding this comment

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

👍, but the space complexity is O(log n) due to heapdown's recursion

Comment on lines +55 to 57
# 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 +67 to 69
# 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.

👍

Comment on lines +85 to 88
# Time complexity: O(log n)
# Space complexity: O(log n)

def heap_down(index)

Choose a reason for hiding this comment

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

👍 Well done

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