Just to add something to this, this problem can be solved iteratively in two different ways:
a. Using a stack to mimic the recursion
b. Using a queue, visiting the levels one by one in a BFS fashion and swapping the left and right nodes to invert the tree.
Great visual explanation, Jake.
Just to add something to this, this problem can be solved iteratively in two different ways:
a. Using a stack to mimic the recursion
b. Using a queue, visiting the levels one by one in a BFS fashion and swapping the left and right nodes to invert the tree.
Wonderful points, thank you! I'll add these to the tutorial.