Shortest-path

18 articles

dsa9 min read

A* Search — Heuristic Shortest Path for Grids and Maps [LC 1091, Google, Tesla]

Master A* search: a heuristic-guided best-first search that finds optimal shortest paths far faster than Dijkstra by combining actual distance g(n) with an admissible estimate h(n). The interview pattern behind LeetCode 1091 Shortest Path in Binary Matrix and the algorithm powering Google Maps, game AI, and robotics navigation.

Read →
dsa9 min read

Snakes and Ladders — BFS on Board State

Minimum dice rolls to reach square n² from square 1. The hard part is converting square numbers to board coordinates in Boustrophedon (snake) order. BFS on the state space of squares gives the optimal answer.

Read →
dsa8 min read

Open the Lock — BFS on State Space

Find the minimum number of turns to go from "0000" to the target combination on a 4-wheel lock, avoiding deadend states. Classic BFS on a finite state space — the lock combination is the node, each wheel turn is an edge.

Read →
dsa9 min read

Cheapest Flights Within K Stops — Bellman-Ford with a Twist

LC 787 Cheapest Flights Within K Stops asks for the cheapest route from src to dst using at most k intermediate stops. Bellman-Ford with exactly k+1 relaxation rounds handles the stop constraint cleanly without Dijkstra getting confused by the layered state.

Read →