My guess is that the potential leaking of some nodes is one of the points of the question. A lot of people would not notice it.
Note that in the original tree each node needs storage for two pointers. After inversion only one is needed. You can use that now unused storage to link together the multiple roots to solve the leak problem.
But note that only consumes the second pointer storage in the roots. Interior nodes end up with some free storage after inversion.
Since inversion is reversible, the binary tree and its inverse contain the same information. Does this mean we should only need one pointer's worth of storage in the binary tree nodes?
Is there something for binary trees similar to Knuth's xor trick for doubly linked lists?
If you invert the tree such that each node points to its parent, and there are no child pointers, you lose information. Namely, the order among children is lost. A given interior node still has two children as before, but it is not known which is the left child and which is the right child; there is just a set of up to two nodes which point to the same parent.
The binary tree inverse specifications/implementations I have looked at preserve the information by selectively using the left or right links. For instance, given:
P
/ \
L R
The inverse would be:
L R
\ /
P
Both children point to the parent. But the left child uses its right pointer, and the right child uses the left pointer. That's what preserves the information about which child is which.
Note that in the original tree each node needs storage for two pointers. After inversion only one is needed. You can use that now unused storage to link together the multiple roots to solve the leak problem.
But note that only consumes the second pointer storage in the roots. Interior nodes end up with some free storage after inversion.
Since inversion is reversible, the binary tree and its inverse contain the same information. Does this mean we should only need one pointer's worth of storage in the binary tree nodes?
Is there something for binary trees similar to Knuth's xor trick for doubly linked lists?