Graph Traversal :-"BFS"
πBFS (Breadth-First Search) – Introduction Breadth-First Search (BFS) is a fundamental graph traversal algorithm used to visit all vertices of a graph in a breadth-wise (level-by-level) manner. Starting from a given source vertex, BFS explores all its adjacent vertices first before moving on to vertices at the next level. BFS uses a queue data structure to keep track of vertices to be visited and a visited array to avoid revisiting the same vertex. It is especially useful for finding the shortest path in an unweighted graph and for level-order traversal. Key Characteristics of BFS: Traversal Type: Level-by-level (or layer-by-layer). Data Structure Used: Queue (First In, First Out — FIFO). Time Complexity: O(V + E), where V is the number of vertices and E is the number of edges. Space Complexity: O(V), as it stores vertices in the queue. Applicable To: Both graphs and trees. How BFS Works BFS uses a queue to store nodes to be explo...