News for hackers. Stuff that matters.
Re:They don't even know the fundamentals by nostrebored on Monday November 01, 2021 @08:03AM (#29065614)
Because an implementation of a binary tree is dead simple.
Re:They don't even know the fundamentals by kayodelycaon on Monday November 01, 2021 @09:02AM (#29066162)
I have a computer science degree from 10 years ago and I couldn't tell you how to implement one. I vaguely know the general principles but I'd have to sit down and start from scratch on how to implement one.

Why? The only time I knowingly used them is with database indices. For everything else I do, they are an unnecessary implementation detail. It doesn't matter what Ruby's Set uses.

Re:They don't even know the fundamentals by gameswithgo on Monday November 01, 2021 @09:13AM (#29066257)
People who make this comment, I generally don't believe you, or don't believe you have done any programming. If I put a gun to your head and give you an hour, you can't make a node that points to two other nodes of the same type?

If you really can't, you should get familiar with how data can point to other data, it is fundamental and done all the time.

Re:They don't even know the fundamentals by what_is_orcas on Monday November 01, 2021 @11:33AM (#29068086)
> If I put a gun to your head and give you an hour, you can't make a node that points to two other nodes of the same type?

It's easy to make an imbalanced binary tree.

I once decided that building a binary tree based only on a friend's explanation of how they worked; it seemed like it would be a good learning exercise for myself (I don't have a CS degree). It was like 10 minutes of coding to get it minimally working & tested, but then I had to work out all of the different rotations to make it a balanced binary tree (I don't know that an imbalanced binary tree is ever actually useful, as it could just work out to be a slower linked-list in the worst case scenario).

I did it once, took me a little while, but I don't know that I could do it again without having to reexamine all of the different cases that result in imbalance and the rotations that respond to each.

Re:They don't even know the fundamentals by humen99 on Monday November 01, 2021 @05:46PM (#29073592)
Binary search tree is more difficult than a binary tree. A BST is a BT but a BT is not a BST. So making a normal BT is just pointing nodes.
Re:They don't even know the fundamentals by what_is_orcas on Wednesday November 03, 2021 @09:23AM (#29094221)
Huh... TIL, as they say.
Re:They don't even know the fundamentals by jb1991 on Monday November 01, 2021 @09:15AM (#29066269)
There’s more than making a node the points to other nodes. That’s not what makes a binary tree a binary tree.
Re:They don't even know the fundamentals by nostrebored on Monday November 01, 2021 @11:33AM (#29068073)
I mean… it literally is all there is to it
Re:They don't even know the fundamentals by jb1991 on Monday November 01, 2021 @02:18PM (#29070693)
Well, the requirements I faced were to implement the tree such that nodes were inserted with the standard ordering you would expect. Walking the tree to find the best place to insert them, etc.
Re:They don't even know the fundamentals by maximus-decimus on Tuesday November 02, 2021 @07:55PM (#29089219)
Again, that's stupidly easy. Right is bigger, left is smaller.

If the current node is a leaf, insert left if smaller and right if bigger.

If not a leaf nods, run the method recursively on the left it it's smaller, on the right if it's bigger.

If they asked you to write a self-balancing binary tree it's one thing, but there's nothing tricky about writing a normal ordered binary tree.

Re:They don't even know the fundamentals by derivagral on Monday November 01, 2021 @10:03AM (#29066714)
It isnt the knowledge itself, it is making sure it works and is tested, etc, all in <45m. It serves as a worse fizzbuzz imo.
Re:They don't even know the fundamentals by kayodelycaon on Monday November 01, 2021 @09:36AM (#29066485)
Do you want me to show you a single-linked list or a double-linked one?

    [data, *next] [data, *next] [data, *next] [data, *next] 
If next is null (0), it's the end of the list.
Re:They don't even know the fundamentals by jb1991 on Monday November 01, 2021 @08:40AM (#29065960)
This is an arrogant comment. You are right that the general algorithm of a binary tree is not complicated. But coding it under pressure, for anyone who is not writing that kind of code on a daily basis, which is most people, and especially for a job where you’re not required to write that kind of code, is ridiculous.

If you audition for the New York City ballet, they don’t expect you to ice skate.

Re:They don't even know the fundamentals by Koshkin on Monday November 01, 2021 @08:21AM (#29065768)
Not to those who struggle with the notion of a pointer (or other such “fundamentals”), it’s not.
Re:They don't even know the fundamentals by ClumsyPilot on Monday November 01, 2021 @10:22AM (#29066911)
There are loads of simple tasks, there should be a bit more reasonaing as to why this is a good filter relevant to the job's day to day.

For example I think writing some logic to filter datapoints or timespans is much better and more practical. But it takes more effort than just opening and pocking binary tree.

Re:They don't even know the fundamentals by marcosdumay on Monday November 01, 2021 @12:31PM (#29069045)
The fact that you didn't even think about asking if it's balanced or not, and just went into declaring stupid everyone that considers the problem hard is annoying.

I wouldn't want to have an interview with you, or you selecting people for a team I'm on.

Re:They don't even know the fundamentals by CheezeIt on Monday November 01, 2021 @12:54PM (#29069429)
Why would it be balanced. Nobody said it was a search tree.
Re:They don't even know the fundamentals by marcosdumay on Monday November 01, 2021 @10:27PM (#29076171)
Just the fact that somebody is talking about "implementing" it implies there's further complication than defining a recursive type.

People in general do not communicate on the cleanest ambiguosity-free way;

Re:They don't even know the fundamentals by nostrebored on Tuesday November 02, 2021 @07:47AM (#29079838)
If you can’t remember the details or understand what makes the problem hard I doubt it would’ve been fine even given a whole day.

I’ve interviewed a _lot_ of people. The people who gripe the loudest about algorithms haven’t had a chance just from answers to situational questions.

Re:They don't even know the fundamentals by jhgb on Monday November 01, 2021 @08:19AM (#29065736)
You mean a naive one, that is, a useless one...or a practical one? Such as, at least something like LLRB?
Re:They don't even know the fundamentals by ascar on Monday November 01, 2021 @08:41AM (#29065966)
A binary tree is just a tree data structure where each node has at most two children. And that's dead simple and every programmer should be able to implement that when aksed. Note that it doesn't even have the search (i.e. sorted) requirement and much less the self-balancing one. You can work your way towards that with the right questions and that would be an acceptable way to structure an interview. Start with something simple everyone should be able to do and then work your way up the requirements and discuss potential problems/pitfalls and their solutions.

Nobody talked about implementing a specific variant of a red-black tree when the general topic of self-balancing binary search tree hasn't even be mentioned.

Re:They don't even know the fundamentals by sureglymop on Monday November 01, 2021 @09:12AM (#29066243)
To add to that, a binary tree is often not really "implemented" but simply encoded in an array. That is, the children of any given node i are 2i and 2i+1 in the array.

So depending on the actual exercise/interview question you might able to just show that, especially of you have to use pseudo code.

Re:They don't even know the fundamentals by jhgb on Monday November 01, 2021 @09:21AM (#29066328)
Correct me if I'm wrong, but isn't this exactly the case where you don't want an unbalanced tree? A degenerate tree is bad enough; a degenerate tree implemented as an array in this way is catastrophic. So it seems to me that if you're refining the topic further in some sort of talk, the topic of balancing should precede the topic of physically representing the tree as an array.
Re:They don't even know the fundamentals by ascar on Monday November 01, 2021 @10:27AM (#29066968)
It all depends on the specific topic. If I just want to store my data in binary tree structure without the possibility of deletes and just with an insertion-order requirement, then the tree is automatically balanced and using an array like that is totally fine. The use-cases are probably rare (I can't think of a situation from the top of my head), but binary tree doesn't have to mean search tree.

The self-balancing part is usually added after the search part as balance is trivial/unimportant when the order/position of the elements has no constraints.

Re:They don't even know the fundamentals by jhgb on Monday November 01, 2021 @01:04PM (#29069597)
> The use-cases are probably rare (I can't think of a situation from the top of my head)

I imagine there's quite a lot of them. Things like VP-trees and such get often built statically and could be implemented in a similar way. Not sure if the simple (2i, 2i+1) schema is optimal for this but perhaps it could be adapted.

Re:They don't even know the fundamentals by sureglymop on Monday November 01, 2021 @10:32AM (#29067040)
Yes, you are of course correct. I was thinking of a heap, which is a complete binary tree.
Re:They don't even know the fundamentals by jhgb on Monday November 01, 2021 @08:53AM (#29066091)
It is dead simple. What you're describing (two children, no constraints) is basically a cons cell. Yet I suspect that most people don't use cons cells as binary trees. Which is probably why I didn't understand that apparently rather nebulous topic as being this generic.
Re:They don't even know the fundamentals by magicalhippo on Monday November 01, 2021 @09:38AM (#29066496)
This is another point in which this can be a good interviewing question. For certain jobs you don't want someone who just forges ahead with an unclear specification.

That said, for most dev jobs implementing a binary tree isn't necessary knowledge. But if I need a dev who can get their hands dirty I would be weary of hiring someone who can't take a decent stab at it during an interview.