Greedy Best-First Search Calculator

Read the Theory Guide →

Build a weighted graph, assign heuristic values to its nodes, and run Greedy Search to see which path it finds. Change heuristics or edge costs and rerun to compare the search order with the true cost of the resulting path.

What You Can Explore

  • Build a graph on the canvas or edit the preloaded one, assigning a heuristic to each node and a cost to each edge.
  • Choose the Starting Point and Goal Point, and switch between directed and undirected graphs.
  • Change a heuristic or edge cost, then press Run Greedy Search to see how the search and resulting path respond.
  • Read each step's Open List, Closed List, and evaluated neighbors, then compare the heuristic-driven search with the Total True Path Cost.
Core Mechanics
▼
  • Only the Finish Line f(n)=h(n)f(n) = h(n): Greedy Search evaluates nodes purely by their estimated distance to the goal h(n)h(n). It completely ignores the actual cost traveled so far.
  • Always Chase the Lowest: At every step, pop the node from the priority queue with the smallest heuristic. The node that looks closest to the goal is always expanded first.
  • Static Scores (No Updates): If you discover a new route to a node already in your Open List, simply ignore it. A node's heuristic h(n)h(n) never changes, so you never update its score.
  • Fast but Foolable (Not Optimal): Because of its severe tunnel vision, a misleading heuristic can trick Greedy into taking a massive detour. It finds the goal quickly, but rarely finds the absolute shortest path.
Initializing Workspace...

Understanding Your Result

The path and trace come from the graph, heuristic values, and start and goal you entered. The search uses the heuristic to decide which node to explore next, while the Total True Path Cost is calculated separately from the edge costs along the route that was found.

  • Total True Path Cost adds the edge costs along the returned route. Greedy Search does not use these costs when choosing which node to explore, so a low-cost route is not guaranteed.
  • Each step shows f(n)=h(n)f(n) = h(n) for the node being evaluated. Compare its heuristic with the Open List to see why that node was selected next.
  • A dead-end node has no valid unvisited neighbors, so the search returns to the remaining candidates in the Open List and continues with the lowest available heuristic.
  • If the search is exhausted without reaching the goal, no route was found from the selected start using the allowed edge directions. Check the graph connections and start and goal selections.

Try These Experiments

Switch to Undirected

Setup: Run the preloaded graph with S as the start and G as the goal. Note the returned path, its Total True Path Cost, and that A reaches a dead end.

Action: Switch the graph to undirected, keep the same start and goal, and run Greedy Search again.

What to Observe: Compare the two paths and their costs. In the directed run, Greedy explores A first and eventually reaches G through B. In the undirected run, A can continue to C and then G, producing a different route.

Takeaway: Edge direction changes which moves are available to the search. Once the graph becomes undirected, Greedy can follow connections that were previously unavailable, which can change both the route explored and its true cost.

Lower the Heuristic of B

Setup: Use the directed preloaded graph and note that S evaluates A before B because A has the lower heuristic. A then reaches a dead end before the search returns to B.

Action: Change the heuristic of B from 9 to 3, keep the rest of the graph unchanged, and run Greedy Search again.

What to Observe: B is now selected immediately after S because its heuristic is lower than A's. A is no longer evaluated, and the returned path remains S → B → G.

Takeaway: Changing a heuristic can change the search order without changing the final route. In this graph, lowering B's heuristic lets Greedy reach the goal directly instead of first exploring the dead-end branch through A.

Raise the Cost of B to G

Setup: Use the directed preloaded graph with S as the start and G as the goal, and note the returned path and its Total True Path Cost of 2.

Action: Change the cost of the edge from B to G from 1 to 50, then run Greedy Search again.

What to Observe: The search follows the same sequence of nodes and returns the same path, but the Total True Path Cost increases from 2 to 51.

Takeaway: Greedy's node selection is driven by heuristic values rather than accumulated edge cost. Changing an edge weight therefore changes the reported true cost without necessarily changing the search behavior.