[1]: https://www.quora.com/What-is-the-algorithmic-approach-to-in...
I always thought it means making one of the leaf nodes a root of the tree. Physically, it would look like taking one of the leaf nodes with your fingers and "hanging" the tree off of it.
What you describe is called “rotation,” and is used to rebalance.
Meaning one could just have the code accessing the tree swap which names it accesses, and the tree would behave as "inverted" with no actual need to invert anything?
def invert(node):
if node is not None:
left = invert(node.left)
right = invert(node.right)
node.left = right
node.right = left
return node node.left, node.right = map(invert, (node.right, node.left)) map(invert, (node.right, node.left))
is definitely not simpler than: invert(node.right), invert(node.left)