AI engineering glossary · Data structures algorithms

What is BFS (breadth-first search)?

Breadth-first search (also called BFS): A graph traversal that visits all vertices at distance 1 from the start, then distance 2, and so on, using a queue. On graphs with equal edge costs it finds the path with the fewest edges.

Level: beginnerTopic: Data structures algorithms

Breadth-first search: an example

Finding the fewest hops between two people in a social network: expand friends, then friends of friends, until the target is reached.

Related terms

More Data structures algorithms terms

Where you learn it

Breadth-first search is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.