Skip to content

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?


# 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)


# 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