-
Notifications
You must be signed in to change notification settings - Fork 41
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
Time - Ross #13
base: master
Are you sure you want to change the base?
Time - Ross #13
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.
Well done Ross, you hit the learning goals here. Nice work!
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def heap_sort(list) | ||
raise NotImplementedError, "Method not implemented yet..." | ||
def heapsort(list) |
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.
👍 But time and space complexity?
# Time complexity: o(1) | ||
# Space complexity: o(1) | ||
def empty? |
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.
👍
# Time complexity: o(log n) | ||
# Space complexity: o(1) | ||
def heap_up(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.
Due to the recursion, the space complexity is O(log n)
# Time Complexity: o(log n) | ||
# Space Complexity: o(1) | ||
def add(key, value = key) |
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.
The space complexity is O(log n) due to recursion.
|
||
# find the min_child | ||
min_i = left_i | ||
if right_i < @store.length |
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.
Nice good catch checking to see if the right index is past the end of the array.
# 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.
👍
# Time Complexity: o(log n) | ||
# Space Complexity: o(1) | ||
def remove() |
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.
👍
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?