-
Notifications
You must be signed in to change notification settings - Fork 43
Branches - Julia Bouvier #37
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?
Conversation
… successfully being replaced the old value is still searchable
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.
Really nice work, you hit most of the learning goals here. Very elegantly written code. The only issue is with height, as it's not quite working. Check out my comments and let me know any questions you have.
| # Time Complexity: log(n) | ||
| # Space Complexity: log(n) | ||
| def add(key, value) |
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: log(n) | ||
| # Space Complexity: log(n) | ||
| def find(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.
👍
| end | ||
| end | ||
|
|
||
| def delete(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.
Just noting this isn't working.
|
|
||
| def remove(node) | ||
| if node.left.nil? && node.right.nil? | ||
| node = nil |
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.
This only changes the local variable (node) reference.
| # Time Complexity: O(n) | ||
| # Space Complexity: O(n) | ||
| def inorder |
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) | ||
| # Space Complexity: O(n) | ||
| def preorder |
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) | ||
| # Space Complexity: O(n) | ||
| def postorder |
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) | ||
| # Space Complexity: O(log n) | ||
| def height |
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.
This method isn't actually working. See my note below.
Think about this:
If the node is nil then return 0
If the node is not 0, find the height of the left and the right.
Return the height of the bigger subtree and add one (for the current node).
lib/tree.rb
Outdated
| end | ||
|
|
||
| height_helper(node.left, left + 1, right) | ||
| height_helper(node.right, left, right + 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.
This is only returning the right side's height!
No description provided.