Live data from Hacker News

Programmers can’t write algorithms without help

queworx.com

41–50 of 105 posts

Re: Programmers can’t write algorithms without help

#41
post #6

Yet another article showcasing how the tech interview process is fundamentally flawed. Personal anecdote: I recently underwent an interview process for a position in my field of expertise (computer vision) consisting of multiple in-person stages, whiteboard coding, product design and a take-home assignment that required developing a foundational (bubble-sort like) algorithm from scratch. After successfully completing…

It's very weird how some of those tech interviews are done. I've luckily never had to do one of those, but from the YouTube videos of training interviews and example interviews, almost everyone seems to be asked to implement a slight variation on something to be found in a Data Structures & Problem Solving book by Weiss. Great if that is what you'll be doing all day, but regurgitating some way to get the smallest num…

I had an interview question a few weeks ago (writing a JSON parser from scratch) that required me to remember that in python that a for loop allows you to iterate through not just a list but also each of the characters in a string. I forgot about that and spent several minutes wasting time trying to think of a regex-based solution before I remembered that was an option.

Why should an interview question reward you/require you to remember this? If I actually had to solve a real-world problem similar to this, I would google it, see a solution that iterated through the characters with a for loop and go “oh yeah, I forgot you could do that. Duh.” Why am I not allowed to google dumb things? On most days, my brain is focused on high-level abstractions that tie together two or more tools via disparate APIs, why the hell should I remember or think about for loops?

Re: Programmers can’t write algorithms without help

#42
I wish I got asked questions like this.

Usually it's just 'How many years of experience do you have in XYZ?' and it's almost never enough. Doesn't matter if your experience is in something similar ('Oh you used Spring boot! We are looking for Spring MVC!') and of course they just care about decades of 'experience'--doesn't matter if you actually know it well.

Then the job ends up not having any relation to what was posted anyway, so it was all moot.

Yes, I am salty. I am sick of taking 'exciting' opportunities just to end up babysitting software that has no relation to the posted skills/requirements.

Re: Programmers can’t write algorithms without help

#43
post #26
post #2

> Programmers can’t write algorithms without help And that might be a good thing. How often does a normal software engineer have to write bubble sort from scratch in his daily life? If someone from my team came to me telling me he had to sort an array and wrote bubble sort from scratch, then I'd probably not be very happy with that unless there is a really good reason to spend that time on it rather than using an exi…

I've been a developer for almost 2 years (I know not that long) but I have never even heard of bubble sort. Looking it up, it is O(n^2). Is there a reason this is a common interview question? It doesn't seem like a sort one would ever really use, or at least it has very obscure uses. I always thought merge/quick sorts accounted for 99.9% of use cases and only ever really learned about those.

Bubble sort is good for two reasons. First, it's so easy that anybody should be able to remember how to do it. Second, it's slow and everybody should know that and be able to point it out.

It's actually usable for small enough n. I once coded it when I expected n to be 4 or less, and I'm sure the person who replaced it cursed my name when that expectation turned out to be false.

Re: Programmers can’t write algorithms without help

#44

Earlier quoted context omitted.

I picked bubble sort, because it's literally the example from the first sentence of the article: > David Hansson, the creator of Ruby on Rails, admitted in a tweet that he wouldn’t be able to write bubble sort on a whiteboard.

Oh my, I’m that guy today. Whoever said it, I have a super hard time believing DHH couldn’t implement bubble sort on a whiteboard. Am I the only one? I get that people hate whiteboard/algorithm interviews, but bubble sort? for i = 0..n: for j = i..n: if arr[i] > arr[j]: arr[j], arr[i] = arr[i], arr[j] Everyone in this field should be able to do this, maybe not right away, maybe not without bugs, but with help within…

Off the top of my head, I could write selection sort, insertion sort, merge sort, quick sort, and with a few minutes of thinking about it, even heapsort. But bubble sort? It's a useless sort, even worse than selection and insertion sort, which have their advantages in certain circumstances. So I don't bother to remember what the algorithm for bubble sort is in the first place.

Re: Programmers can’t write algorithms without help

#45

