Skip to content

Conversation

@jetabajrami
Copy link

@jetabajrami jetabajrami commented Sep 28, 2020

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? BSC has a sacrifice order relationship between parent children and siblings(so it guarantees order from “left” to “right”). In a Heap parent has a specific order relationship with its children but children don't have any specific order relationship between (so doen’t guarantees order from “left” to “right”).
Could you build a heap with linked nodes? Yes we could build heap with Linked Nodes. But we do with array because it is more easy by using index.
Why is adding a node to a heap an O(log n) operation? Heap is binary tree and it had a logn levels. If we add a node to a heap we need to swap per tree level.
Were the heap_up & heap_down methods useful? Why? They were useful but they were hard to build. They helped to go through each tree level.

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.

No heapsort solution? Your MinHeap class is well done. Nice work.


def initialize
@store = []
end

Choose a reason for hiding this comment

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

No heapsort method?

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

👍 , nice work with a non-recursive heap_up method.

Comment on lines +64 to 66
# Time complexity: O(logn)
# Space complexity: O(1)
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 +27 to 29
# Time Complexity: O(logn)
# 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.

👍

else
return
end
elsif left && !right

Choose a reason for hiding this comment

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

Nice work catching the scenario where the right is not in the array, but left is.

Comment on lines +81 to 83
# moves it up the heap if it's smaller
# than it's parent node.
def heap_down(index)

Choose a reason for hiding this comment

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

👍

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