5 ms·
To be honest I was a bit taken aback by the author not being able to implement a BFS. It's a fairly standard and really simple algorithm and it's probably one o
by Morgawr 10y ago
To be honest I was a bit taken aback by the author not being able to implement a BFS. It's a fairly standard and really simple algorithm and it's probably one of the most common ones to actually implement because of a need in your day-to-day work.
What do you do if you have a nested data structure (like a tree) and want to print it in order? You write a simple BFS on it.
It's not even a question where you need prior knowledge on the algorithm, it's just logical. He could've easily asked "Print the contents of this tree to screen" and it would've been the same.
I can see how some questions like implementing quick or merge sort can be annoying, most libraries have a sort() function that usually implement either (or similar), you don't often have to write them yourself, but a BFS does not fall into that category in my opinion.
- tptacek 10y agoHold on. I'm not taken aback by their inability to do BFS in an interview at a whiteboard from memory. That, I think, is a total bullshit question, which is why I think the right play there is to one-up them. What I have a problem with is the assertion that a front-end dev shouldn't have to grok BFS. Not "be able to implement from memory", but "be able to quickly implement on demand given a few minutes research".
- hexagonc 10y agoI would agree with you if the author had complained about depth-first search as opposed to breadth-first search. Any decent developer should be able to understand and reason through depth-first search but I wouldn't expect breadth-first search to show up doing front-end web development. In my own side-projects, which involve much more complicated algorithms than anything I've implemented in my day job, breadth-first search has only really come up in one context that wasn't explicitly AI related, and that was a grammar parser. In every other case that I needed to search something, it was depth-first search that I was using. If you're given the whole tree at the beginning, I think most developers would probably start with depth-first search, even if they didn't know the name of the algorithm they were using.
- ljw1001 10y agoNo. if you have a tree, you get an iterator on that tree, and print each element. Because your a pro, so of course your tree is based on a well-tested library component, one that provides a way to iterate it.