-
Notifications
You must be signed in to change notification settings - Fork 44
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
Ports - Elle #9
base: master
Are you sure you want to change the base?
Ports - Elle #9
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.
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.
@@ -16,45 +16,127 @@ def initialize | |||
@root = nil | |||
end | |||
|
|||
# Time Complexity: | |||
# Space Complexity: | |||
# Time Complexity: O(logn) if the tree is balanced (best case), O(n) if tree is unbalanced (worst case) |
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: | ||
# 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method could use a bit of a refactor.
|
||
return @output if !@root | ||
|
||
def analyzeInorder(current) |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for readability adding a return here would be good.
end | ||
|
||
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(n-squared) |
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 hit each node just once, so I would say O(n) instead.
Chris, can we go over big O again?