Santa Route Planner

Graph Traversal Bfs Holiday

Problem: Santa Route Planner

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.

Input

  • A graph represented as an adjacency list. In most languages, this is an associative data structure (like a dictionary or hash map) where each key is a node and its value is a list/array of adjacent nodes.
  • A starting node from which the traversal begins.

Output

Return an array (or list) of nodes in the order they are visited during the BFS traversal.

Example

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!