I have a grid of NxN cells (think of a 2 dimensional array defined as follows Array[N][N]).
Which algorithm will compute every path from every cell a[i][j] to every cell a[k][l] where:
- No cell is included twice within a single path.
- Only adjacent diagonal, horizontal and vertical moves all legal.
- The algorithm is the fastest, on average.
- The least amount of memory is used.
I assume you want the actual paths, and not just the number of them.
You can achieve it by using DFS that maintains
visitedset on the vertices explored in the same path, and avoids exploring a vertex that was already discovered in the same path.Pseudo code:
invoke
with DFS(source,target,{})[where{}is an emptyvisitedset].