Breadth First JavaScript Search Algorithm for Graphs

Kyle Shevlin
InstructorKyle Shevlin

Share this video with your friends

Send Tweet

Breadth first search is a graph search algorithm that starts at one node and visits neighboring nodes as widely as possible before going further down any other path. This algorithm requires the use of a queue to keep track of which nodes to visit, so it might be worth your time to brush up on that data structure before watching this lesson.

Christopher Ueda
Christopher Ueda
~ 2 years ago

If you're not using the code in the code sandbox and don't want to import the queue data structure from the previous lesson you can also just use an array to store the nodes. Also, the transcript has some discrepancies with the usage of visited and visitedHash for the name of the aforementioned queue.

Rob
Rob
~ 2 years ago

In the transcript, in the second example, an object named visited is created. In later examples, it is referenced as visitedHash. This is corrected in the full source code above.

Lucas Minter
Lucas Minter
~ 7 months ago

Thanks for this Rob and Christopher! I got the transcripts updated.