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

Sockets-Bita #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Sockets-Bita #24

wants to merge 1 commit into from

Conversation

Bitaman
Copy link

@Bitaman Bitaman commented Oct 3, 2019

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? it does not follow the rule of smaller values in the left side and bigger values on the right side.
Could you build a heap with linked nodes? yes
Why is adding a node to a heap an O(log n) operation? because you only need to check half the nodes each time.
Were the heap_up & heap_down methods useful? Why? yes, because when we add or remove a node we need to bubble it up or down to keep the heap structure.

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.

Not bad, you do have a small bug in heap_down that the heapsort tests found. Take a look and let me know if you have questions.

I'd like you to try to do the time and space complexity, you can't learn if you don't make attempts at it.

return
end
if @store[right_child] == nil
if @store[index] > @store[left_child]

Choose a reason for hiding this comment

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

You should be comparing the keys here.

Suggested change
if @store[index] > @store[left_child]
if @store[index].key > @store[left_child].key

Comment on lines 4 to 5
# Time Complexity: ?
# Space Complexity: ?

Choose a reason for hiding this comment

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

No time or space complexity?

@@ -17,15 +17,23 @@ def initialize
# Time Complexity: ?
# Space Complexity: ?
def add(key, value = key)
raise NotImplementedError, "Method not implemented yet..."
new_node = HeapNode.new(key, value)
new_node_index = @store.length

Choose a reason for hiding this comment

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

I don't think you really need this.

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