-
Notifications
You must be signed in to change notification settings - Fork 41
space katem #25
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
base: master
Are you sure you want to change the base?
space katem #25
Conversation
CheezItMan
left a comment
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 Kate, one minor note on heal_down, and some notes on space/time complexity due to recursion. Otherwise well done.
| # Time Complexity: ? n log(n) | ||
| # Space Complexity: ? O(n) | ||
| 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.
👍
| # Time Complexity: O(logn) | ||
| # 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.
👍 However since you are doing recursion the space complexity is O(log n) due to the call stack.
| # Time Complexity: ? O(logn) | ||
| # 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.
👍 However since you are doing recursion the space complexity is O(log n) due to the call stack.
| elsif right_child_index >= @store.length | ||
| return | ||
| 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.
What if the left child index is less than the length and the value at the left child index is less than the current parent!
| elsif right_child_index >= @store.length | |
| return | |
| end | |
| elsif right_child_index >= @store.length && @store[left_child_index].key >= @store[index].key | |
| return | |
| end |
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up&heap_downmethods useful? Why?