To solve the maze for lab 9, you need to make sure you don't get stuck in a loop by trying the same path repeatedly. You need to be able to *backtrack* to a previous "choice point" so that you can explore a different path if the path you've followed led to a dead end. You can do this with a stack, recording on the stack the positions you've visited and whether or not they are choice points. However, an easier way to accomplish this is to store values in the matrix itself. When the matrix was first "dug out", it only had values 0 (wall) or 1 (path). However, we can store different values to indicate *how many times we've been in a certain position*. That is, we can increment M[y][x] each time we visit position y,x. The algorithm is then just to pick the direction whose matrix value is the *smallest non-zero number*. Ties can be broken arbitrarily. This scheme is valid because, when you return to a branch point, the branch that you have not yet explored (or have explored fewer times) will have a smaller value. The basic algorithm used here is called "depth-first search". That is, we continue in one direction until we get stuck, then back up to the previous choice point and go in another direction.