I have just finished a project where I implemented the recursive backtracking algorithm for a maze generator. Since then I have been looking for an algorithm that goes through a matrix but passing through each square only once. Just like in the recursive backtracking algorithm but without "going back". Is there any algorithm for this? This is an example of what I mean with a 5*5 matrix:
5 4 1 20 21
6 3 2 19 22
7 8 17 18 23
10 9 16 15 24
11 12 13 14 25
As you can see you can start from square 1 and end on 25 without repeating any other square. Thanks for your time.