-
Notifications
You must be signed in to change notification settings - Fork 40
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
Raisah #24
base: master
Are you sure you want to change the base?
Raisah #24
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.
Well done. You hit all the learning goals here. Nice work.
# Time Complexity: O(nlogn + nlogn) The heapsort will iterate n times through the list to add elements to the heap, taking logn times at worst each time and then the heapsort will iterate n times through the heap to remove elements, taking logn times at worst to remove elements. This reduces to O(nlogn) | ||
# Space Complexity: O(n) the heapsort function creates a heap of n size when sorting. | ||
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.
You can reduce the time complexity to O(n log n). Otherwise this works well.
# Time Complexity: O(logn) At worse, the heap_up function will have to iterate logn times to add a heapnode from the leaf to the root of the heap | ||
# Space Complexity: O(logn) the heap_up function doesn't store additional variables, but does make logn recursive calls to the memory stack in worst case | ||
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(logn) At worse, the heap_down function will have to iterate logn times to remove a heapnode | ||
# Space Complexity: O(logn) the remove function doesn't store additional variables, but does make logn recursive calls to the memory stack in worst case | ||
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(n) checks the length of @store, which varies linearly with the length of the heap | ||
# Space complexity: O(1) variables stay constant regardless of length of heap | ||
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.
Why would this be O(n) time complexity ?
# Time Complexity: O(logn) At worse, the heap_up function will have to iterate logn times to add a heapnode from the leaf to the root of the heap | ||
# Space Complexity: O(logn) the heap_up function doesn't store additional variables, but does make logn recursive calls to the memory stack in worst case | ||
def heap_up(current_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.
👍
raise NotImplementedError, "Method not implemented yet..." | ||
# moves it down the heap if it's larger | ||
# than it's children nodes. | ||
def heap_down(current_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_down
methods useful? Why?