- **Lee Algorithm** is a breadth-first search (BFS) based algorithm used to find the shortest path in a grid-based problem, particularly in a **2D grid** (or maze), where movement is allowed only in 4 or 8 directions.
-
Steps:
Start at the source node and enqueue it in the queue.
Mark the current node as visited and begin processing the neighbors (up, down, left, right, or diagonal).
For each unvisited neighbor, enqueue it and mark its distance from the source node.
Repeat until the target node is reached or all reachable nodes are visited.
Time Complexity:
O(V + E), where V is the number of vertices and E is the number of edges.