JTable with 5 column and n rows. After filling the table with values i've got an array of object of cell values . I want to perform the permutation combination on this Object  to fetch the all possible combinations of n(row)-5(column-fix) elements. suppose i have 5 rows and 5 columns in the table then it should generate all possible combinations i.e(120) without repeating the elements. result should be such that from each column only one elements would be selected at a time. each individual combination will have exact 5 elemnts. Sequence of elements will not be considered. The permutation should be the maximal possible combination of the attributes with each other.
For Example: Result should be like this each (combination must be unique):
1st column will always have A's, 2nd column will always have B's, 3rd C's, 4th D's and 5th E's......
A1B1C1D1E1....Correct combs A1B2C1D1E1 A2B1C1D1E1 A2B2C1D1E1 ......................... B1A1C1D1E1...wrong combination( At 1st place only A should be entertain) ........................ and so on.... Can i get some help or code snippet to generate this?
Normally permutations and combinations are two different things, and it's confusing to refer to this as a "permutation combination". What you have here seems to be a combinations problem, with additional constraints, so I'll just use the term combinations.
It looks to me like there are not 120 combinations here, but 3125. That is, there are 5 choices for the first positions, 5 choices for the second, 5 for the third, etc. 5 * 5 * 5 * 5 * 5 = 3125. Since each position is drawn from a separate sample set (1st column is always an A, 2nd always a B, etc) there is no need to divide by anything to eliminate duplicates.
It seems like it should be fairly straightforward to solve this with some nested for loops - five of them. Or you could do this with a recursive solution, if you prefer. Whichever makes more sense to you. I'd prefer the nested loops:
For simplicity, while working on this you may want to start with a smaller table, e.g. 2 x 2 or 3 x 3. Because it may be difficult to check 3125 rows for accuracy. But checking 4 or 27 is easier.
"I'm not back." - Bill Harding, Twister
posted 12 years ago
Thanks for your help.... Actualy i also tried the same with one D array. I have a 2D array like Object[n][m] where m=5 (Fixed), but n could be anything. so the combination of elements should be generated according to no. of rows.