Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph) and explores the neighbor nodes first, before moving to the next level neighbors.
n
: Number of nodes in graphm
: Number of edges in graph
start
: Starting node (Source node)
dist
: Array of minimum distances from source node to the others.parent
: Array of parents for the shortest path between source node and target node.