-
Notifications
You must be signed in to change notification settings - Fork 51
Marjan-Pine #14
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?
Marjan-Pine #14
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 Marjan, you have a solid implementation. I left some comments below on complexity. I'm marking this as yellow since the comprehension questions are not filled out. You can resubmit with them filled out for a green! 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.
✨
self.store = [] | ||
|
||
|
||
def add(self, key, value = None): |
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.
✨
self.store.append(HeapNode(key,value)) | ||
self.heap_up(len(self.store)-1) | ||
|
||
def remove(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.
✨ Space and time complexity?
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.
✨ The recursive call stack here is going to make the space complexity O(log n) as each recursive call halves the heap
self.swap(index, parent_node) | ||
self.heap_up(parent_node) | ||
|
||
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.
✨
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.
Thanks for updating. I would note that other big differences between heaps and BSTs are that heaps are semi-ordered and maintain a complete binary tree.
🟢
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up
&heap_down
methods useful? Why?