Although I've never asked or been asked it in interview context, reversing a binary tree specifically is probably just checking you understand how to write recursive functions. Binary, because variable number of child nodes would make the code longer and more complex for no good reason. Reverse, because that's the simplest operation you can do at each node.
People in this thread are acting like tree processing is as exotic as theorem proving, and could never have anything imaginable to do with daily work, but every web page is literally a tree!
And it's not like you can't find out of the applicant knows recursion and what a tree is without bringing in memorization, there's just some weird obsession with a very specific type of problem which happens to often involve memorization
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.
> - easy
> - freely available
> - relevent to your job
> then that's pretty much entirely your fault and it has nothing to do with your educational background.
Sure. But reversing a binary tree isn't relevant to most modern software engineers. And when it does become relevant then, like you said, it's easy to learn (on the job).
> It's not even anything that advanced or difficult either.
No but it is something that gets "memorized" for a test (and therefore immediately forgotten afterward).