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.
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.
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.
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.
[data, *next] [data, *next] [data, *next] [data, *next]
If next is null (0), it's the end of the list.If you audition for the New York City ballet, they don’t expect you to ice skate.
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.
I wouldn't want to have an interview with you, or you selecting people for a team I'm on.
People in general do not communicate on the cleanest ambiguosity-free way;
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.
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.
So depending on the actual exercise/interview question you might able to just show that, especially of you have to use pseudo code.
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.
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.
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.
Coding binary tree is not the way to discover that.
Presenting a task and observing people solving it and explaining computation complexity behind their solution and the thinking behind their solution is how you do that.
It's a simple data structures / algorithms question. Can you think in terms of how data is stored in memory? Do you understand the tradeoffs of storing data in one form or another? Can you work with recursive algorithms? Given a challenge of having to think about data in a form you haven't recently, can you wrap your mind around the characteristics of that data structure?
If you're getting asked all this for a ReactJS UI building job, then the interviewer is probably off-base. But otherwise, make sure you're applying for jobs you're suited for. If you don't want a job where coming up with efficient algorithms is important, that's fine - there's plenty of others out there.
If you're using a modern OS, you don't know this. The kernel remaps everything and pretends to give you a linear chunk of memory. You don't know what's in the various caches and what's been paged out of ram completely.
Everything is built on layers of abstraction. C is an abstraction layer that fits poorly into what modern CPUs and operating systems actually do, but everything is programmed to cater to C's assumptions so people don't need to rewrite their programs.
Higher languages don't necessarily use the data structure you think they do and they can switch the implementation details based on the size.
"Simple data structures" are only simple because you pick one specific layer of abstraction to work with.
If I ask if you can do something basic binary tree things, I will also not know if you are brilliant, but I can at least rule out if you are totally clueless or not.
Or you have a candidate who understands binary trees, can implement it but can't regurgitate binary tree operations from the top of their memory.
If they can't recall how balancing is done that would be fine with me, as long as they mention it.
I know dozens of good candidates who can't get there pretty quickly but are really good. I also know dozens of good candidates who can get there pretty quickly but won't be good enough on the job.
You not hiring for backend positions doesn't mean they are not good at the positions. It just means they aren't good at your signals.
Some of my coworkers are not nearly as strong as me when it comes to "CS details" like data structures or programming languages, but they have other attributes which complement me and which are good for the team.
Having a bunch of me's (or any of the others) would be a disaster.
find = lambda k, t: t if t is None or k == t.k else find(k, t.left) if k < t.k else find(k, t.right)
I mean, figuring out how to rebalance a red-black tree after insertion is more demanding, and you could legitimately quibble with my golfing here, but I feel like the reasoning required to write that function (given the tree definition) is just not that advanced. It's like the FizzBuzz of pointers.I implore you get to a state where this isn't hard for you, it will make you capable of more.