7 ms·
The majority of working programmers rarely have to write a correct binary search from scratch. Why should you ask it? A better question would be to ask when it'
by sidlls 9y ago
The majority of working programmers rarely have to write a correct binary search from scratch. Why should you ask it? A better question would be to ask when it's appropriate to use the algorithm, and possibly provide a set of data and a scenario (i.e. context) that the candidate might encounter in which using the algorithm is an appropriate solution but not necessarily obviously so, then see if his process of thinking about the problem leads him there.
- joshuamorton 9y agoDoes every language include a generic binary search method? Where? Or similar, if I asked you to find a specific value in a list of Comparable objects, in my language of choice, how would you do it?
- itronitron 9y agoread pseudocode definition of the algorithm and implement in your language of choice, alternatively you could port from one language to another language
- joshuamorton 9y agoIn which case I'm curious why it's an unreasonable interview question. The argument is always "use the stdlib one", but if there isn't one, and you need to implement it, why isn't it fair game?
- itronitron 9y agoit's fair game, but to have the best shot of implementing the algorithm the correct way would be to look up the algorithm definition in a reputable algorithms book and implement directly from that, doing so also provides the developer with additional knowledge and context about the algorithm's use and performance characteristics, my 2 cents
- joshuamorton 9y agoReplace "algo book" with "person asking you the question", and I see relatively little difference.
- mathgeek 9y agoOne difference is that this penalizes people with social anxiety.
- joshuamorton 9y agoDon't all in person interviews do this?
- mathgeek 9y agoSome more than others. It can be mitigated, and probably should be for certain roles.
- sidlls 9y agoI guess it depends on what you're interviewing for. If you want a junior to implement specs he's given your point might apply. It's not an appropriate question for someone with basically any real experience, though. Especially not someone who you expect to do anything more complex, like engineering.
- joshuamorton 9y agoSo now I ask this: Given that google probably does more software interviews than you do, why do you think they ask such questions, even to experienced candidates?
- AnimalMuppet 9y agoRarely have to? For a professional programmer, writing their own binary search for actual use at work is nearly a firing offense (with a very few exceptions). Use the library. Don't write your own. (Yes, I exaggerate. Train such programmers, don't fire them... the first time. But they're wasting your time, and probably introducing bugs in the process. It's deeply unprofessional.)
- notyourwork 9y agoI agree with your sentiment but being over dramatic here.
- Ace17 9y ago> Use the library. Don't write your own. Things are not so simple. Dependencies on 3rd party libs also imply maintenance costs (generally related to the integration of this lib into your build system). They are moderate, however, they don't go away with time. Binary search is a small algorithm, which is easy to understand, and whose correctness is easy to check. It's not a good example of a "good" dependency on a 3rd party lib.
- notyouravgdoge 9y ago> correctness is easy to check This binary search bug took two decades to be discovered: https://research.googleblog.com/2006/06/extra-extra-read-all-about-it-nearly.html https://research.googleblog.com/2006/06/extra-extra-read-all...
- hackinthebochs 9y agoSeems like a good a place as any to note that I actually discovered this bug in high school programming class circa 1999. If only blogging was popular back then I could have been internet famous! (Surely this bug has been rediscovered many times, just predates the self-aggrandizing blog-post-for-everything era)
- throwaway613834 9y ago
- ignoramous 9y agoThe issue is not not being able to write binary-search; but, given a set of constraints, a very well defined set of steps, and ample enough time; is the candidate able to write it in code what's there in their head (a pretty straight forward algorithm). I expect candidates to write in code what they can explain verbally, given that the code is do-able in the confines of an interview. That said, I also get what you're trying to say: Capably implementing Binary Search may not be the best indicator of skill, since Software Engineering is so much more than just converting thought to code.
- eccbits 9y agoRight. There are two ways you get to implementing binary search in an interview: (1) figuring it out from some basics & possibly hints or (2) reciting it from memory. 1 is useful, 2 is useless. Having used inteviewing.io, it facilitates #1 much more than #2, as a good process should. Interviewer ratings help that.
- 549362-30499 9y agoIt's not a complicated algorithm. It's one that people might even use in their every day life (the example I used to use is finding a name in a phone book, I guess that's pretty dated now). I still see candidates who seem to have a conceptual understanding of it fail to translate it into code. That's why I ask it, it's a very simple "here's a thing that intuitively makes sense, now formalize it" question. Maybe this question rules out people who can only copy existing patterns and change values within them, but that's fine as far as I'm concerned. I don't want to hire engineers who can only mimic.
- Retra 9y ago> I don't want to hire engineers who can only mimic. How is a binary search not mimicry? Probably only 1 in a million people could figure out how to do it if they didn't already know how it is done elsewhere. The only reason most people know how binary search works is because they were taught it somewhere along the line. Ask an interviewee how to Voronoi diagram the surface of a sphere or something. Then you'll see how things look when people don't do mimicry. You don't get original ideas by asking first-semester programming puzzles.
- Banthum 9y agoI'm pretty sure I independently invented binary search when I was a child (as have many others). It's a pretty darn obvious thing to do when you're physically handling an ordered collection of records.