Results 1 to 3 of 3
 02122011, 06:09 PM #1Member
 Join Date
 Dec 2010
 Posts
 88
 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].length1) 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.length1){ maxRow(matrix,i+1,0,sum,0,i); } return row; } }
 02122011, 08:52 PM #2Member
 Join Date
 Dec 2010
 Posts
 88
 Rep Power
 0
I might reached to an understanding
please hold on with the replies, I've found a similar method online and working on it right now.
Thanks.
 02122011, 09:06 PM #3Member
 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.
Similar Threads

Clever glimpse needed with this recursion
By Yakg in forum New To JavaReplies: 14Last Post: 02102011, 09:15 PM 
GUI help. Don t understand
By s0meb0dy in forum AWT / SwingReplies: 2Last Post: 10272010, 09:40 PM 
Trying to understand
By ladykrimson in forum New To JavaReplies: 20Last Post: 10122010, 11:10 PM 
findind it very difficult to understand recursion.
By talper in forum New To JavaReplies: 20Last Post: 05262010, 06:18 PM 
recursion and tailrecursion differences
By OptimusPrime in forum New To JavaReplies: 2Last Post: 12282009, 06:26 PM
Bookmarks