A* Search vs. Uniform Cost Search

Last Updated July 20, 2026

A* and Uniform Cost Search both use accumulated path cost, but they rank the frontier differently. A* uses f(n)=g(n)+h(n)f(n)=g(n)+h(n), while Uniform Cost Search uses only g(n)g(n) and has no heuristic guidance toward the goal.

  • Use A* Search when a reliable heuristic can direct the search toward the goal while preserving the cheapest-path guarantee under the required conditions.
  • Use Uniform Cost Search when no reliable heuristic exists and node priority must depend only on accumulated path cost.
A* adds heuristic direction to UCS; setting h(n)=0h(n)=0 makes A* behave like UCS.

Head-to-Head Showdown

Frontier Priority

A* Search: Lowest g(n)+h(n)g(n)+h(n)

Uniform Cost Search: Lowest g(n)g(n)

The Implication: A* ranks nodes using both the cost already paid and the estimated cost remaining. Uniform Cost Search ignores goal direction and expands whichever frontier node currently has the smallest accumulated path cost.

Heuristic Effect

A* Search: Guides node expansion

Uniform Cost Search: No heuristic used

The Implication: An informative heuristic can move goal-relevant nodes ahead of cheap but unhelpful alternatives in A*. Uniform Cost Search cannot make that distinction because accumulated path cost alone controls its expansion order.

Zero-Heuristic Relationship

A* Search: Becomes UCS

Uniform Cost Search: Native g(n)g(n) priority

The Implication: When h(n)=0h(n)=0 for every node, A* reduces from g(n)+h(n)g(n)+h(n) to g(n)g(n). With the same tie-breaking, duplicate handling, and goal test, both algorithms then follow the same search behavior.

Selection Criteria

Scenario:Routing a warehouse robot across a large four-directional grid where Manhattan distance safely estimates the remaining movement cost.

Choose A* Search:Manhattan distance gives A* useful goal direction through f(n)=g(n)+h(n)f(n)=g(n)+h(n), allowing promising cells to outrank cheap cells leading away from the destination. Uniform Cost Search uses only g(n)g(n) and may expand more low-cost cells before reaching the goal.

Scenario:Finding the cheapest route through a weighted network with no coordinates or reliable estimate of the remaining cost.

Choose Uniform Cost Search:Without a meaningful heuristic, A* loses its directional advantage and effectively becomes Uniform Cost Search when h(n)=0h(n)=0. Uniform Cost Search uses only known path costs and returns the cheapest path under the required edge-cost and graph-search conditions.

Scenario:Checking whether a custom A* implementation returns the correct cheapest-path cost before deployment.

Choose Uniform Cost Search:Uniform Cost Search provides a heuristic-free reference result by ranking nodes only through accumulated path cost. Comparing its final cost and predecessor chain with A* can expose mistakes in heuristic handling, score updates, node reopening, or goal termination.

Side By Side Trace

A directed graph runs from SS to GG through AA and CC, with a cheap but unpromising side route through BB. Edge labels show travel cost, and each node's floating value is h(n)h(n), the estimated remaining cost to GG. A* orders its Open List by f(n)=g(n)+h(n)f(n)=g(n)+h(n), while Uniform-Cost Search selects the smallest tentative distance from its priority queue.

3
1
2
10
2
6
S
3
A
8
B
2
C
0
G

Step 1: Evaluating the Start Node

A* Search

Evaluates SS with g(S)=0g(S)=0, h(S)=6h(S)=6, and f(S)=6f(S)=6. The edges from SS generate AA with f(A)=3+3=6f(A)=3+3=6 and BB with f(B)=1+8=9f(B)=1+8=9. The Open List becomes [A(6),B(9)][A(6), B(9)], and SS moves to the Closed List.

Uniform Cost Search

Sets the tentative distance of SS to 00 and all other nodes to infinity. Relaxing SAS \rightarrow A records 0+3=30+3=3, while relaxing SBS \rightarrow B records 0+1=10+1=1. The priority queue therefore places B(1)B(1) before A(3)A(3), and SS becomes closed.

Step 2: Point of Divergence

A* Search

A* selects AA because f(A)=6f(A)=6 is lower than f(B)=9f(B)=9. Evaluating ACA \rightarrow C gives g(C)=3+2=5g(C)=3+2=5, h(C)=2h(C)=2, and f(C)=7f(C)=7. The Open List becomes [C(7),B(9)][C(7), B(9)], while AA moves to the Closed List.

Uniform Cost Search

Uniform-Cost Search selects BB because its tentative distance 11 is lower than AA's distance 33. Relaxing BGB \rightarrow G records 1+10=111+10=11 as the first known distance to GG. The priority queue becomes [A(3),G(11)][A(3), G(11)], and BB becomes closed.

Step 3: Updating the Next Candidates

A* Search

A* selects CC because f(C)=7f(C)=7 is lower than f(B)=9f(B)=9. Evaluating CGC \rightarrow G gives g(G)=5+2=7g(G)=5+2=7, h(G)=0h(G)=0, and f(G)=7f(G)=7. The Open List becomes [G(7),B(9)][G(7), B(9)], while CC enters the Closed List.

Uniform Cost Search

