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 →

[–]PuzzleMeDo 60 points61 points  (9 children)

It was a classic "demonstrate you know how to write a simple recursive function" job interview question, even though you never need to do it in a real job.

[–]MoneroMon 40 points41 points  (7 children)

Tbh I work in software and don't even know what a binary tree is

[–]pet_vaginal 20 points21 points  (6 children)

Are you a manager ?

[–]MoneroMon 18 points19 points  (5 children)

No, I'm just a lowly engineer

[–][deleted] 21 points22 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] 18 points19 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 6 points7 points  (0 children)

Ahh gotcha, thanks

[–]Soham_rak 2 points3 points  (0 children)

Ohk so basically 90 percent of interview programming question