-
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
Cyndi #15
base: master
Are you sure you want to change the base?
Cyndi #15
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.
You hit the learning goals here and even got Breadth-First-Search. I like how you used stacks & queues to do the iterative solutions (nonrecursive).
Nice work!
@@ -0,0 +1,64 @@ | |||
class TreeNode |
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.
What's this file for?
end | ||
|
||
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: if well balanced, O(h) where h is the height of the tree |
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 could also say O(log n) if it's balanced, except that since you're going to visit each node in the tree, it has to be O(n)
end | ||
|
||
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: if balanced, O(h) where h is the height of the tree |
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 have to visit each node to figure out the height, it's O(n) for time complexity. Space is different.
stack = [] | ||
output = [] | ||
current = root | ||
while current || !stack.empty? |
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.
It's neat how you used stacks here to avoid the recursive solution.
return [] if @root.nil? | ||
queue = [] | ||
output = [] | ||
queue.push(@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.
Niiice!
No description provided.