Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What does it mean to "invert" a binary tree?


Inverting a binary tree is easy; express the tree as a matrix (laplacian), invert the matrix, then convert that back to a tree. What the canonical question is asking is not inversion.

Since too many people were memorizing inversion, I switched to asking how to evert a binary tree. This leads naturally into a discussion of the 1:1 relationship between complex numbers and cohomology sets, I figure if somebody can get that right, they can be a junior programmer on the team.


"Flip" or "mirror" is probably a better term. It seems the goal is to swap left and right: https://leetcode.com/problems/invert-binary-tree/


I don't get why this one is the meme. Just because it's recursion? Because it's (nearly) pointless? There are so many other algorithms I find more difficult/more tedious.


I think it’s a meme because the home brew author tweeted that he was rejected by Google for failing to invert a binary tree.


Is there a practical reason to do this in a real-world program?


Sure, it’s the binary tree equivalent of reversing an array.


For large enough trees it's probably more efficient to instead just switch from preorder to postorder traversal instead of changing the whole tree.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: