Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Shirley #27

wants to merge 2 commits into from

Conversation

shirley1chu
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a 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)

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

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|

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)

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants