3 ms·
I don’t understand why reversing a binary tree has become a favorite punching bag of the popular ire against programming interviews. It is an instance of the qu
by vmladenov 6y ago
I don’t understand why reversing a binary tree has become a favorite punching bag of the popular ire against programming interviews. It is an instance of the question: do you understand recursion from a discrete math perspective?
I’ve never been asked this question, so I haven’t “memorized” it as you say, but if you want to flip the order of all the nodes in a binary tree, you’ll need to at least reverse the left and right subtrees at some point. The understanding recursion part is knowing that reversing the subtrees is the same operation as reversing the main tree. In that way, it’s similar to the recursive solution to the Tower of Hanoi.