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

Branches - Farah #25

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

Branches - Farah #25

wants to merge 4 commits into from

Conversation

in-formation
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 BST's left child is less than and right child node is greater than. Essentially a BST is sorted while a heap is not.
Could you build a heap with linked nodes? Apparently, yes but I'm not familiar with this. An array is most common form.
Why is adding a node to a heap an O(log n) operation? Because you are only traversing through half the nodes in the heap.
Were the heap_up & heap_down methods useful? Why? Most of the time, yes. It made it more clear to have these helper functions that broke down add or removing a node into smaller chunks of work.

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, all the methods work, but you didn't have any guesses on time/space complexity.

Comment on lines 4 to +6
# Time Complexity: ?
# Space Complexity: ?
def heap_sort(list)
raise NotImplementedError, "Method not implemented yet..."
def heapsort(list)

Choose a reason for hiding this comment

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

This works, but no guesses on time/space complexity?

@@ -17,15 +19,25 @@ def initialize
# Time Complexity: ?
# Space Complexity: ?
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.

This works, but no guesses on time/space complexity?

@@ -47,7 +59,7 @@ def to_s
# Time complexity: ?
# Space complexity: ?
def empty?
raise NotImplementedError, "Method not implemented yet..."
return true if @store[0] == nil

Choose a reason for hiding this comment

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

Suggested change
return true if @store[0] == nil
return @store[0] == nil

Comment on lines 59 to 61
# Time complexity: ?
# Space complexity: ?
def empty?

Choose a reason for hiding this comment

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

This works, but no guesses on time/space complexity?

Comment on lines 70 to 72
# Time complexity: ?
# Space complexity: ?
def heap_up(index)

Choose a reason for hiding this comment

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

This works, but no guesses on time/space complexity?

Comment on lines 81 to 84
# 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.

👍

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