DFS can be implemented with recursion. It starts from the source cell and explores the adjacent cells in 4 directions (up, down, left, right). The adjacent cells are accessed by increasing or decreasing the indices of the row or the column by 1 at a time. If the cell’s value is pass, it continues further. If a cell’s all un-visited adjacent cells are blocked or beyond the edge, this is a dead end. Then the recursive method returns by the order of call stacks and explores other routes.