-
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
Elle #14
base: master
Are you sure you want to change the base?
Elle #14
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.
Nice work! You hit all the learning goals here. See my notes on space complexity. When you have a recursive method, you have to account for the use of the call stack.
# Time Complexity: O(nlogn),where n is the number of items in the list, | ||
# because the add and remove methods are O(nlogn) | ||
# Space Complexity: O(2n), where n is the number of items in the 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.
So really O(n)
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(nlogn) because heap_up is nlogn, where n is the number of nodes in the heap | ||
# Space Complexity: 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 heap_up
is recursive, you have to account for the space complexity of the system stack.
# These helper methods find the index of the | ||
# current item's parent node, and the indices | ||
# of its left and right children | ||
def find_parent_index(node_index) | ||
return ((node_index-1)/2).floor | ||
end | ||
|
||
def find_left_child_index(node_index) | ||
return node_index * 2 + 1 | ||
end | ||
|
||
def find_right_child_index(node_index) | ||
return node_index * 2 + 2 | ||
end |
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.
Good set of helper methods.
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?