Conversation
kyra-patton
left a comment
There was a problem hiding this comment.
✨ Nice work, Mac! I left a few comments on complexity below. Also technically you could create a heap with a linked list, it's just, as you said, much more convoluted and therefore not advisable.
🟢
|
|
||
| from heapq import heappush, heappop | ||
|
|
||
| def heap_sort(list): |
There was a problem hiding this comment.
✨ Time and space complexity? It would also be great to see you implement heap_sort using the MinHeap you implement below!
| the heap property is reestablished. | ||
| """ | ||
| pass | ||
| left_index = (index * 2) + 1 |
| Time complexity: ? | ||
| Space complexity: ? | ||
| Time complexity: O(1) | ||
| Space complexity: O(n) |
There was a problem hiding this comment.
✨ However time and space complexity are O(log n) here because of the recursive call. heap_up will be called (log n) times because each time you are halving the index
| Time complexity: ? | ||
| Space complexity: ? | ||
| Time complexity: O(1) | ||
| Space complexity: O(1) |
|
|
||
| self.heap_up(len(self.store) - 1) | ||
|
|
||
| def remove(self): |
There was a problem hiding this comment.
✨ However space complexity will be O(log n) because of the recursive call stack of heap_down
| """ Adds a HeapNode instance to the heap | ||
| If value == None the new node's value is set to key | ||
| Time Complexity: O(log n) | ||
| Space Complexity: O(n) |
There was a problem hiding this comment.
✨ However space complexity will just be O(log n) here because of the recursive call stack of heap_up. You aren't creating any other significant data structures.
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up&heap_downmethods useful? Why?