Using the backtracking method to solve the maze problem