-
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
Shirley #27
base: master
Are you sure you want to change the base?
Shirley #27
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, I like how you did the bonus BFS method. Do note that recursion does impact space complexity. Otherwise this is outstanding!
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(logn) | ||
# 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.
Since you're using a recursive add_node
helper method, you are using the system stack and this impacts space complexity. Since you are making O(log n) recursive calls on a balanced tree this would have a space complexity of O(log n).
return 0 unless node | ||
left_counter = height_counter(node.left) | ||
right_counter = height_counter(node.right) | ||
counter = left_counter > right_counter ? left_counter : right_counter |
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.
👍
i += 1 | ||
current = array[i] | ||
end | ||
return array.map do |node| |
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.
Good use of map
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(n) | ||
# Space Complexity: O(2n) |
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.
In Big-O we drop the coefficient so this should be Space complexity of O(n)
No description provided.