Live data from Hacker News

Programmers can’t write algorithms without help

queworx.com

51–60 of 105 posts

Re: Programmers can’t write algorithms without help

#51
post #43
post #26

Earlier quoted context omitted.

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.

For a simple sort you can use for small N, I'd suggest insertion sort. Its constants are better, it performs well on almost-sorted input, and I think it's even easier to implement, personally.

Re: Programmers can’t write algorithms without help

#52
post #9

Shouldn't be a surprise; the person who wrote the algorithm without help took more than 15 minutes, and got a paper or a PhD out of it.

The first time I heard the problem of detecting a circular link in a linked list, I figured out the tortoise/hare solution in probably 15 minutes without having heard it before, so it's not impossible.

Re: Programmers can’t write algorithms without help

#53
Asking hard brainteasers in interviews is questionable but bubble sort is so simple anyone should be able to do it or at least start writing a correct loop to go through the list and put a useful if statement in there.

If you don't remember bubblesort the interviewer could explain what the algo does and then you should be able to implement it. I'm all for looking stuff up on the web and we all have phones in our pockets but if there's to be a minimum bar it shouldn't be lower than bubblesort.

Re: Programmers can’t write algorithms without help

#54
post #51
post #43

Earlier quoted context omitted.

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.

For a simple sort you can use for small N, I'd suggest insertion sort. Its constants are better, it performs well on almost-sorted input, and I think it's even easier to implement, personally.

Yes, I've heard that suggestion many times since then. I wasn't well versed on the different sorts at the time.

Re: Programmers can’t write algorithms without help

#56

Whenever this comes up, I can only assume that people are talking about very different sorts of technical interviews than I’ve ever been subject to. I’ve been working as a programmer for 25 years now and must have been through at least two dozen technical interviews in that time (one just a couple of years ago) and I’ve never had this level of pedantry thrown at me. It sounds like the poster has been rejected from a…

That's my experience as well - 30 years under the belt and I don't see interviews like this nor do I give them. I think the audience here is a bit different, startups are by definition immature and usually don't have the experience or means to set up a proper interview team that screens for the right things.

The flip side is that in mature companies like the one I work for, where professional interviews are more of the rule, we don't get the best candidates, at least not right now. I could imagine that super attractive startups can afford to set the bar higher and still get enough applicants.

Re: Programmers can’t write algorithms without help

#57
post #28

Earlier quoted context omitted.

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 i…

Mergesort sticks in my memory better, for whatever reason. And yes, definitely agree that in real life, avoid those allocations. For a whiteboard interview, declare an std::vector and call it a day, no need to manually call new and delete.

Re: Programmers can’t write algorithms without help

#58
post #4

String length in Python is maybe too much exaggeration unless someone hasn’t wrote Python for a long time. But, algorithms? Sure! Nobody remembers them for ever. Often you at least need to read how the algorithm works before implementing it. Obviously for most devs it is faster to just search for a sample implementation or a pseudocode.

> String length in Python is maybe too much exaggeration unless someone hasn’t wrote Python for a long time.

Or they use several languages. Say you have client side code in JavaScript, with the client served by PHP on the server. You've got some log analysis scripts in Perl. You've got some SOAP services in Java. You've got some machine learning stuff in Python. You've got a mobile app in Swift.

It's real easy to get confused about which of foo.length, strlen($foo), length($foo), foo.length(), len(foo), or foo.characters.count is the right one for the language you are dealing with at the moment.

Re: Programmers can’t write algorithms without help

#59
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…

Is cultural? I always discuss price AT THE START, when was hunting jobs, and now as contractor, and even when I sub-contract.

In the other side, I always pitch "We do this or that, this is what we need help for, and this is how much we can pay (or: how much is your rate?)".

Is an amazing filter. Specially when you don't have much cash to give. Because: If I can't pay... why lost more time? And if I can pay and the other accept it.. only need to solve if is capable.

This is also for my customers. I put a money estimate as soon as possible, or ask upfront what is the budget range.

Is an amazing filter. Because: If I the customer can't pay... why lost more time? And if can pay I only need to solve why I'm a good fit.

The less hidden variables the better for all...

Re: Programmers can’t write algorithms without help

#60

Whenever this comes up, I can only assume that people are talking about very different sorts of technical interviews than I’ve ever been subject to. I’ve been working as a programmer for 25 years now and must have been through at least two dozen technical interviews in that time (one just a couple of years ago) and I’ve never had this level of pedantry thrown at me. It sounds like the poster has been rejected from a…

>It sounds like the poster has been rejected from a job interview for missing a semicolon or writing “length” instead of “len”.

These kinds of anecdotes make me often wonder if candidates are "disqualified" for far more superficial reasons, and if interviewers hone in on pedantry like this to legitimize their reasoning perhaps even unconsciously. I have trouble believing most candidates wouldn't make at least one trivial mistake of that sort and I am equally reluctant to believe the same interviewers would disqualify any given candidate for a mistake so trivial.

Post reply on HN