I am quite new in programming and JAVA. I have created a simple JAVA code for the generation of S-permutation matrices. S- permutation matrices are the square matrices which have 1 in each row, each column and each block exactly once e.g.
1 0 0 * 0 0 0 * 0 0 0
0 0 0 * 1 0 0 * 0 0 0
0 0 0 * 0 0 0 * 1 0 0
***********************
0 1 0 * 0 0 0 * 0 0 0
0 0 0 * 0 1 0 * 0 0 0
0 0 0 * 0 0 0 * 0 1 0
***********************
0 0 1 * 0 0 0 * 0 0 0
0 0 0 * 0 0 1 * 0 0 0
0 0 0 * 0 0 0 * 0 0 1
Above is an example of 9 X 9 S-permutation matrix.
4 x 4 example is
1 0 * 0 0
0 0 * 1 0
***********
0 1 * 0 0
0 0 * 0 1
I made a Java code for 4 X 4 and it is generating all 4 X 4 S-permutation matrices which are 16 in number. But with the same logic when I did it for 9 X 9 the program is giving some matrices and then showing stackoverflow error.
These 9 X 9 S-permutation matrices are 46656 in number. The program is giving some 2000 matrices and then showing stackoverflow error. I asked some of my friends and searched on google and think either the logic of the program is at fault or it is because of heavy use of recursion in the program.
Would any one please help me regarding this and tell me how can I minimize use of recursion. I read on some site that one way is of using loops but there is no way of using loops for that. Kindly tell me is there any other way for it?
Program which I am gonna share is the second program I made and it is giving only around 300 matrices..http://pastebin.com/2LBCCcE9