Weighted A* Search (WA*)
A* with inflated heuristics — faster but suboptimal, with bounded error
The Simplest Explanation
A* is optimal but slow. What if you're willing to accept a solution that's a little bit worse than optimal, as long as you get it much faster?
WA* says: inflate the heuristic by a weight . This makes the algorithm greedier — it rushes toward the goal more aggressively, exploring fewer nodes. The tradeoff: the solution may not be optimal, but its cost is bounded by .
- : standard A* (optimal, slow)
- : WA* (faster, suboptimal but bounded)
- : Greedy Best-First Search (fastest, no guarantee)
If the heuristic is admissible, then WA* with weight finds a solution with cost , where is the optimal cost. For example, with , the solution cost is at most twice the optimal. You always know the worst-case error.
Why WA* Works (Intuition)
Think of as a dial that controls how much you trust the heuristic vs. the actual cost:
- Low (close to 1): you trust more, explore carefully, find near-optimal solutions
- High : you trust more, rush toward the goal, find solutions fast but they may be costly
- The error bound grows linearly with , so you always know the worst case
The Algorithm
WA* is identical to A* except for the evaluation function:
- Put the start node in the open list with ,
- While the open list is not empty:
- Pick the node with the lowest from the open list
- If it's the goal → done!
- Move it to the closed list
- For each neighbor:
- Calculate
- Calculate
- Standard open/closed list checks (same as A*)
- If open list is empty → no path exists
Only one thing changes: becomes . The entire algorithm is the same. The weight simply makes the heuristic "count more" when deciding which node to expand next.
Bounded Suboptimality
The key theorem for WA*:
where is the optimal (cheapest possible) path cost.
Why the Bound Holds (Sketch)
With , WA* may expand nodes in a different order than A*. But it will never expand a node with before finding a solution, because the goal node has , and the first goal found satisfies .
The Weight-Error Tradeoff
| Weight | Max Error | Speed | Use Case |
|---|---|---|---|
| 1.0 | 0% (optimal) | Slowest | When optimality is required |
| 1.5 | ≤ 50% over optimal | Faster | Near-optimal solutions |
| 2.0 | ≤ 100% over optimal | Fast | When speed matters more |
| 3.0 | ≤ 200% over optimal | Very fast | Real-time systems |
| No bound | Fastest | When any solution will do |
Properties Summary
| Property | Value | Condition |
|---|---|---|
| Complete? | Yes | Finite branching factor |
| Optimal? | No (bounded) | Cost if admissible |
| Time complexity | Better than A* | Fewer nodes expanded |
| Space complexity | Same as A* | Still keeps all nodes in memory |
WA* with typically expands far fewer nodes than A*. In practice, the reduction can be exponential — especially when the heuristic is good. The price is a solution that's at most twice the optimal cost, which is often acceptable in real-time applications like video game pathfinding or robotics.
Anytime A*
A powerful pattern: run WA* with decreasing weights.
- Start with → get a quick but rough solution (cost ≤ 5 × C*)
- Lower to → get a better solution (cost ≤ 2 × C*)
- Lower to → get the optimal solution (cost = C*)
Each iteration reuses the search from the previous one. You can stop at any time and still have a valid solution with a known error bound. This is called Anytime A* — it gives you the best solution found so far, with improving quality over time.
Worked Example: WA* with w=2
Here's the same 8-node graph. Start at S, goal is G. We use weight .
| Node | |
|---|---|
| S | 6 |
| A | 4 |
| B | 2 |
| C | 2 |
| D | 3 |
| E | 1 |
| F | 1 |
| G | 0 |
Compare WA* (w=2) with A* (w=1) — notice how WA* rushes toward B because its low h=2 gets inflated to 4:
Initialize: Open = {S}. f(S) = g(S) + w×h(S) = 0 + 2×6 = 12. Weight w = 2 inflates the heuristic.
WA* vs A* on This Graph
| A* (w=1) | WA* (w=2) | |
|---|---|---|
| Path found | S→A→D→F→G | S→B→E→G |
| Cost | 5 (optimal) | 6 (suboptimal) |
| Nodes expanded | 4 | 3 |
| Within bound? | — | 6 ≤ 2×5 = 10 ✓ |
WA* found a solution 25% worse than optimal, but expanded 25% fewer nodes. In larger graphs, the node savings are far more dramatic.
Exam Practice: WA* vs A* Comparison
This question tests whether you can trace WA* and identify when it finds a different (suboptimal) path compared to A*. The graph is designed so that WA* with w=2 takes a completely different route.
Given: Find the shortest path from P to Z using WA* with w=2. Heuristic values:
| Node | |
|---|---|
| P | 7 |
| Q | 5 |
| R | 6 |
| T | 3 |
| S | 2 |
| U | 1 |
| Z | 0 |
Trace WA* with w=2 on paper, then click "Show Solution" to verify. Compare with A* — does WA* find the same path?
Key Observation
A* (w=1) would expand P → R → S → U → Z (cost 6). WA* (w=2) expands P → Q → T → Z (cost 8). The entire path is different because the inflated heuristic makes Q (h=5, inflated to 10) look better than R (h=6, inflated to 12), even though R is on the optimal path.
Error bound verification: 8 ≤ 2 × 6 = 12 ✓