0

As i am from mathematics background and require to do some huge permutations to start in my work kind help.

If i have a table by name sample1 with n columns what is fastest way to get all the permutations of the rows of sample1 into a new table. n>=12 say.

Please provide kind help with a link where i can get help or any code or query.

An example

say the 6 columns of a row contain

E1       E2      E3        E4        E5        E6

'[0,1]' '[1,2]'  '[2,3]'   '[3.4]'   '[4,5]'   '[9,10]' 

I need to include its permutations

like

E1       E2      E3        E4        E5        E6

'[1,2]' '[0,1]'   '[2,3]'   '[3.4]'   '[4,5]'  '[9,10]'

 '[0,1]'   '[2,3]' '[3.4]' '[4,5]'  '[9,10]' '[1,2]'

and other permutations of row 1 above if there are n columns there will be n! permutations i need them also to be generated quickly and put into a new table. U can the headers as column name each is a varchar.

Like for the above table if there are two rows with same elements in each of its columns how to remove duplicates kind help with any query

  • 1
    What do you mean by "permutations of rows"? Can you provide some example of what you have and what you want to obtain? – mustaccio Dec 18 '15 at 17:06
  • 2
    Define "huge". Are we talking a million permutations, a billion permutations, or hundreds of billions of permutations? – Justin Cave Dec 18 '15 at 17:13
  • huge may be 5 lac rows and each has to be permuted 12! ways and added to the table – sriram Dec 19 '15 at 3:13
  • Kind help with a query to remove duplicate rows – sriram Dec 19 '15 at 15:52
  • I'm not sure what you mean by duplicate rows, is E_i != E_j if i != j? – Lennart Dec 21 '15 at 22:20
1

This isn't really an answer, more of a discussion of the problem. If I understand correctly, you would have 1 row with twelve columns turn into 479,001,600 rows. From the initial row you provided there are no duplicate values within the columns of the same row, so it doesn't appear that you are trying to eliminate duplicates within a row.

You didn't say how many rows are in your initial table, but this should mean that 100 rows in the initial table would equate to 47,900,160,000 rows in the resulting table. The only way there could be duplicates there is if two rows in the initial table had a row with the same values as another row.

If those values are in the same order, then a simple select distinct * from t1 would eliminate the duplicates. If instead the values are in a different order, then you actually have to determine the permutations for each row and make sure only one of those is in the initial table.

For smaller values of n, it would probably be easiest just to determine all the permutations of each row and then remove the duplicates. For larger values of n eliminating from the initial set would certainly be advantageous for lower numbers of rows in the initial table. As the initial table size grows the benefit of this early elimination is diminished.

Here is a way to get the permutations of one row. It is likely not the best way.

Here is a way to get rows that have duplicates in a different order in the initial table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.