← Back to context

Comment by to3m

11 years ago

I wondered this as well! As far as I can tell - I asked google and looked at what it came up with :) - it means swapping children.

I don't even understand why you would ever want to do this. You could just invert the input or output at the beginning or end (depending on what the binary tree is used for) for super cheap. It's not uprising that no one has done this in practice, though it also seems trivial (visit each node once).

  • It's an interview programming question, so what matters is that it's a good interview programming question, not that it's something you would ever want to do. It's an important distinction. Generally you're looking to test candidates' abilities to come up with efficient algorithms to solve problems, which you're not going to get if you ask them to, say, tweak the order that fields are displayed on a web app form (even though that's a "real programming task").

    Although I do see this as something you could possibly do "for real". Sometimes you'd rather change your existing data once than continue carrying forward what amounts to hacks, which is what inverting the output would amount to. Reversing a binary tree would be what you'd run in a tool to migrate all of your data over from the old format to the new format.

Yeah I checked Google as well, but swapping children seemed too easy for an interview question. I'm wondering if it means restructuring the tree so a different node is the root. Trees have the property that any node can be the root and it is still a tree. Not sure just wondering if anyone had more info.

  • It does seem way too easy. Maybe it was the first part in an increasingly difficult several part question, each part building off of the previous part, and the interviewee never made it past the first part in the time allotted?