-
Notifications
You must be signed in to change notification settings - Fork 37
Earth - Jasmine #10
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?
Earth - Jasmine #10
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.
Nice work Jasmine, you hit the learning goals here. Well done.
| # Time Complexity: O(n * log(n)) where n is the number of elements. | ||
| # Space Complexity: O(log(n)) worsecase because of recursion inside of heapify? | ||
| # list = [5, 27, 3, 16, -50] | ||
| 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.
👍 Really nice. However you're using a lot of one letter variable names.
| # Time Complexity: O(log(n)) | ||
| # Space Complexity: O(log(n) due to the stack call in heap_up, could be O(1) using a loop | ||
| 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.
👍
| # Time Complexity: O(log(n)) - where n is the number of elements and log(n) reps the levels | ||
| # Space Complexity: O(log(n) due to the stack call in heap_down, could be O(1) using a loop | ||
| 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.
👍
| # 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)) - n for number of elements. log(n) represents the number of levels. | ||
| # Space complexity: O(log(n)) - the stack for the resursive calls could be as tall as the number of levels. | ||
| 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.
👍
| # 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.
👍
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up&heap_downmethods useful? Why?