Search Algorithm Comparison: Complete, Optimal, Time and Space Complexity

Build one graph and compare all ten search algorithms on it: whether each is complete and optimal, its time and space complexity, and — on your graph — whether it found a path, the path cost and how many nodes it expanded.

About this visualization

Build one graph and run all ten AI search algorithms on it. The table shows the textbook properties — complete, optimal, time and space complexity — next to what actually happened on your graph: the path cost and how many nodes each algorithm expanded.

How it works

  1. Every algorithm runs on exactly the same graph, start, goal and heuristic.
  2. The table shows textbook properties and your graph's actual results.
  3. Change the edge costs or heuristic and see which algorithms stay optimal.

Worked example

On the Romania map from Arad to Bucharest, UCS and A* find the cheapest path (418), while BFS, DFS, greedy, IDDFS, bidirectional search and beam search return a path of cost 450. A* expands fewer nodes than UCS because its heuristic steers it toward the goal.

Enter these numbers in the simulator above to see every step.

Complexity and properties

Complete: finds a solution whenever one exists. Optimal: the solution it finds is the cheapest.

When to use it

  • Choosing a search strategy for a given problem.
  • Revising for AI exams with complexity and optimality tables.
  • Experimenting: break the heuristic and see which algorithms stop being optimal.

Frequently asked questions

Which search algorithms are complete and optimal?

Uniform-cost search and A* (with an admissible heuristic) are both. BFS and IDDFS are optimal when all step costs are equal.

What is the difference between informed and uninformed search?

Uninformed searches (BFS, DFS, UCS, IDDFS, bidirectional) use only the problem definition. Informed searches (greedy, A*, hill climbing, beam) also use a heuristic estimate of the distance to the goal.

Which search algorithm is best?

There is no single best: A* with a good heuristic is the usual choice when optimality matters; DFS and IDDFS when memory is tight; greedy or beam search when speed matters more than optimality.