Live data from Hacker News

Ask HN: Have you ever needed to invert a binary tree at work?

news.ycombinator.com

11–20 of 22 posts

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#11

0, but you need it to get work. Just be pragmatic about it. The same way you've learned a lot of crap at school for nothing, do you expect that in the job market it would be any different? The world is fucked up, the earlier you internalise this in yourself, the less you suffer.

I hate that you're right. But you're right.

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#12
I've used trees for data, but never had to invert one.

TBH asking that kind of question at interview is a big red flag for me, means that they don't understand how to interview tech people and therefore probably don't understand how to manage tech people.

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#13

What does that even mean? Putting it upside down? But that's just the exact same graph, so a no-op operation? Come to think of it, I wrote a plenty of no-op methods in my career...

It means ordering it in reverse. Mirroring might be a better description.

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#14

I've used trees for data, but never had to invert one. TBH asking that kind of question at interview is a big red flag for me, means that they don't understand how to interview tech people and therefore probably don't understand how to manage tech people.

> TBH asking that kind of question at interview is a big red flag for me, means that they don't understand how to interview tech people and therefore probably don't understand how to manage tech people.

This means Google and others don't understand how to manage tech people... which I guess it may be true.

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#15
As a professional developer, if I am faced with the task of dealing with binary trees at work, I would never:

- implement my own binary tree

- implement my own "invert a binary tree" algorithm

Reasons:

- my own implementation would be way worse than any other open source implementation (which has been reviewed extensively) in terms of: performance, number of bugs, correctness

- it would be a hell to maintain for future developers that have to maintain my code

- it just makes sense. Well understood algorithms do not require re-implementation

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#16

I've used trees for data, but never had to invert one. TBH asking that kind of question at interview is a big red flag for me, means that they don't understand how to interview tech people and therefore probably don't understand how to manage tech people.

> TBH asking that kind of question at interview is a big red flag for me, means that they don't understand how to interview tech people and therefore probably don't understand how to manage tech people. This means Google and others don't understand how to manage tech people... which I guess it may be true.

[deleted]

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#17
So I had to look up what 'invert a binary tree' meant. I was thinking make the leaves roots and the root a leaf, which made no sense.

So flipping the left and right, no I have never had to do that. I have had to write algorithms that processed the tree in infix, prefix and postfix order. And I have had to do it backwards, which is kind of the same but I never changed the tree for that.

As far as an interview question it is testing 2 things, 1) do you even know what a binary tree is, 2) are you comfortable with recursion. And in my case 3) are you willing to admit you do not understand and need an explanation.

From an interview perspective, all 3 are viable questions.

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#18

I've used trees for data, but never had to invert one. TBH asking that kind of question at interview is a big red flag for me, means that they don't understand how to interview tech people and therefore probably don't understand how to manage tech people.

> TBH asking that kind of question at interview is a big red flag for me, means that they don't understand how to interview tech people and therefore probably don't understand how to manage tech people. This means Google and others don't understand how to manage tech people... which I guess it may be true.

Large organisations almost universally don't understand how to manage tech people. HR get in the way and force bad decisions onto even the good managers.

Re: Ask HN: Have you ever needed to invert a binary tree at work?

#20
Inverting a binary tree doesn't achieve anything; the organization is basically the same, being a mirror image, and so doesn't shed any new light on the data.

If you ever have to maintain a code base that happens to invert binary trees, find a way to nuke that code. Whatever needs the binary tree backwards should just process the original order backwards. Then you can say you once needed to remove a silly binary tree inversion at work.

Even reversing arrays and linked lists is suspicious.

Lisp code sometimes does a nreverse pass due to pushing items onto a stack while processing, which reverses their order.

I've never had to reverse an array in C or what have you.

I recall that the block sort algorithm does some clever things with multiple reverses of subranges of an array.

Post reply on HN