-
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
Tatiana - sorry it's so late! #26
base: master
Are you sure you want to change the base?
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.
Not bad, take a look at my comments and let me know what questions you have. In particular when you heap up and down you need to compare the values involved to make sure if you need to swap or not.
@@ -1,8 +1,24 @@ | |||
|
|||
require 'pry' |
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.
You can take out pry when submitting things.
|
||
# This method uses a heap to sort an array. | ||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n) followed by O(log n) beacause going through entire array for first operation |
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.
It's actually O(n log n)
which is because you're adding n
elements to the heap which each take log n
time. Then you remove n
elements which takes log n
time each.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(n) followed by O(log n) beacause going through entire array for first operation | ||
# Space Complexity: I am attempting to do it in O(1) |
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're creating a heap and building it up. This is O(n) space complexity.
elsif @store[child_index_right].nil? | ||
swap(index, child_index_left) |
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.
You should always compare the element at index
with child_index_left
. This applies every place in the heap.
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?