-
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
Savannah #18
base: master
Are you sure you want to change the base?
Savannah #18
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.
Well done, you hit the learning goals here. Do look at my comments on Big-O. I liked the helper methods you wrote and how you did the height methods. Great work!
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(log(n)) where n is the number of nodes | ||
# Space Complexity: O(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.
Remember since you're doing this recursively, the system stack will allocate space for each recursive call.
So if the tree is balanced the space complexity is O(log n), if it's widely unbalanced O(n). The same also applies to time complexity.
return 0 if !node | ||
right = longest_tree_path(node.right) | ||
left = longest_tree_path(node.left) | ||
return [right, left].max + 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.
clever!
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(n) where n is the number of nodes | ||
# Space Complexity: O(n) |
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.
The space complexity will be O(n) if the tree is unbalanced (due to the system stack) or O(log n) if the tree is balanced.
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(n) where n is the number of nodes | ||
# Space Complexity: O(n) "" | ||
def bfs |
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.
Niiiice!
@@ -69,6 +68,21 @@ | |||
end | |||
end | |||
|
|||
describe "hieght" do |
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, I will use these for C12, if that's ok.
No description provided.