-
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
Sara - Branches #28
base: master
Are you sure you want to change the base?
Sara - Branches #28
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.
Overall pretty well done, you hit the main learning goals here. There are some issues with time/space complexity and with heap_down, but otherwise well done. Take a look at my comments and let me know what questions you have.
# Time Complexity: o(logn) | ||
# Space Complexity: o(n) | ||
def heap_sort(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.
👍
# Time Complexity: o(logn) | ||
# Space Complexity: o(logn) | ||
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) | ||
# Space Complexity: o(1) i think | ||
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.
Since heap_down
is recursive this is O(log n) for time complexity just like add
# Time complexity: o(1) | ||
# Space complexity: o(1) | ||
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.
👍
# Time complexity: o(logn) | ||
# Space complexity: o(1) | ||
def heap_up(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.
See add for notes on time complexity, otherwise 👍
return | ||
end | ||
|
||
if @store[left_index].key < @store[right_index].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.
You also need to compare the child to the current element.
if @store[left_index].key < @store[right_index].key | |
if @store[left_index].key < @store[right_index].key && @store[left_index].key < @store[index].key |
if @store[left_index].key < @store[right_index].key | ||
swap(left_index, index) | ||
heap_down(left_index) | ||
else |
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.
else | |
elsif @store[right_index].key < @store[index].key |
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions