Santa needs to figure out all the houses he can visit on his route in his neighborhood. The neighborhood is represented as an undirected graph, where each node is a house and each edge represents a path between two houses.
Your task is to implement a function that performs a Breadth-First Search (BFS) traversal starting from a given house (node) and returns a list of houses in the order they are first visited.
Return an array (or list) of nodes in the order they are visited during the BFS traversal.
Given the graph:
{
A: [B, C],
B: [A, D, E],
C: [A, F],
D: [B],
E: [B, F],
F: [C, E]
}
and starting node A
, a valid output would be:
[A, B, C, D, E, F]
(Note: depending on the order in the adjacency list, some valid traversals may vary.)
On this day, as we approach the festive season, imagine Santa planning his route to ensure no house is missed!
Good luck!