Uniform-Cost Search selects AA because its tentative distance 33 is lower than GG's distance 1111. Relaxing ACA \rightarrow C records 3+2=53+2=5 as the first known distance to CC. The priority queue becomes [C(5),G(11)][C(5), G(11)], and AA becomes closed.

Step 4: A* Finishes While UCS Relaxes the Goal

A* Search

A* selects GG because f(G)=7f(G)=7 is lower than f(B)=9f(B)=9. The goal is accepted when GG is removed from the Open List, so the search returns SACGS \rightarrow A \rightarrow C \rightarrow G. Node BB remains in the Open List and is never evaluated.

Uniform Cost Search

Uniform-Cost Search selects CC because its tentative distance 55 is lower than GG's current distance 1111. Relaxing CGC \rightarrow G produces 5+2=75+2=7, which improves the recorded distance from 1111 to 77. The matrix updates GG's predecessor from BB to CC, and the priority queue becomes [G(7)][G(7)].

Step 5: Uniform-Cost Search Finishes

A* Search

Performs no further work. The search already ended after GG was selected from the Open List with total path cost 77.

Uniform Cost Search

Uniform-Cost Search selects GG with tentative distance 77, the smallest value remaining in the priority queue. Once GG becomes closed, its distance is final and the predecessor chain returns SACGS \rightarrow A \rightarrow C \rightarrow G.

Final Result

A* Search:A* Search returns SACGS \rightarrow A \rightarrow C \rightarrow G with total cost 77 after evaluating 44 nodes: SS, AA, CC, and GG. Its Open List ordering kept B(9)B(9) behind C(7)C(7) and G(7)G(7), so BB never entered the Closed List.

Uniform Cost Search:Uniform-Cost Search returns the same path with total cost 77 after closing 55 nodes: SS, BB, AA, CC, and GG. Its matrix first recorded G=11G=11 through BB, then relaxed that value to 77 through CC before selecting the goal.

Common Pitfalls & Exam Mistakes

  • Ordering A*'s frontier using only g(n)g(n).

    The Mistake: Students ignore the provided heuristic and rank A* nodes only by accumulated path cost, making the trace behave like Uniform Cost Search.

    Why It's Wrong: A* ranks frontier nodes by f(n)=g(n)+h(n)f(n)=g(n)+h(n), while Uniform Cost Search uses only g(n)g(n). Removing h(n)h(n) eliminates A*'s goal guidance and can change the node-expansion order.

  • Adding h(n)h(n) to Uniform Cost Search.

    The Mistake: Students include heuristic values in UCS priorities because the shared graph displays h(n)h(n) beside every node.

    Why It's Wrong: Uniform Cost Search updates and ranks nodes using accumulated path cost alone. Adding h(n)h(n) changes its priority from g(n)g(n) to g(n)+h(n)g(n)+h(n), turning the trace into A* rather than UCS.

  • Assuming A* always expands fewer nodes than Uniform Cost Search.

    The Mistake: Students treat A*'s heuristic as a guaranteed reduction in runtime and expanded-node count on every graph.

    Why It's Wrong: An informative heuristic can reduce irrelevant expansions, but h(n)=0h(n)=0 makes A* behave like Uniform Cost Search. Weak heuristics may provide little advantage, while inconsistent heuristics, reopening rules, and implementation overhead can create additional work.

Comparative Analysis

AttributeA* SearchUniform Cost Search
Evaluation Functiong(n)+h(n)g(n)+h(n)g(n)g(n)
Heuristic UsedYesNo
Expansion OrderLowest estimated totalLowest accumulated cost
OptimalityConditional guaranteeCost-condition guarantee
Zero-Heuristic CaseBecomes UCSNative cost-only search
Typical AdvantageFewer irrelevant expansionsNo heuristic required

Common Questions & Edge Cases

  • Can Uniform Cost Search replace A* Search when no reliable heuristic exists?

    Yes. Without a trustworthy h(n)h(n), A* has no dependable directional advantage and can set h(n)=0h(n)=0. Uniform Cost Search then returns the cheapest path using only g(n)g(n) under the required edge-cost and graph-search conditions.

  • Does h(n)=0h(n)=0 make A* Search identical to Uniform Cost Search?

    Yes. Setting h(n)=0h(n)=0 reduces A*'s priority from g(n)+h(n)g(n)+h(n) to g(n)g(n), matching Uniform Cost Search. With identical tie-breaking, duplicate handling, and goal testing, both follow the same expansion order and return the same result.

  • Can A* Search expand more nodes than Uniform Cost Search?

    Yes. An inconsistent heuristic can cause node reopenings, while different tie-breaking and duplicate-handling policies can also change the amount of work. A weak heuristic may offer little advantage, so A* does not universally run faster or expand fewer nodes than Uniform Cost Search.

  • Can A* Search and Uniform Cost Search return the same path but expand nodes differently?

    Yes. Both can return the same cheapest path under their required correctness conditions while using different frontier priorities. A* includes h(n)h(n) in its ordering, so it can avoid nodes that Uniform Cost Search expands through g(n)g(n) alone.

Explore the Algorithms in Action

Open the theory pages or try the interactive solvers for the algorithms compared above.