# Thread: Help needed trying to understand recursion.

1. Member
Join Date
Dec 2010
Posts
60
Rep Power
0

## Help needed trying to understand recursion.

Hi, I am trying to write a recursive method that returns the row of a multi dimensional array with the greatest sum.

For ex, With the given values : {{2,3,4},{6,8,9}{9,9,9,9}}.
Number 3 will be returned as the 3rd row has the largest amount of numbers.

The problem: I keep getting 0 as the result would appreciate if you could help with this method and a good explanation about the procedures as I would like to understand it.

What I've tried to do is go thorough each row and when the sum is the higher than the previous row update the current row.

The method:
Java Code:
```public int maxRow(){
return maxRow (_mat,0,0,0,0,0);
}

private int maxRow(int [] [] matrix, int i, int j, int sum,int ezer,int row){
if (j<matrix[i].length-1)
maxRow(matrix,i,j+1,sum,ezer+=matrix[i] [j],row);
if (ezer>sum)
maxRow(matrix,i,j,sum=ezer,0,i);

if (i<matrix.length-1){
maxRow(matrix,i+1,0,sum,0,i);
}
return row;
}
}```
Thanks.

2. Member
Join Date
Dec 2010
Posts
60
Rep Power
0

## I might reached to an understanding

please hold on with the replies, I've found a similar method on-line and working on it right now.

Thanks.

3. Member
Join Date
Feb 2011
Posts
30
Rep Power
0
Why you want to use recursion when the problem is very simple iteration problem?
Don't mess with recursion when it not simplifying the problem.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•