DEV Community

Discussion on: A Visual Guide to How to Actually Invert a Binary Tree

Collapse
 
codinglanguages profile image
Your DevOps Guy

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.

Collapse
 
jacobjzhang profile image
Jake Z.

Wonderful points, thank you! I'll add these to the tutorial.