-
Notifications
You must be signed in to change notification settings - Fork 51
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
Pine - Kristel J #15
base: master
Are you sure you want to change the base?
Pine - Kristel J #15
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 Kristel, however there are a few issues with your heap_sort
function and time complexity. Also, you left the comprehension questions blank. I'm grading this as a yellow, but please feel free to resubmit if you would like a green score! Let me know what questions you have!
🟡
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: O(n log n) | ||
Space Complexity: O(n) |
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 and space complexity and overall logic flow are correct, however, your heap_sort
tests are failing. See my comment below!
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: O(log n) | ||
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.
✨ Nice, however, space complexity is O(log n) because of the recursive call stack of the heap_up
operation
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: O(log n) | ||
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.
✨ Very nice, however like above, the space complexity is O(log n) because of the recursive call stack of heap_down
def __str__(self): | ||
""" This method lets you print the heap, when you're testing your app. | ||
""" | ||
if len(self.store) == 0: | ||
return "[]" | ||
return f"[{', '.join([str(element) for element in self.store])}]" | ||
|
||
|
||
def empty(self): |
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: ? | ||
Space complexity: ? | ||
Time complexity: O(log n) | ||
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.
✨ However space complexity is O(log n) because of the recursive call stack
store = self.store | ||
if store[parent].key > store[index].key: | ||
self.swap(parent, index) | ||
self.heap_up(parent) | ||
|
||
def heap_down(self, 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.
✨ Very nice!
|
||
for item in list: | ||
heap = heap.add(item) |
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.
Your failing tests for heap_sort
return AttributeError: 'NoneType' object has no attribute 'add'
. Look at the return value for add
and see if you can figure out why that might be 🤔
What are you setting the heap equal to here? Do you need to be?
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?