BFS Traversal Problem
BFS Traversal Problem — ExecCode Easy DSA Practice
Solve the BFS Traversal problem on ExecCode. Free online easy DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an undirected graph as an adjacency list and a start node, return the BFS visit order. Mark a node visited when it is enqueued so each node appears exactly once.
Examples
Input n = 7, adj = [[1, 2], [0, 3, 4], [0, 4, 5], [1, 6], [1, 2, 6], [2, 6], [3, 4, 5]], start = 0; Output [0, 1, 2, 3, 4, 5, 6]. Input n = 3, adj = [[1], [0, 2], [1]], start = 1; Output [1, 0, 2]
Constraints
1 ≤ n ≤ 10⁴ 0 ≤ start < n 0 ≤ |edges| ≤ min(n·(n-1)/2, 2·10⁴) Graph may be disconnected; only the component of start is traversed
Practice BFS Traversal free on ExecCode. Browse DSA problems, topic map, and placement guides.