-
Notifications
You must be signed in to change notification settings - Fork 34
Niv #10
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?
Niv #10
Conversation
CheezItMan
left a comment
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.
Ok so some issues here. Take a look at my comments on time and space complexity and look at my heap-down method. You need to compare the current index with both of it's children, not just the left-child.
| # Time Complexity: ? | ||
| # Space Complexity: ? |
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 you're doing recursion it should be O(log n) for both.
| def find_parent(index) | ||
| parent_index = (index - 1)/2 | ||
| return parent_index | ||
| end |
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.
I like this helper method.
| if @store[parent_index].key <= @store[index].key || index == 0 | ||
| return | ||
| end | ||
| if @store[parent_index].key > @store[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.
Since your prior if statement returns you don't need an if statement here.
| raise NotImplementedError, "Method not implemented yet..." | ||
| puts 'heap down' | ||
| puts to_s | ||
| child_index = 2*index + 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.
You are only finding the left child here. You are not finding the right child.
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
heap_up&heap_downmethods useful? Why?