5 ms·
was writing DFS from scratch ever needed to perform dev job or was it a thing that stumped 95% of applicants (and let you read some hacker news/email on your ph
by sheeshkebab 10y ago
was writing DFS from scratch ever needed to perform dev job or was it a thing that stumped 95% of applicants (and let you read some hacker news/email on your phone/laptop in the mean time)?
- ng12 10y agoIt only stumped the candidates that clearly wouldn't make it through the rest of the problem. One sixth was a probably a high estimate. DFS for an acyclic graph is about five lines of code and shows me that you A. know a programming language B. can figure out a data structure. I would argue both are needed to perform a dev job.
- DontGiveTwoFlux 10y agoEh, I had to write a DFS the other day at work.
- ap22213 10y agoI've written DFS about 1-2 times a year, on average, for the last 15 years. Why do I need to? Usually, because I need to modify or create a data structure that is kind of graph-like but not quite. If someone didn't know how to write one or at least derive it, they would confuse a lot of people, so yeah it's kind of important.
- lawnchair_larry 10y agoNo, they'd probably look it up, skim a blog for a few minutes, then figure it out and promptly forget. This is no different than forgetting the order of the arguments to socket() and accusing that person of being incapable of writing networking code.
- ap22213 10y agoThe difference is that the arguments to socket() were arbitrarily defined, but DFS is an algorithm. Anyone who has taken a intro data structures course should be able to at least derive the pseudo code for DFS.
- morgante 10y agoIf you ignore the terminology, DFS is basically just recursively walking a graph, something which actually happens all the time in most dev jobs. I'm sure I wrote a DFS long before I had heard the term. I hate brain teaser interviews as much as the next guy, but being able to do basic operations on basic data structures is pretty much the minimum to be a developer.
- vonmoltke 10y ago> If you ignore the terminology, DFS is basically just recursively walking a graph, something which actually happens all the time in most dev jobs. In ten years of full-time professional development I have never needed to recursively walk a graph. Hell, the only data structures in the software I worked on for the first six (real-time signal processing code) didn't use any data structures other than lists, arrays, and C structs. I would not be able to answer the interview question that started this subthread, despite my track record of efficient and well-designed code.
- morgante 10y agoAre you sure? Keep in mind that a graph doesn't always come up and slap you saying that it's a graph. This very comment thread is a graph which is being printed depth-first.
- vonmoltke 10y agoI'm very sure. The signal processing code had no graph structures whatsoever. That's certainly not the case with the NLP code I have been working on for the past 4.5, but I have never personally needed to search the (usually) trees in a structured manner. Most of our code that searches for things doesn't care about the structure of the graph during the search; it just searches a node list. Once the node is found, structure matters. There are some algorithms that use calculations like shortest path and tree height, but I didn't write the code to actually do that.
- djb_hackernews 10y agoDo you think you've ever had to do something as algorithmically complex as recursively walk a graph? Sometimes these questions are used to probe the meta understanding of a candidate and using Graphs/Trees/DFS are universally understood concepts that make doing that easy.