Skip to main content

Rat in a Maze

Learn Rat in a Maze (Recursion & Backtracking, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Finding a Path Through a Grid A rat starts at the top-left of a grid maze and must reach the bottom-right, moving only through open cells (marked 1, blocked cells marked 0). Backtracking tries each direction from the current cell, marking it visited, recursing, and UN-marking it if that direction leads to a dead end - the un-marking is essential so other paths can still use that cell.

More lessons in Recursion & Backtracking