So, I have the following problem:
Given a grid of x by y measurements, calculate the number of routes through it that start in one corner (let them say at the top left) and end with another (bottom right) and go through each vertex.
Thus, my current method just rudely makes it just try all possible paths and count those that reach the finish line and cross each node. While it works, it is O (n ^ 2) and it incredibly slowly slows down very quickly. Iโm not sure how to do this combinatorially due to the fact that the path goes through each vertex.
I was looking for more complex algorithms, and the Herholzer algorithm for calculating the Eulerian paths seems somewhat connected, but not perfect, because it is impossible to traverse the nodes more than once.
Be that as it may, my program works, but it is bad, and I would like to make it more efficient. Are there any better algorithms I could use?
Edit Thanks for the answers. To clarify, all nodes in a 2d grid are connected n / e / s / w
In addition, the grid should not be square
java c ++ algorithm
Charmquark
source share