Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5510565

Browse files
authored
Update breadth-first-search.md
1 parent bdb1b78 commit 5510565

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/graph/breadth-first-search.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ Thus, we perform normal BFS from each of the vertices, but do not reset the arra
8484
* Finding the shortest path in a graph with weights 0 or 1:
8585
This requires just a little modification to normal breadth-first search: if the current edge of zero weight, and distance to the vertex is shorter than the current found distance, then add this vertex not to the back, but to the front of the queue.
8686

87-
* Finding the shortest cycle in a directed unweighted graph: start a breadth-first search from each vertex; as soon as we try to go from the current vertex to an already visited vertex, then it means that we have found the shortest cycle containing the source vertex, and should stop the BFS; from all such cycles (one from each BFS) choose the shortest.
87+
* Finding the shortest cycle in a directed unweighted graph:
88+
Start a breadth-first search from each vertex.
89+
As soon as we try to go from the current vertex back to the source vertex, we have found the shortest cycle containing the source vertex.
90+
At this point we can stop the BFS, and start a new BFS from the next vertex.
91+
From all such cycles (at most one from each BFS) choose the shortest.
8892

8993
* Find all the edges that lie on any shortest path between a given pair of vertices $(a, b)$.
9094
To do this, run two breadth first searches:

0 commit comments

Comments
 (0)