-
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
Areeba R - Pine #21
base: master
Are you sure you want to change the base?
Areeba R - Pine #21
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.
💫 Great job Areeba! I left a couple comments on complexity. Let me know what questions you have.
🟢
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: n log n | ||
Space Complexity: 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.
✨ Nice! How might you implement this using the MinHeap
you created below?
@@ -79,3 +131,12 @@ def swap(self, index_1, index_2): | |||
temp = self.store[index_1] | |||
self.store[index_1] = self.store[index_2] | |||
self.store[index_2] = temp | |||
|
|||
def parent_idx(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.
💫 Nice helpers!
left = index * 2 + 1 | ||
right = index * 2 + 2 |
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.
🤔 Why not use your helpers here?
#swap | ||
self.swap(parent, index) | ||
#you would need to keep calling this until you have finally restored the heap | ||
self.heap_up(parent) | ||
|
||
def heap_down(self, index): | ||
""" This helper method takes an index and | ||
moves the corresponding element down the heap if it's | ||
larger than either of its children and continues until | ||
the heap property is reestablished. |
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.
✨ Great job! Love the comments
Time complexity: ? | ||
Space complexity: ? | ||
Time complexity: log n | ||
Space complexity: 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 because of the recursive call stack, space complexity is O(log n) here
Time complexity: ? | ||
Space complexity: ? | ||
Time complexity: 1 | ||
Space complexity: 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.
✨
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: log n | ||
Space Complexity: 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 because of the recursive call stack of heap_down
, space complexity is also O(log n)
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: log n | ||
Space Complexity: 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.
✨ Because of the recursive call stack of heap_up
space complexity is O(log n) here
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?