-
Notifications
You must be signed in to change notification settings - Fork 34
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
Jessica #3
base: master
Are you sure you want to change the base?
Jessica #3
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work! You hit all the learning goals here. Well done!
@@ -14,18 +14,23 @@ def initialize | |||
end | |||
|
|||
# This method adds a HeapNode instance to the heap | |||
# Time Complexity: ? | |||
# Space Complexity: ? | |||
# Time Complexity: O(n(log(n))) where n is the number of nodes in the heap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are making at most log n
swaps to add something to a heap, the time complexity is O(log n)
return if @store[current_index].key > @store[parent_index].key | ||
|
||
swap(current_index, parent_index) | ||
heap_up(parent_index) | ||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done!
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?