I have a problem where I need to search for all unique paths in an undirected graph of degree <=4. The graph is basically a grid, and all connections are between direct neighbors only (4-way).
- A path cannot visit the same vertex
more than once. - A path can visit any
number of vertices to make a path. - A path contains at least 2 vertices.
How do I go about this problem?

Here’s the pseudocode I just came up with:
This would be this code in Java (untested):
This should find the paths from one starting node. You can start it on each node but you’d get some duplicates. To weed them out you’d also need to return the paths though.