Conversation
There was a problem hiding this comment.
Nice work, you hit the learning goals here. I like the helper methods, they look good. I would suggest either putting them in the TreeNode class or making them private helper methods rather than methods embedded in another method. I feel that inner methods break up the flow of the outer method, making it hard to read.
|
|
||
| # Time Complexity: | ||
| # Space Complexity: | ||
| # Time Complexity: O(logn) if the tree is balanced (best case), O(n) if tree is unbalanced (worst case) |
| # Space Complexity: | ||
| # Time Complexity: O(logn) if the tree is balanced (best case), O(n) if tree is unbalanced (worst case) | ||
| # Space Complexity: O(1) | ||
| def add(key, value) |
There was a problem hiding this comment.
This method could use a bit of a refactor.
|
|
||
| return @output if !@root | ||
|
|
||
| def analyzeInorder(current) |
There was a problem hiding this comment.
An inner method? I suggest either putting this method in TreeNode or making it a private helper method. Output doesn't need to be an instance variable.
| return height_left > height_right ? (height_left + 1) : (height_right + 1) | ||
| end | ||
|
|
||
| findMaxHeight(@root) |
There was a problem hiding this comment.
Just for readability adding a return here would be good.
|
|
||
| # Time Complexity: | ||
| # Space Complexity: | ||
| # Time Complexity: O(n-squared) |
There was a problem hiding this comment.
You hit each node just once, so I would say O(n) instead.
Chris, can we go over big O again?