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

Cyndi #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Cyndi #15

wants to merge 1 commit into from

Conversation

cyndilopez
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.

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

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

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

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?

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiice!

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