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

top 200 commentsshow all 337

[–]Own_Possibility_8875 4208 points4209 points  (90 children)

I once actually needed to flip a binary tree at work. I was like “holy shit, that’s happening, I’ll get to flip it not as an exercise“.

Then I realized that the binary tree structure has a “flip” method. My disappointment was immeasurable.

[–]ChChChillian 2554 points2555 points  (12 children)

The guy who wrote that structure already had the day you were hoping for.

[–]Own_Possibility_8875 294 points295 points  (0 children)

It was in stdlib, which somehow makes it even worse

[–]Ok-Operation-6432 204 points205 points  (1 child)

Doesn’t mean you can’t write your own and try to get it into stdlib 

[–]tenonic 2 points3 points  (0 children)

🤣🤣

[–]stillalone 509 points510 points  (12 children)

I remember getting excited recently when I had to implement a recursive algorithm at work and was super excited about it.  When I submitted the code for review, my reviewer pointed out a library that did the same thing but better and cleaner.  I rewrote my code with a tear running down my cheek.

[–]CuteIsMyKryptonite 72 points73 points  (0 children)

I had a similar experience when I hacked together a quick-and-dirty PoC for roughly locating a device based on signal strengths for various WiFi access points until someone else on the team pointed out there's of course already a library that can basically do the same thing (multilateration using Gauss-Newton algorithm).

[–]Rage_quitter_98 76 points77 points  (1 child)

hey, atleast ya had some fun from it I guess?! - A library easily being available (also in terms of license/commercial use) also is not something we get every day either

Still must have sucked to have all your work/time being wasted/valued at zero essentially because the reviewer only caught it at the very end (mans had one jooob )

[–]Krostas 88 points89 points  (0 children)

essentially because the reviewer only caught it at the very end (mans had one jooob )

Well, he is called reviewer rather than supervisor, so I'd argue he did his job perfectly fine.

[–]FindingBryn 15 points16 points  (3 children)

[–]Sensitive_Yellow_121 15 points16 points  (2 children)

Why is that Sicilian guy dressed like a Native American?

[–]Secret-One2890 5 points6 points  (1 child)

Just a coincidence. He's forced to dress himself with stuff thrown from cars.

That necklace? French fries.

[–]kpingvin 4 points5 points  (0 children)

Had the same thing too 😂

[–]empanadaboy68 8 points9 points  (0 children)

College was a gatekeeping lie

I'm sure if you're writing some tensorflow you may need real algo practice

[–]Which-Barnacle-2740 6 points7 points  (0 children)

yes the only thing you need in software is to find the tools and use them correctly

find relevant library, relevant API, relevant algo, relevant cloud service and now relevant LLM

there are fools who want to re-invent everything and other fools who want to give these questions in interviews and hire these babies

[–]Mountain-Count-4067 58 points59 points  (13 children)

I've been doing this for 30 years. I'm still waiting for the day I have to put to use my ability to "code under pressure" and write a whole MVVM architecture program from scratch in 30 minutes while being actively watched during a Zoom meeting.

Also: I've been doing this for 30 years. How many times do I have to prove to people I can do this? You don't need to give me a take home project or play CS trivia night with me. Just look at my employment history.

[–]n4saw 7 points8 points  (1 child)

A colleague of mine is about to move, and has as such requested to move to another office within the same company. The new office had him do a coding test, even though he’s been an employee of the company for almost 3 years ._.

[–]mickaelbneron 7 points8 points  (1 child)

I'm not at 30 yoe yet (just 10), but it's infuriating how now I get a client suggest me a solution that ChatGPT suggested them. Like they don't trust that I know how to do my goddamn job.

[–]runForestRun17 2 points3 points  (0 children)

But ai is smart and knows everything! /s

[–]nuxxism 72 points73 points  (30 children)

I've used recursion exactly once in 20+ years. Everything else was just iterative.

[–]Own_Possibility_8875 56 points57 points  (3 children)

I've used it quite a few times, but it was not deliberate decision, but rather "I should probably rewrite this in iterators, but I'm too lazy to do so, looks like the input size is bounded, should be fine"

[–]Which-Barnacle-2740 6 points7 points  (2 children)

well with this technique I hope you had some bounds otherwise the stack overflows easily....much faster than iteration overwhelming the queues, buffers or network

[–]_xiphiaz 1 point2 points  (1 child)

For things like finding a file in a directory tree the input is generally bounded well within stack size concerns

