-
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
Ngoc L #25
base: master
Are you sure you want to change the base?
Ngoc L #25
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. Thanks for getting this in. Note my comments on heap_down and on your space complexity overall. You need to remember that recursion incurs some space complexity.
You hit the learning goals here, well done!
while @store[index].key < @store[parent_index].key && parent_index > -1 | ||
swap(index,parent_index) | ||
index = parent_index | ||
if index.odd? |
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.
Actually due to truncation it doesn't matter if the index is even or odd.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
# Time Complexity: O(logn) adding element to end of array is O(1) while heap-up worst case is O(logn) | ||
# 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.
Remember since your heap_up
and heap_down
methods are recursive, you have some space complexity from use of the system stack. So space complexity is O(log n)
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?