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-Kalki-Heaps #30

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

Fire-Kalki-Heaps #30

wants to merge 2 commits into from

Conversation

KayKay-git
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The BST is an ordered data structure, however, the Heap is not.
Could you build a heap with linked nodes? Yes, but it's easier to implement a heap with an array.
Why is adding a node to a heap an O(log n) operation? 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, it helps to keep the heap organized as it gets re-structured

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.

Get work Kalki, this is quite well done.

@@ -3,6 +3,6 @@
# This method uses a heap to sort an array.
# Time Complexity: ?
# Space Complexity: ?
def heap_sort(list)
def heapsort(list)

Choose a reason for hiding this comment

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

Why the rename?

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.

👍 Nice work with the time/space complexity

Comment on lines +29 to 31
# 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.

👍 Nice work with the time/space complexity

Comment on lines +62 to 64
# 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 +74 to 76
# 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.

👍

if parent_node > 0
return heap_up(parent_node)
end
end
end

# This helper method takes an index and
# 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.

👍 Nice work with the time/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