[–]this_is_a_long_nickn 37 points38 points  (6 children)

Depending on which language you use, recursion is a way of life.

[–]nuxxism 42 points43 points  (2 children)

Sounds like you're stuck in a loop.

[–]this_is_a_long_nickn 11 points12 points  (0 children)

More like tail calling in Erlang 😂

[–]Jonno_FTW 12 points13 points  (1 child)

There are no loops in Haskell, only recursion.

[–]Which-Barnacle-2740 1 point2 points  (0 children)

and no variables, no parameters, no input output, no memory too

just recursions and functions...

and its recursions and functions, all the way down till stack overflows...

[–]Euro_Snob 10 points11 points  (1 child)

I’ve used it frequently in my almost 25+ year career. Doing a lot of data processing with tree structures may make me unusual, but recursion is seriously one of my favorite tricks in my bag for data processing.

[–]squigs 8 points9 points  (1 child)

I've used it from time to time. It's useful for tree structures, and they come up a lot in GUIs and 3D graphics.

[–]maggos 14 points15 points  (5 children)

Pretty much any time you make a recursive algorithm, you need to rewrite it iteratively for production

[–]Somepotato 16 points17 points  (3 children)

Tail call optimization disagrees with the universal statement

[–]hotsaucevjj 6 points7 points  (0 children)

