• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 28, 2023 |410 Views
SDE Sheet - Breadth First Traversal
  Share  1 Like
Description
Discussion

This video is part of Graphs section under GFG SDE Sheet.

In this video, we are given, a directed graph. The task is to do the Breadth First Traversal of this graph starting from 0.
Note: One can move from node u to node v only if there's an edge from u to v. Find the BFS traversal of the graph starting from the 0th vertex, from left to right according to the input graph. Also, you should only take nodes directly or indirectly connected from Node 0 in consideration.


Example :

Input:
V = 5, E = 4
edges = {(0,1),(0,2),(0,3),(2,4)}


Output: 
0 1 2 3 4
Explanation: 
0 is connected to 1 , 2 , 3.
2 is connected to 4.
so starting from 0, it will go to 1 then 2
then 3. After this 2 to 4, thus bfs will be
0 1 2 3 4.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-

Article: https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/
Problem: https://practice.geeksforgeeks.org/problems/bfs-traversal-of-graph/1

Read More