MATLAB Answers

How to get all permutation of a large vector?

43 views (last 30 days)
Hildo
Hildo on 17 Nov 2016
Edited: John D'Errico on 17 Nov 2016
How to get all permutation of a large vector? (50 elements) I need this to generate a Simulink simulation with each combination result. So the ideal is some generation in a loop.

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Nov 2016
If you were able to process the entries at a rate of 5 GHz (that is, you were able to process 5*10^9 complete entries per second), then it would take you 1.93 * 10^47 years to process all 30414093201713378043612608166064768844377641568960512000000000000 permutations.
But if you have a yotta-yotta year to spare,

  4 Comments

Show 1 older comment
Guillaume
Guillaume on 17 Nov 2016
You expressed yourself very clearly the first time but you're not understanding Walter so well.
There are 50! permutations of a 50 elements vector. According to Walter, that's 30414093201713378043612608166064768844377641568960512000000000000 of them (I haven't checked, I believe him). So as Walter pointed out even if you can generate 5,000,000,000 permutations per second (unlikely) in your for loop, it will still take 1.93e47 years for the loop to finish.
You need to rethink your approach. It's simply not possible.
Walter Roberson
Walter Roberson on 17 Nov 2016
If you processed at the same rate that I described above, then a vector with 30 elements would take approximately 1.68 * 10^15 years.
This figure needs to be understood as a very very rough approximation. The rotation of the Earth is slowing down due to gravity interactions with the Moon, so the very meaning of "year" will change, even if only in terms of "days". On the other hand, apparently the Sun is likely to only last about another 2.2 * 10^9 years and if the Earth survives that, you can be sure that "year" will have a very different meaning.
If you were to compare age of the Universe itself to the age that the Universe would have at the end of the 1.68 * 10^15 years, it would be like the first 4.38 minutes out of a year.
You should probably rethink your strategy.
John D'Errico
John D'Errico on 17 Nov 2016
Yes, but with Moore's law in operation, before 10^15 years have passed, computers will be fast enough to process this easily. In fact, we can even predict when computers will be capable of solving the larger problem, of computing all permutations of 50 elements. (In theory, assuming we are still alive by then, and Skynet has not managed to do nasty things to us.) The thing is, by the time we are actually capable of solving the desired problem, this question will have been replaced by someone wanting to generate all permutations of 100000 elements, or something as bad.
So, even with Moore's law on our side, we can't win. Lets just call it John's law:
No matter how big or powerful their computer may be, there will always be somebody wanting to solve a problem that is ridiculously large, far beyond the capabilities of that computer, or even any computer in the known universe.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags

Products