retrieve the path with the lowest weight from matrix recursively
<p>let's say I have a <strong>n^n</strong> matrix. In every cell there is a positive number, and I need to <strong>retrieve the path with the lowest weight</strong>.</p>

<p><strong>path</strong> is every path that start in <code>matrix[0][0]</code> and end in <code>matrix[matrix.length-1][matrix[0].length-1]</code>, <strong>without</strong> diagonals.</p>

<p><strong>weight</strong> of a path is the amount of all the numbers in it's cells.</p>

<p>For example, let's say I have this matrix: </p>

<pre><code>mat = {{1,2},{3,4}};
</code></pre>

<p>so <code>{1,2,4}</code> is a <strong>path</strong>, and <code>{1,3,4}</code> is another <strong>path</strong>.</p>

<p>The weight of the first path is <strong>7</strong> (1+2+4) and the second one has a weight of <strong>8</strong> (1+3+4), so the function will return <strong>7</strong>.</p>

<p>I need to solve it recursively. The pseudo code should be something like this:</p>

<pre><code>if i &gt; matrix.length-1 || i &lt; 0 || j &gt; matrix[0].length-1 || j &lt; 0
//then I passed the borders, so I need to step back.
if i == matrix.length-1 &amp;&amp; j == matrix[0].length-1
//Then I reached the last cell, and I need to retrieve sum
</code></pre>

<p>Then call four recursives calls:</p>

<pre><code>public static int smallPath(a, i+1, j, sum);
public static int smallPath(a, i, j+1, sum);
public static int smallPath(a, i-1, j, sum);
public static int smallPath(a, i, j-1, sum);
</code></pre>

<p>Then I need to retrieve something, what?</p>

<p>I know it's not current but that's the general idea, can someone help me solve this? Thanks!</p>