5

Configure inputs and press Visualize to begin.

Pseudocode & Implementations
1 approach

Level-order traversal using a queue. Guarantees shortest path in unweighted graphs.

BFS(graph, start):
  visited = {start}
  queue = [start]
  order = []

  WHILE queue not empty:
    node = DEQUEUE(queue)
    order.append(node)

    FOR each neighbor OF node:
      IF neighbor NOT in visited:
        visited.add(neighbor)
        ENQUEUE(queue, neighbor)

  RETURN order
Complexity Analysis

Time Complexity

Best Case
PolynomialO(V+E)
Average
PolynomialO(V+E)
Worst Case
PolynomialO(V+E)
Space (aux)
PolynomialO(V)
traversalshortest-pathqueue
About

Explores all neighbors at current depth before moving deeper. Uses a queue to process nodes level by level.

Key Insight

Guarantees shortest path in unweighted graphs. Explores in concentric rings from source.

Use Cases

Shortest path (unweighted)Level-order traversalSocial network analysisWeb crawling