# Finding disjoint paths between any number of cell pair marked in nXn matrix

What should be algorithm to find all the disjoint paths between any number of pairs of cells given in matrix?

We will say two paths will not intersect if there there is no cell common between any two paths.

My approach is : I will pick first cell pair and create a path between them. Now it will work as obstacle for path between other cell pairs. But problem is how to first pick which cell pair? Because it will create problem in finding path between some cell pair in future.

• Your reasoning is correct. The choice of a path rules out the existence of other ones (and there is even a path which rules out the existence of any other path). I suppose what you really want to do is maximize the number of disjoint paths. If that is the case, please mention it in the answer. – dkaeae Jan 13 '19 at 9:22
• @dkaeae I have a fixed number of cells given but pair is not fixed. It is upto us which cell we pick to make path between other given cell. – ironman Jan 13 '19 at 9:37
• I am afraid I cannot make sense of this. What is given? What can you choose? What are you supposed to do? The question would (greatly) benefit from a formal description of the problem. – dkaeae Jan 13 '19 at 10:10
• @dkaeae You're given a (full) grid graph and disjoint sets $S$ and $T$ of vertices with $|S|=|T|$ and you have to find a set of $|S|$ vertex-disjoint $S$-$T$ paths. (Or, possibly, you're told which $S$ vertex should be linked to which $T$ vertex; it shouldn't make much difference.) – David Richerby Jan 13 '19 at 10:20
• @DavidRicherby Aha, so this is simply Menger's theorem restricted to matrices? – dkaeae Jan 13 '19 at 10:32