Breadth First Search Calculator

Explore layered graph searches with flexible controls. Track visit order, depths, and parent links precisely. Build cleaner paths, validate graphs, and understand traversal behavior.

Graph Inputs

Enter node labels and edges. Use commas or new lines for nodes, and one edge per line such as A-B or A->B.

Unique labels work best for clear traversal results.
Use one edge per line. Directed graphs accept A->B.
Reset

Example Data Table

This sample shows a small graph and the expected BFS layering from start node A.

Node Connected To Level from A Parent Visit Order
AB, C0Root1
BA, D, E1A2
CA, F1A3
DB2B4
EB, G2B5
FC, H2C6
GE3E7
HF3F8

Formula Used

Breadth first search expands the graph level by level using a first-in, first-out queue. The calculator uses these core relationships for every reachable node.

  • Level of start node: level(start) = 0
  • Level update: level(child) = level(parent) + 1
  • Shortest unweighted distance: distance(start, node) = level(node)
  • BFS tree path: path(node) is reconstructed by following parent links back to the start node
  • Time complexity: O(V + E)
  • Space complexity: O(V)

Because the queue processes older discoveries first, every node is visited in the smallest possible number of unweighted edges from the chosen start node.

How to Use This Calculator

  1. Enter all graph nodes using commas or separate lines.
  2. Type one edge per line using A-B or A->B format.
  3. Choose whether the graph is directed or undirected.
  4. Provide the start node and optionally add a target node.
  5. Select the neighbor ordering rule for deterministic traversal output.
  6. Set a maximum depth when you want a partial layered search.
  7. Press the submit button to generate traversal summaries and logs.
  8. Use the export buttons to save your results as CSV or PDF.

Frequently Asked Questions

1. What does this calculator solve?

It runs breadth first search on a custom graph, then reports visit order, levels, parent links, shortest unweighted path, reachable nodes, and queue activity.

2. Why is breadth first search useful?

Breadth first search is ideal for layer-based exploration. It finds the minimum edge count path in unweighted graphs and helps inspect connectivity clearly.

3. Does it support directed graphs?

Yes. Choose the directed option when edge direction matters. In that mode, A->B does not automatically create B->A.

4. How is the shortest path computed?

When a target is provided and reachable, the calculator traces parent links from the target back to the start node, then reverses that chain.

5. What does max depth do?

Max depth limits expansion beyond a chosen layer. Nodes deeper than that boundary remain unvisited, which is useful for controlled local searches.

6. Why can visit order change?

Traversal order depends on the arrangement of each node’s neighbors. Sorting ascending, descending, or preserving input order can produce different valid BFS sequences.

7. Can isolated nodes be included?

Yes. Any listed node without connecting edges still appears in the node table and will be marked unreachable unless it is the selected start node.

8. What do CSV and PDF exports contain?

The exports include the main summary, per-node metrics, and queue progression. That makes the output convenient for teaching notes, debugging, and documentation.

Related Calculators

adjacency matrix generatortopological sort calculatorminimum spanning tree calculatorgraph distance calculatorford fulkerson calculatorvertex degree calculatorconnected components counterfloyd warshall calculatoreulerian path calculatorsteiner tree calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.