|
|
|
|
|
by theamk
2709 days ago
|
|
Huh, what's terrible about it? BFS is exactly what I'd want. Let's make up a synthetic problem, like "the closest friend which has property X". Then you'd first check all of your direct friends for X, then check friends-of-friends for X, then check friends-of-friends-of-friends for X, and so on.
You'd go on forever until you either find a friend with property X, or run out of time/space. This is the classic BFS problem, and I can see how it would make a good interview question. |
|
DFS or IDFS can generally use space proportional to the diameter of the graph, which is far smaller.
That caveat with BFS turns out to be so bad in practice that I've never seen the algorithm used in practice, outside of a classroom. And indeed, I first thought the point of the question was to elicit this complaint. The interviewer wasn't on that page, though.
The problem being asked was considerably more complex than "closest friend with property X". I don't recall the details, but perhaps it was something more like "find the ten shortest friend paths to (a unique but unknown) someone with property X, where those paths share no nodes".