I wanted to know the Java code to find all the possible paths of a multidimensional array. We should start from the [0][0] node and move forward. The thing to keep in mind that the paths must be in an increasing order irrespective of the elements order.
We should not traverse if the next element is equal to (or less then) the current one.
Example Array:
3 5 1
6 7 4
8 2 9
Result:
3,5,6,7,8
3,5,6,7,9
3,5,7,8
3,5,7,9
3,6,7,8
3,6,7,9
3,7,8
3,7,9
I think the following code does what you describe. It start checking with the first node (0,0). For every node that is checked, a vector of neighbors is created. The neighbors are the nodes that are eligible to be a continuation to the path (i.e. neighboring nodes with higher value in the table). Then for each neighbor, the path is cloned, and the new neighbor is checked. This continues until the checked node has no eligible neighbors, at which point the path is printed and the algorithm terminates.
Try this:
Output:
It also gives me the path 3,6,8, which is not in your sample output