- Graph traversal means visiting every vertex and edge exactly once in a well-defined order.
- While using certain graph algorithms, you must ensure that each vertex of the graph is visited exactly once.
- The order in which the vertices are visited are important and may depend upon the algorithm or question that you are solving.
Breadth First Search (BFS):
- BFS is a traversing algorithm where you should start traversing from a selected node (source or starting node) and traverse the graph layer wise thus exploring the neighbor nodes (nodes which are directly connected to source node). You must then move towards the next-level neighbor nodes.
- As the name BFS suggests, you are required to traverse the graph breadth wise as follows:
- First move horizontally and visit all the nodes of the current layer
- Move to the next layer
printf(“Breadth First Search Results”);