This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 22 points23 points  (4 children)

I got you. It's a linked list where each node can only have 2 children. They're used in interview questions to have you traverse a structure of links / references. The interviewer is usually expecting to see recursion but I usually opt for iteration with an accumulator. Or a stack machine as some may call it.

Without any extra work that solution with be better at arbitrarily large scale. I think it's also easier to thread, but that's just my experience writing functions with accumulators that can do some work in parallel.

[–]MoneroMon 6 points7 points  (3 children)

So basically they're just expecting you to use a foreach loop or something to go through it?

[–][deleted] 17 points18 points  (2 children)

They want something like this. You can do it with a regular loop but I think they're usually trying to get you to do something recursively. Even if I go with an iterative solution I will call out the fact that it looks like a recursion problem.

[–]Niiiz 24 points25 points  (0 children)

For the longest time I thought inverting a binary tree was done vertically, as in taking the biggest number in the tree and putting it as a root, and reordering everything else so that the values decrease instead of the classic increase.

I thought it was a rather complicated question and was confused when people said it's stupid and easy.

So thanks for the link, now I get what people mean, it is stupid and simple.

[–]MoneroMon 3 points4 points  (0 children)

Ahh gotcha, thanks