Open
Conversation
CheezItMan
reviewed
May 3, 2021
Comment on lines
3
to
6
| # # This method uses a heap to sort an array. | ||
| # # Time Complexity: O(n log n) to add elements to a heap and swap them in order at each level | ||
| # # Space Complexity: O(log n) for recursive heap_up in .add | ||
| def heapsort(list) |
There was a problem hiding this comment.
👍 , except that the space complexity is O(n) since you're adding all the elements to a heap here.
Comment on lines
+35
to
+37
| # Time Complexity: O(n log n) to add elements to a heap and swap them in order at each level | ||
| # Space Complexity: O(1) | ||
| def heapsort_in_place(list) |
There was a problem hiding this comment.
👍 This is really nice Christina. Well done !
Comment on lines
+27
to
29
| # Time Complexity: O(log n) to swap for each level | ||
| # Space Complexity: O(log n) for the call stack in heap_down?? | ||
| def remove() |
Comment on lines
+57
to
59
| # Time complexity: O(1) | ||
| # Space complexity: O(1) | ||
| def empty? |
Comment on lines
+68
to
70
| # Time Complexity: O(log n) to swap for each level | ||
| # Space complexity: O(log n) for the call stack | ||
| def heap_up(index) |
Comment on lines
+17
to
19
| # Time Complexity: O(log n) to swap for each level | ||
| # Space Complexity: O(log n) for the call stack in heap_up?? | ||
| def add(key, value = key) |
Comment on lines
+83
to
85
| # moves it down the heap if it's larger | ||
| # than it's children node. | ||
| def heap_down(index) |
There was a problem hiding this comment.
👍 I love the helper methods here, super readable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up&heap_downmethods useful? Why?