Solving Permutations Problems: Finding Algorithms & Optimizing Efficiency

In summary: You can do this in time O(N log N).In summary, you can find the kth composition of a permutation P in time O(N log N) if you have an algorithm that does this for any given natural N and any given permutation of N elements.
  • #1
alejandrito
7
0
I have two problems on permutations which I can´t solve now becuase my knowledge about permutations and the necessary tricks is very poor.
1st:
Find an algorithm that for given natural N (N<=1000), K and given permutation of N elements will find the Kth composition of this permutation in time less or equal to O(N log K).
2nd:
Find an algorithm that fot given natural N (N<=1000) and given permutation of N elements will determine the number of all cycles that the permutation is composed from in time less or equal to O(n).
Can anybody give me some hint related with any of this two problems, I´m mainly confused as to the satisfaction the maximal possible effecienty.
 
Technology news on Phys.org
  • #2
This sounds like a homework problem. Can you show use any type of thought process before we start giving you hints.
 
  • #3
Here's an example of a Permutation P on n=4 elements:
Code:
|x1 x2 x3 x4|
| 4  3  2  1|
This Permutation P sends element x1 to #4 spot, x2 to #3 ...etc, producing:
Code:
|x4 x3 x2 x1|

What happens if you apply permutation P twice? Then:
Code:
|x1 x2 x3 x4|
| 4  3  2  1|
|x4 x3 x2 x1|
| 4  3  2  1|
|x1 x2 x3 x4|
This would be the second composition of P. Notice that the resulting permutation of the 2nd Composition of P is the original arrangement of the n elements, so this is a cycle. Of course this isn't the case for every possible P. Suppose that a permutation Q moves each element xi one place to the right (wrapping around), then, it will go back to the original arrangement only at the nth (in this case the 4th) composition of Q.
In your first question you're asked to find the kth composition of a permutation P. Obviously you can do this in O(Nk) time (n elements and k applications of permutation P). You need to squeeze this into O(N log k). Here's a strategy:
Let A1 be a permutation equal to two applications of permutation P. Then let A2 be a permutation equal to two applications of permutation A1 (4 of P). Let A3 be two applications of A2 (8 of P).. etc. Then, if k = 8:
the permutation A3 gives you the kth composition of P. If k = 9, then A3 followed by P gives you the kth composition of P. If k = 10, then A3 followed by A1 gives you the kth composition of p ..etc. If k > 16 then you need to compute A4, and so on. This takes at most 2*N*log k = O(N log k).
Now all you need is to do is turn this into an algorithm which should be easy enough.
 
Last edited:

FAQ: Solving Permutations Problems: Finding Algorithms & Optimizing Efficiency

What is the difference between permutations and combinations?

Permutations and combinations are both ways of arranging a set of objects, but the main difference is that permutations take into account the order of the objects while combinations do not. For example, if you have the letters A, B, and C, a permutation would be ABC while a combination would be any group of these letters, such as ACB or BCA.

How do I approach solving a permutation problem?

The first step in solving a permutation problem is to clearly define what you are trying to find, whether it is the number of possible arrangements or a specific arrangement. Then, you can use various mathematical formulas or algorithms to find the solution. It may also be helpful to break down the problem into smaller, more manageable parts.

Can you provide an example of an algorithm for solving permutation problems?

One common algorithm for solving permutation problems is the factorial formula, which states that the number of permutations of n objects is n! (n factorial). For example, if you have 5 letters, there are 5! = 5 x 4 x 3 x 2 x 1 = 120 possible arrangements.

How can I optimize efficiency when solving permutation problems?

To optimize efficiency, it is important to understand the problem and choose the most appropriate formula or algorithm to use. It may also be helpful to use computer programs or calculators to handle larger numbers. Additionally, breaking down the problem into smaller parts and using strategies such as combination and repeated permutation can also save time.

Are there any real-life applications of solving permutation problems?

Permutations are used in various fields such as mathematics, computer science, and statistics. In real life, they can be used to determine the number of possible outcomes in games or to calculate the number of possible combinations of genetic traits. They can also be used in cryptography to create secure passwords or codes.

Back
Top