The tech lead who doesn't know `len()` but claims to know Python? Yes, they're incompetent. It's okay; it's a common problem in our industry, and easily remedied by study and practice. Chinese is not a great example. Native speakers have trouble reading and writing their own language; it is so complicated that people cannot remember how to write commonly-spoken words or how to read. [0][1] (Choice moment from [1] is…

In their defense, some other languages make the length of a string an attribute/property on a string instance. Python feels like the odd one out here making it a free function you must pass an instance to.

If the tech lead spent a lot of time working with another language that made the length an attribute, I think it would be reasonable for them to need to look it up often.

https://apidock.com/ruby/String/count https://docs.oracle.com/javase/7/docs/api/java/lang/String.h... https://developer.apple.com/documentation/swift/string/30035...

Re: Programmers can’t write algorithms without help

#46
post #28

Earlier quoted context omitted.

I wouldn't be able to write a bubble-sort specifically. But if I were asked to "sort" a set of numbers, I'm sure I'd come up with some unholy combination of bubble, selection, and insertion sort that got the job done. I always have to consult the books to remember the difference between bubble, insertion, and selection sorts. But even without documentation, surely people can write a list of numbers (ex: 9, 4, 5, 3, 2…

Mergesort is also worth looking into.

Merge sort is wonderful. Not only is it as easy to remember as bubble sort, but is there anything else that can work with data that doesn't all fit in memory?

Re: Programmers can’t write algorithms without help

#47
post #28

Earlier quoted context omitted.

I wouldn't be able to write a bubble-sort specifically. But if I were asked to "sort" a set of numbers, I'm sure I'd come up with some unholy combination of bubble, selection, and insertion sort that got the job done. I always have to consult the books to remember the difference between bubble, insertion, and selection sorts. But even without documentation, surely people can write a list of numbers (ex: 9, 4, 5, 3, 2…

Mergesort is also worth looking into.

Strangely enough, I always found quicksort easier to write than Mergesort. But that's probably just how my mind works.

Hmmm... with Mergesort, you gotta be copying the data to new buffers, malloc-ing arrays and new arrays, managing the data etc. etc.

Quicksort can be trivially done in-place. And yes, I know Merge-sort has an in-place variation, but in-place Mergesort is non-intuitive IMO.

-------

I guess merge-sort is easy if you are willing to call malloc / free (or new / delete) over-and-over again. But those functions scare me. I prefer to get things done without dynamic memory, especially if its a whiteboard interview.

Quicksort does require more brainpower than selection / insertion / bubble sorts. But if I were to use a recursive methodology, trying to do quicksort would be my strategy.

Re: Programmers can’t write algorithms without help

#48
post #26
post #2

> Programmers can’t write algorithms without help And that might be a good thing. How often does a normal software engineer have to write bubble sort from scratch in his daily life? If someone from my team came to me telling me he had to sort an array and wrote bubble sort from scratch, then I'd probably not be very happy with that unless there is a really good reason to spend that time on it rather than using an exi…

I've been a developer for almost 2 years (I know not that long) but I have never even heard of bubble sort. Looking it up, it is O(n^2). Is there a reason this is a common interview question? It doesn't seem like a sort one would ever really use, or at least it has very obscure uses. I always thought merge/quick sorts accounted for 99.9% of use cases and only ever really learned about those.

It's not one you'd ever use in practice (I know of no use at least). It's pretty simple to implement given a short description though, so it can be seen as kind of an "advanced" fizzbuzz.

If someone just says "hey, implement bubblesort", that's pretty awful though. Then it's just testing your memory and/or gating by people that studied a particular algorithms curriculum. (Though _many_ intro algorithms courses go through sorting and most of those mention bubble sort probably)

Re: Programmers can’t write algorithms without help

#49
post #2

> Programmers can’t write algorithms without help And that might be a good thing. How often does a normal software engineer have to write bubble sort from scratch in his daily life? If someone from my team came to me telling me he had to sort an array and wrote bubble sort from scratch, then I'd probably not be very happy with that unless there is a really good reason to spend that time on it rather than using an exi…

> And that might be a good thing.

- Graphics

- Machine learning

- Gaming

Imagine yourself working in these fields and not being able to implement algorithms, you wouldn't be a super useful teammate.

Re: Programmers can’t write algorithms without help

#50

Earlier quoted context omitted.

Oh my, I’m that guy today. Whoever said it, I have a super hard time believing DHH couldn’t implement bubble sort on a whiteboard. Am I the only one? I get that people hate whiteboard/algorithm interviews, but bubble sort? for i = 0..n: for j = i..n: if arr[i] > arr[j]: arr[j], arr[i] = arr[i], arr[j] Everyone in this field should be able to do this, maybe not right away, maybe not without bugs, but with help within…

Off the top of my head, I could write selection sort, insertion sort, merge sort, quick sort, and with a few minutes of thinking about it, even heapsort. But bubble sort? It's a useless sort, even worse than selection and insertion sort, which have their advantages in certain circumstances. So I don't bother to remember what the algorithm for bubble sort is in the first place.

Do you learn algorithms by blindly memorizing their steps? There's nothing to remember in bubble sort, if you know that it "bubbles" by swaping the elements you're already done.
Post reply on HN