santoshvijapure / DS_with_hacktoberfest

Celebrate Hacktoberfest by getting involved in the open source community by completing some simple tasks in this project.
Apache License 2.0
10 stars 95 forks source link

Breadth First Search or BFS for a Graph #237

Closed mehrajcode closed 3 years ago

mehrajcode commented 3 years ago

we start traversal from vertex 2. When we come to vertex 0, we look for all adjacent vertices of it. 2 is also an adjacent vertex of 0. If we don’t mark visited vertices, then 2 will be processed again and it will become a non-terminating process. A Breadth First Traversal of the following graph is 2, 0, 3, 1.

The implementation uses adjacency list representation of graphs. STL‘s list container is used to store lists of adjacent nodes and queue of nodes needed for BFS traversal.

Checklist

Pick at least one of the three options