|
|
|
|
|
by aavz
3709 days ago
|
|
I'm sorry, but breadth-first-search is a simple and fundamental algorithm and straightforward to write if you understand the concept and have decent coding skills. You're just visiting a level of the tree at a time: stick each level in a list, iterate over it, and append the next level's nodes to the next list. There's no trick to it. Not being able to do write a basic BFS algorithm suggests a) you didn't do any interview prep and b) whatever you've been working on hasn't involved any non-trivial algorithms. It doesn't mean you're a bad programmer but if you can't answer a basic BFS algorithms question I wouldn't trust you to touch code with any non-trivial algorithms in it. |
|
My immediate thought is that if I have to implement a breadth-first search from scratch it probably means that I or someone has made a terrible mistake someplace.
Also, I'd want more information. Am I just getting some values then doing some recursion? How large is the maze? The stack? Are these spherical frictionless chickens or do I need to worry about real-world constraints?
Or for someone else's mention of the Nth from last item in a linked list, my first questions would be "Do I know the length?", "Is this going to need to be repeated?" and possibly "Do I have enough RAM available to create a ring buffer of N addresses?"