DEV Community

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

Collapse
 
belinde profile image
Franco Traversaro

I hoped for a better solution... Recursive functions are limited by the call stack maximum size, so in case of huge trees (or incredibly slim and deep ones) we should linearize the solution. Unfortunately I don't see an easy approach, given the data structure we have; probably we should add an ordered list of visited nodes and try every path from root to the leafs, but I'm on the phone now and it's difficult to write a solution. I'll try today.