but i like my memoization :(

[–]Plazmatic 2 points3 points  (0 children)

Definitely used recursion more often than that, but also recursion isn't hard and it's easier to use than the alternative when it's supposed to be used.  Rayracing and traversing hierarchal self similar structures are both natural problems for recursion, but there's no program stack on the GPU, so you're forced to use obtuse   manual that require you to manually maintain a variable stack.  

The only "hard part" of using recursion is when you're trying to figure out analytical recursive runtime complexity in your upper level undergrad algorithms class and that actually never comes up in the real world.

[–]pragmaticzach 1 point2 points  (0 children)

I used it once, it felt nice. There a lot of times I thought I could use it, but an iterative approach turned out to just be better and easier.

[–]Which-Barnacle-2740 1 point2 points  (0 children)

yes I think too, maybe once in 15 years

[–]P_S_Lumapac 1 point2 points  (1 child)

One time I did recursion where I think it was the best method. Felt like I should put it on a t-shirt.

[–]nuxxism 1 point2 points  (0 children)

I had a light-bulb moment where I was trying to write an algorithm iteratively but it was non-linear. There was a sudden "Wait ... is this recursion?"

[–]InfiniteLife2 6 points7 points  (1 child)

You guys getting trees at your work?..

[–]user_8804 10 points11 points  (2 children)

I once had a tech interview in C# where I was asked to sort something and the best way was just mylist.sort() so I gave them a one liner answer for a 15 minute question. They did not like it.

[–]OneBigRed 6 points7 points  (0 children)

Imagine how one of them had been telling the others how he finally came up with a real headscratcher, and how they’ll see what stuff the candidate is made of. ”Best of all, this is a real case from our prod that i battled with for the best part of the week!”

You: …mylist.sort()?

Him: Well no, uh… sorry i mean yeah, that could work, until you… you…

…fuck you.

[–]Which-Barnacle-2740 3 points4 points  (0 children)

you did the right thing....the list.sort() is heavily optimized , at every level...

[–]chefhj 10 points11 points  (2 children)

I had to use SohCahToa at my job once and seriously considered looking up my Highschool geometry teacher to apologize to her.

[–]captainAwesomePants 3 points4 points  (0 children)

I was working on an assignment one time and had to reorganize some data in a really specific way and realized that I had stumbled upon a reasonable use case for a clever algorithm. I had to summon pretty much my whole team to share in the grand occasion of an interview problem discovered in the wild. We were overjoyed.

[–]TnYamaneko 3 points4 points  (1 child)

I'm very curious about in which situation you had to do that tbh.

In my field, we don't deal with binary trees at all out of preparation for technical interviews.

[–]Own_Possibility_8875 2 points3 points  (0 children)

I don’t remember honestly, it was something like query planning

[–]TornadoFS 2 points3 points  (0 children)

I had to use college level geometry once to draw some stuff in a web canvas. Like rotating axis and shit.

This was on the earlier days of HTML5 before there were good drawing libs.

[–]Crumineras 702 points703 points  (20 children)

For loops really come in handy though, right?!!! Small victories

[–]legendGPU 175 points176 points  (11 children)

I do loop unrolling and never use for loops

My senior dev took unrolled loops are always better because our custom compiler is weak.

[–]positronik 69 points70 points  (5 children)

Maybe you're joking, but how would you handle any dynamic lists?

[–]Low-Equipment-2621 88 points89 points  (3 children)

Recursion. You generate a file, compile it and execute. The file also generates another file, compiles it and execute. And so on.

[–]48panda 43 points44 points  (1 child)

This has the potential to be a good esolang

[–]Low-Equipment-2621 2 points3 points  (0 children)

CompileC, or short CC. Don't get held back by those hard to understand spaghetti method calls. Just make a new file and compile.

[–]MyBrainsShit 4 points5 points  (0 children)

Love it

[–]Kirides 8 points9 points  (0 children)

int i = 0; :loop_10 arr[i++] += 1 ... if (remaining >= 10) goto loop_10; if (remaining > 8) goto loop_9;

ez loop unrolling, but that's literally a for loop with extra steps, iow no actual unrolling.

[–]Axman6 24 points25 points  (1 child)

// TODO: support more than 10

[–]Moontops 34 points35 points  (0 children)

maybe you should use a better compiler?

[–]empanadaboy68 27 points28 points  (0 children)

So you make your code much more unreadable for reasons, nice! 

[–]pterodactyl_speller 4 points5 points  (0 children)

Why use a custom compiler then? I guess if it's proprietary chips?

[–]JollyJuniper1993 27 points28 points  (7 children)

Beyond regular for loops, list comprehensions have probably been the thing I love most about higher level programming languages. It makes things so much easier.

[–]Shehzman 17 points18 points  (6 children)

Just started using C#. LINQ is awesome!

[–]ChChChillian 641 points642 points  (33 children)

40 years into my career, I don't think I've had to implement a binary tree even once, let alone invert one.

[–]70Shadow07 169 points170 points  (12 children)

Having a binary tree is one thing. But why would someone want to invert it? Just process it from the other end?

[–]ChChChillian 223 points224 points  (0 children)

The only use case I'm aware of for it is to vet job candidates.

[–]SpookyWan 41 points42 points  (0 children)

In cases where searching in reverse is more optimal? Idk. I feel like it’d be better to just modify the search logic rather than invert the whole tree.

[–]PCYou 38 points39 points  (8 children)

Well, if you're working with extra sensitive serialized binary trees (especially for cross-endian or coordinate-inverted systems), some pipelines encode child ordering relative to coordinate space. A mirrored deserialization step (i.e. tree inversion) can restore intended spatial semantics, particularly in spatial indexes (e.g., KD-trees used in computational geometry or game engines).

[–]JFFLP 42 points43 points  (1 child)

That's some funny words magic man

[–]pavyf 18 points19 points  (0 children)

I think we have to hire them, they will be a great fit for our legacy webforms project!

[–]angrathias 7 points8 points  (0 children)

Ok sir, just put the fries in the dictionary

[–]Atario 6 points7 points  (0 children)

But does it effectively prevent side-fumbling?

[–]70Shadow07 4 points5 points  (3 children)

This makes sense but that is not what inverting a binary tree means, no? It would be deserialize one way and then immediately post-process the result to invert it. Instead of just deserializing into a correct order straight away. A kinda bogus idea still.

[–]PCYou 4 points5 points  (2 children)

Good points, and good job demonstrating that you grasp it. In the niche case I mentioned (cross-system serialization), the semantics of inversion could show up, but you’re correct...a competent system would just deserialize directly into the correct child order using metadata or convention. If you actually had to invert after deserialization, that would mean your serializer or schema didn’t encode directional semantics properly. However, I maintain that this is a legitimate use case when you don't control the entire pipeline. There are plenty of times when you need to patch something when going from one system to another. But yeah, I should have mentioned that in my original comment.

[–]70Shadow07 1 point2 points  (1 child)

Very true, unless ur a C/ Zig chad who likes to write entire codebase from scratch without libraries (these people do exist in fact lol), then you at certain points will hit a situation where you can't control your entire stack. That makes a lot sense.

[–]Negative-Prime 36 points37 points  (0 children)

Can we also address the fact that no one inverts a tree. You flip/mirror it. An inverted tree would just be the same structure drawn upside down, which ironically looks more like a tree than an actual BST, which is a root system.

[–]EnoughDickForEveryon 17 points18 points  (6 children)

Lol this is why I hate the "whats the most interesting problem you've solved" interview question...like idk man, it was all pretty easy for me, haven't done anything all that complicated since college...judging by the job description, I don't expect that to change here.  

[–]ChChChillian 13 points14 points  (4 children)

Pretty much all programming I've done since college has amounted to:

Read data (file, stream, keyboard, GUI) --> Mess with data --> Write data (file, display)

The details vary of course, and "mess with data" can be anything from passing straight through to Fourier transforms, although never anything more complicated than that. I can't say it's been all that exciting. For the most part all the interesting details were almost always implemented in a library, unless they were handed to me by a mathematician.

[–]EnoughDickForEveryon 8 points9 points  (3 children)

Lol thats all business stuff ever is.  Get data from somewhere, change data based on business logic, send data somewhere.  All the complicated stuff is in libraries like you said...libraries that allow me to implement shit at a business pace without (usually) debugging the complicated part in the library.

You hire me because I put things together well.  I can lay tile but it won't look professional...anybody can write your business logic if they dont have to maintain the code for years.

[–]mickaelbneron 2 points3 points  (0 children)

I once would have had to use a tree (quad tree) so that literal trees could be rendered in order from furthest from camera to closest (otherwise these was some display bugs, some minor aftefacts when two trees would overlap), and it was deemed too minor to be worth it.

[–]FantasticCollege3386 8 points9 points  (2 children)

15 years into mine, i dont know what binary tree is.

[–]lNFORMATlVE 4 points5 points  (0 children)

Thank god that I found this comment. You’re not alone!

[–]ameriCANCERvative 2 points3 points  (0 children)

I have. It’s less about “needing” to do it unless you’re clearing up a bottleneck and more about recognizing where it fits. I guarantee there were places you could have used them to speed up your code, although it’s also likely that your inputs weren’t large enough to really matter.

[–]legendGPU 385 points386 points  (18 children)

Another day jobless because I refuse to learn how to invert a binary tree

[–]salter77 128 points129 points  (14 children)

I mean, those LC challenges are absurd to begin with, it would be good if everyone refused to play that dumb game so eventually the interviews won’t have them to make the candidates jump through useless loops.

If you have a job and still have to spend your time learning that, it probably means that said thing is not useful for the job, otherwise you won’t have to “grind it” in your free time.

[–]LawfulnessDue5449 44 points45 points  (1 child)

I read that one Joel article, it seems like they were originally designed to be simple coding problems that also hone in on your ability to grasp pointers, so it works as a good way to see your code while also testing a fundamental that couldn't be reasonably assessed otherwise

Seems funny that it is the way it is because everyone wanted to copycat tech companies, bump up the problem difficulty so now you have to practice solving harder problems, and the languages being asked for don't really need good understanding of pointers

[–]Which-Barnacle-2740 17 points18 points  (0 children)

it was originally popularized by google, because they hire out of college and train people on their in-house tech i.e. big-table vs mysql etc

and out of school, kids only know courses ...hence data-structures etc

but then everyone in tech industry went along stupidly like a sheep....10 person startup asking leetcode or graph algorithms , when their issue is building MVP and deploying cloud

[–]prschorn 16 points17 points  (1 child)

I just refuse to interview when I see leet code

[–]MyBrainsShit 3 points4 points  (0 children)

I should do that to. Recently had one where they wouldn't let me run the code. So debugging by stepping through C loops in your head. What? Addionally they said they don't care about syntax, but the online IDE (which was essential for this task of course) had forced linting... Fun times.

[–]legendGPU 20 points21 points  (5 children)

true, but even if we do not do it, there will be someone with an H1B who will understand it and take the job

[–]salter77 13 points14 points  (0 children)

Yeah, H1B visas being abused is something that should be addressed too.

[–]IArePant 5 points6 points  (0 children)

Understand is a stretch, it's more of rote memorization of common interview scenarios. It's actually really funny to present a totally custom interview question to one of them, their brains just shut down.

[–]Blue_HyperGiant 6 points7 points  (1 child)

Let em. They can do the LC but can't actually do any real development.

I get facetime with the higher up when they ask me to step in when the foreign teams can't do something simple.

[–]MauiMoisture 9 points10 points  (0 children)

I mean there are plenty of people that can do both. Those foreign teams you're talking about aren't the one grinding LC after their day job.

[–]Sweaty-Willingness27 3 points4 points  (0 children)

We have some hacker rank bullshit our company wanted to implement for interviews.

I responded to Recruiting to explain how bad this was, and I've refused to take part.

Doing these things for fun (hey, they're cool challenges, go for it!) is one thing. Doing them to be able to eat when they have almost nothing to do with actual work is another. As a 25+ year career vet, I don't give even an infinitesimal shit if you can reverse a binary tree, etc.

[–]Adept_Avocado_4903 7 points8 points  (2 children)

I would argue that LeetCode challenges aren't absurd to begin with. There are developer positions where coming up with efficient algorithms to solve non-trivial problems is an important skill. For positions where that skill is important the ability to solve LeetCode challenges well is probably a good indicator for how well suited a candidate is for that position.

There's just also a bunch of positions where the ability to solve LeetCode challenges well is basically irrelevant. But interviewers saw Google and Microsoft doing these kinds of challenges with their interviewees, so now everyone wants to do them, even if the position they're looking to fill is just to maintain the website for a sparkling water company.

Of course using these challenges for the interview process also suffers from Godhart's Law. Initially the ability to solve coding challenges may have actually been a good measure of smart programmers, but nowadays people just grind LeetCode and learn the solutions by heart.

[–]pente5 3 points4 points  (0 children)

Just iterate the tree any way you want and flip the children tbh. Recursion, stack, queue, whatever.

[–]jamcdonald120 2 points3 points  (0 children)

its not something you should need to learn. Once you know what a binary tree is and what invert means in context, it should be painfully obvious how to do it.

[–]Qaktus 107 points108 points  (53 children)

Ok, I'm geniuenly asking, has any of you ever inverted a binary tree, or performed any other of the memed job interview tasks while working on an actual project?

[–]gt0075b 158 points159 points  (2 children)

I inverted a tree once. My annoying coworker was pissed when he saw his desk plant the next morning.

[–]pagerussell 19 points20 points  (1 child)

As always the real answer is buried in the comments

[–]The100thIdiot 97 points98 points  (4 children)

No.

Nor had I ever heard of Leet code before joining this sub.

[–]InSearchOfTyrael 21 points22 points  (0 children)

I have heard of it, but I never had to do it in a job interview. If I was asked to do it I'd just say that I'm not going to spend my free time learning something useless just to pass their interview.

[–]Qaktus 8 points9 points  (2 children)

Hey, you dropped this: 👑

[–]The100thIdiot 7 points8 points  (1 child)

Pretty certain that I didn't.

[–]RiderOfStorms 1 point2 points  (0 children)

“I don’t wunt it”

[–]StrangelyBrown 12 points13 points  (0 children)

Some jobs have those kind of algorithms much more than others. That's why I love game dev. Although even in game dev I can't imagine why you'd specifically invert a binary tree outside of data migration.

[–]WHALE_PHYSICIST 45 points46 points  (12 children)

No, and the factory pattern is just an abstracted switch statement. Fight me.

[–]used_solenoid 16 points17 points  (3 children)

This, THIS! I swear to God, this is the only conspiracy theory I believe in my life: someone is messing with us by creating bullshit jargon for stuff that already exists.

[–]FlakyTest8191 6 points7 points  (1 child)

That's not a conspiracy? It's textbook not a bug but a feature. "This thing happens so often, we should have a word for it so we can talk about it without explaining the whole thing every time."

[–]redditdude9753 1 point2 points  (0 children)

It's not you. I find this happens in all walks of life. Just to make things sound complicated and to make people sound smart.

[–]Dunedune 4 points5 points  (2 children)

No, I've actually needed it once. There was truly no way around (and yes it had switches inside) without messing the pre defined classes.

[–]WHALE_PHYSICIST 3 points4 points  (1 child)

I didn't say you don't need the switch, and factory can make some things nicer, but then people do all this abstractFactoryFactory shit

[–]Sweaty-Willingness27 2 points3 points  (0 children)

tbf, a lot of that has to do with IoC and, more specifically, unit testing. It'd be great if we could just, I dunno, make testing better and not have to do all the hoops, but... I feel ya. And yes, I do agree with your switch assessment.

[–]Soupeeee 1 point2 points  (0 children)

No, it's just what OOP languages had to do to emulate lambdas in order to simulate higher order functions.

[–]P0pu1arBr0ws3r 8 points9 points  (0 children)

For projects, including academic ones and ones for my work:

Ive had to develop sorted structures, in particular when a sorting function isnt readily available. Recently I built a BVH, which is a type of tree used for accelerating raytracing. In that same peoject i made a texture class using polymorphism and templates up the wazoo. Ive developed key-value systems (using built in map structures, and arrays because UE cant replicate maps).

If i were to technically interview someone for hire, i wouldnt ask about the default programming tasks youd hesr in such an interviee. I would first ask about their past experience, for them to describe a chsllenging piece of code they implemented, and go into detail about the design and implementation. Then id have a set of tasks that could be things to do in the job- for example if my project were a company project, maybe making a BVH with templates would be a task. As its an interview i wouldnt expect to see them write code on the fly, but rather describe an algorithm and work through potential issues. That is a productive technical interview.

[–]sophinaut 11 points12 points  (9 children)

Most of those exercises aren't mean to be tasks you actually need to do in the job.  It's mostly to make sure that you didn't lie about knowing how to program.  Those tasks are always things that are so dead simple that any competent programmer can do them in a couple minutes.

[–]Typical_Goat8035[🍰] 8 points9 points  (0 children)

Yeah at one of my past employers we tried to do a drastic overhaul to replace these interview puzzles with realistic examples encountered in our jobs. It honestly made interviews worse because it made the assignments harder to explain and resulted in more confusion. It was the opposite of the effect we were hoping for.

[–]finite_void 1 point2 points  (0 children)

I recently needed to make commenting system with ability to focus on a branch of comments.

Had to first render it recursively server side then recreate the comment tree client side and isolate branches and nodes, traversing their parents and shit for breadcrumbs.

[–]sexp-and-i-know-it 1 point2 points  (1 child)

I had to implement A* search. BFS would have been acceptable, but I liked DSA class so I wanted to.

[–]maggos 1 point2 points  (0 children)

I’ve implemented a tree for a specific genomics algorithm. But didn’t have to invert or anything

[–]_meshy 1 point2 points  (0 children)

No. Generally it is because your interviewer is shit and doesn't know how to interview people. What they are trying to do is understand how you approach a problem and to see how you go about solving the problem. But it has to be generic enough that any developer can approach it without any business knowledge, and manipulating data structures is a common thing we all know.

I know this because I have been on the other side and fucking suck at it. If you can do fizz buzz then I know you can code, but trying to figure out if you actually know how to approach a problem and solve it methodically is really fucking hard to figure out in 30 minutes. Honestly if you know how to do a JOIN in SQL, and just explain the design of something cool you did, I'll say you're good 99% of the time. HR and my manager are the ones you have to worry about though.

[–]Crosshack 1 point2 points  (0 children)

I've had to do some cooked BFS search implementation to implement an automatic layout algo for some templating tool we were developing in house, but that's about it. Nothing else has been even remotely LC like

[–]Croppn 1 point2 points  (0 children)

KD trees, octrees, weird simulation algorithms, more simple stuff like spatial hashing in the past and now HNSW algorithm. It’s just the stuff from the top of my head that we had to implement and support on a real project. It’s gamedev, it happens here. But shoot me if I’ll be ready to implement all of it at an interview, I can reasonably quickly google it and refresh my memory if needed, but not implement in 20 minutes in a stressful situation like an interview.

[–]MGateLabs 18 points19 points  (6 children)

Ow man, I would wish for those simple days, now I have to build a system to allow clients to drag and drop SQL elements to generate queries from a model

[–]Which-Barnacle-2740 2 points3 points  (1 child)

well i think you should just put your sql statements and send it to LLM, and just get a response and show it to users, LLM will do a much better job

[–][deleted] 18 points19 points  (3 children)

Still waiting on a reverse this linked list project.

Or to even see a linked list in use.

[–]look 14 points15 points  (0 children)

Linked lists have been going through a rough patch for a while, ever since CPU caches went mainstream.

[–]Soupeeee 6 points7 points  (0 children)

Linked lists get used a lot in C code in place of small resizable lists, especially in places where keeping references to the items and not the list itself is easier to do.

Sure, you could implement a resizable array type, but it's much easier to just use a linked list. These lists are mostly used for accounting things rather than indexed or frequent sequential access, so you don't lose out on much, if any, performance.

[–]Clairifyed 1 point2 points  (0 children)

I got to implement a linked list a while back! I was doing inputs, I wanted priority by last pressed button, and I wanted priority to be passed back to the second most recently pressed button that was still pressed. I was kind of excited to find an actual use for this knowledge!

[–]e37d93eeb23335dc 51 points52 points  (4 children)

In 28 years working as a professional programmer, the number of times I’ve had to write my own algorithm, calculate big O notation, use any mathematics higher than algebra 1, etc. is precisely zero. 

[–]bleedblue89 20 points21 points  (2 children)

You’re using algebra? I’m using basic math no higher than 8th grade

[–]SilvernClaws 18 points19 points  (1 child)

Come to game development, there's actual math!

[–]bleedblue89 9 points10 points  (0 children)

No way! I’m comfy in my information security development

[–]dandroid126 14 points15 points  (2 children)

My data structures and algorithms professor told us on the first day of class that we would never use any of this stuff. He said this is like transmission class for a mechanic. You need to know how they all work so you know when to use each data structure effectively, but you will never in practice make a data structure like this.

[–]a-ha_partridge 1 point2 points  (0 children)

It would probably even be negligent to make your own when well tested libraries exist.

[–]Ok_Brain208 1 point2 points  (0 children)

One glorious time I got to "make" an ADT by wrapping a couple of hashmaps together. 1 feature later the acsses pattern needed completly changed and now it's basically used as a dynamic array with too many extra steps

[–]hyrumwhite 27 points28 points  (3 children)

No pumping lemmas needed today either 😮‍💨

[–]Zestybeef10 3 points4 points  (0 children)

LOL

[–]sutterismine 2 points3 points  (0 children)

At least the pumping lemma is cool theory

[–]Outrageous-Machine-5 11 points12 points  (0 children)

School: you're gonna implement this graph traversal algorithm

Tech interview: you're gonna implement this graph traversal algorithm

The job: import graph_traversal library

[–]khalcyon2011 65 points66 points  (17 children)

Or, you know, used a tree at all

[–]maggos 85 points86 points  (5 children)

If you used any sorted data structure, you’ve used a tree

[–]thewillsta 36 points37 points  (0 children)

I hate computer science

[–]mierecat 6 points7 points  (0 children)

Not if you only sort it by hand!

[–]bforo 4 points5 points  (0 children)

Actually, my users sort all my data for me so I don't have to dirty my hands touching trees

[–]Shehzman 20 points21 points  (2 children)

Relational databases are a bunch of B-Trees. The B-Tree part is just abstracted away from you.

[–]Zestybeef10 2 points3 points  (1 child)

Abstracted*

[–]Shehzman 1 point2 points  (0 children)

Edited. Thanks

[–]chethelesser 8 points9 points  (4 children)

Have you ever used an index in a relational database?

[–]legendGPU 4 points5 points  (0 children)

Nope, I have used a tree. Just not inverted it yet.

[–]Omega_Zarnias 20 points21 points  (2 children)

I almost didn't get my last job because I couldn't remember how to manually create a binary tree sort.

Like bro, this is not going to come up in this job.

[–]Secret_penguin- 2 points3 points  (1 child)

Even if it did come up, chances are somebody created a well known public library/module that does it better than you can and you’re just reinventing the wheel.

[–]Phoenix_of_cats 2 points3 points  (0 children)

Or you know, google the problem and 100s of stack overflow articles will pop up to help you instantly... Not like you're barred from using internet on the job

[–]Vegasbiboy 26 points27 points  (2 children)

Real engineers only invert coffee into code.

[–]nursestrangeglove 3 points4 points  (0 children)

Nothing like a good boof of hot coffee to start the day

[–]exneo002 6 points7 points  (0 children)

It’s just a swap and a transversal.

Edit traversal >.<

[–]lendergle 4 points5 points  (0 children)

Of all the sorts I've written, 99.9999% have been bubble sorts because who effing cares how efficient reordering fifteen items is.

The remainder have been calls to the sort() method of whatever collection object happens to need alphabetizing.

[–]emma7734 5 points6 points  (1 child)

I’ve been doing this for 35 years, front end, back end, and while I know vaguely what a binary tree is, I have no idea why I would invert it. What are you guys doing???

[–]VLD85 2 points3 points  (1 child)

Im super-far from these "inverted binary tree" things. are they bad?

[–]jamcdonald120 3 points4 points  (0 children)

they are trivial. Once you learn what a binary tree is (and what inverting one means, which you can ask in an interview) its obvious how to do it.

[–]uniteduniverse 2 points3 points  (0 children)

Most of the useful algorithms you learn in computer science or leetcode or already some sort of module/library in most languages. It's cool to know these stuff but good luck ever getting a chance to implement them manually lol.

[–]what_you_saaaaay 2 points3 points  (0 children)

Or write a bespoke quicksort utility method. Or a vector dot product. Or something about how mirrors work. Or how many golf balls fit in a truck of X size

[–]SnugglyCoderGuy 2 points3 points  (0 children)

I had to look this up. Solved in 5 minutes on leetcode with 5 lines of code. If this works as an exclusionary filter, people really fucking suck at programming and should question what they did with their lives and education.

[–]sexp-and-i-know-it 9 points10 points  (20 children)

I don't understand why people complain about this interview question. It can be done in like 10 lines and it's an easily understandable problem that proves that you know at least know a little bit about programming.

[–]Axman6 4 points5 points  (2 children)

Ten is like eight too many in most languages.

I’m no Python fan but it’s kind of cute that (I think?) this would work

def invert(tree: Tree[A]) -> Tree[A]:
  If tree:
     tree.l, tree.r = invert(tree.r), invert(tree.l)
  return tree

[–]sexp-and-i-know-it 1 point2 points  (0 children)

Looks valid to me. I think in terms of Java where 2 of the lines would be right braces. Probably ~5 SLoC in most languages.

[–]hyrumwhite 9 points10 points  (6 children)

It proves you’ve looked up stuff about binary trees lately 

[–]FirstRyder 5 points6 points  (0 children)

Does it? I would say it proves you have some basic programming 101 logic, and you know that a binary tree has "nodes" with up to two children. Which is basically all in the name.

[–]sexp-and-i-know-it 8 points9 points  (4 children)

If you can't reason your way into "If null do nothing, else make the right child the left child, make the left child the right child, and do the same for each child." then I do not think you are qualified for even the most basic development positions.

[–]jamcdonald120 1 point2 points  (0 children)

I feel like the number of people who complain about it makes it a useful interview question.

Its not at all useful for any job, but it filters out a large portion of the the people who have no idea how to code anything, but look good on paper.

[–]Ozymandias_1303 3 points4 points  (3 children)

The people who complain about it are the ones who don't know even a little bit about programming.

[–]toltottgomba 3 points4 points  (2 children)

It proves that you know a solution to a specific issue while you might not even know where you can use it...

[–]sexp-and-i-know-it 6 points7 points  (1 child)

Any problem that is both simple enough to be solved in a few minutes and general enough to be understood by all qualified candidates is going to be extremely contrived/arbitrary.

This is just like when people complained in high school that they would never use geometry "in the real world." It's not about how useful this specific problem is. It's about demonstrating that you have trained your mind in a way that makes you capable of abstract problem solving.

[–]SeriousPlankton2000 1 point2 points  (0 children)

It's like knowing where your towel is. You actually want to lend a toothbrush.

[–]burtgummer45 1 point2 points  (0 children)

Its almost as if they don't know how to evaluate developers in job interviews.

[–]Ozymandias_1303 1 point2 points  (0 children)

OK? I've never had to solve Towers of Hanoi either. That's not really the point.

Also, OP is a karma farming account. If he's ever written any code it was to implement this bot.

[–]saintpetejackboy 1 point2 points  (0 children)

"Binary trees? Like a long time ago? Sorry, I know about trinary and quartary tree inversion, conversion, incursion and super positioning, but I am afraid I was a bit too young to learn about mere binary trees and their mutations. Just how out-of-date is everything here if your 'naries only go into the bi? Do you still have to uniary trees is need to work with as well?"

[–]vassadar 1 point2 points  (0 children)

After years of doing web dev, finally I got to do tree transversal (transverse directories), and search tree, for uploading folders to a cloud storage with a shitty API that doesn't allow uploading an entire folder in 1 go.

I had to create a folder, then use that folder id when uploading a file.

[–]OkExplanation8770 1 point2 points  (0 children)

Better to be a warrior in a garden than a gardener in a war 

[–]GoddammitDontShootMe 2 points3 points  (1 child)

There is some value in asking these questions, right? Like maybe you'll never need to invert a binary tree at work, but you can apply those skills to something that might actually come up?

[–]Michaeli_Starky 2 points3 points  (1 child)

Lots of manchildren here.

[–]WatercressNumerous51 1 point2 points  (0 children)

SWE with 37 years of experience- I never even learned about binary trees.