How to find the nth binary permutation?

In summary, the conversation discusses the calculation and computation of the total number of permutations for a given number with a specific number of bits set as 1. It also mentions the desire to find the nth permutation sequence for a given number. There are algorithms available, such as the lexicographic method, to find the nth permutation.
  • #1
Chadi B Ghaith
35
4
I need to complete this.
Let's say I have 4 bits with 2 bits set as 1, 0011. The total number of permutations for this number is 0011, 0101, 0110, 1001, 1010, 1100, 6 cases. This can be computed using the calculation.

4! / ((2!)(4-2)!) = 6

Now I want to be able to find the nth sequence, for instance 1st number is 0011, second number is 0101. So if I say n=5, I want to be able to get the 5th permutation sequence 1010 from the initial 0011. How do I do this?
 
Mathematics news on Phys.org
  • #2
What do you mean by 'the nth sequence'? You have given a 'for instance' but I don't even understand that case, let alone how you wish to generalise it.
 
  • #3
There are algorithms to find the nth permutation for a given order (e. g. lexicographic - as it would appear in a lexikon). Example, another example.

The basic idea: Start with the first digit: How many permutations start with 0? Compare your number to that number and you get the first digit. Continue like that for all other digits.
 

Related to How to find the nth binary permutation?

1. How do I determine the total number of possible binary permutations for a given number of digits?

The total number of possible binary permutations for a given number of digits is calculated by raising 2 to the power of the number of digits. For example, if you have 3 digits, there are 2^3 or 8 possible binary permutations.

2. How do I find the nth binary permutation in a sequence?

To find the nth binary permutation in a sequence, you can use the formula n-1 in binary. For example, if you are looking for the 5th permutation, you would convert 5-1 (4) into binary, which is 100. This represents the 5th permutation in a sequence of 3 digits (2^3 = 8).

3. Can I use a computer program or algorithm to find the nth binary permutation?

Yes, you can use a computer program or algorithm to find the nth binary permutation. Many programming languages have built-in functions for generating binary permutations, such as Python's itertools.permutations() function.

4. How do I ensure that all possible binary permutations are included in my search?

To ensure that all possible binary permutations are included in your search, you can use a loop to iterate through all possible combinations of 0s and 1s. Alternatively, you can use built-in functions or libraries that handle binary permutations for you.

5. Can I apply the same method for finding the nth binary permutation to other types of permutations?

Yes, you can apply a similar method for finding the nth permutation in other types of permutations, such as strings or arrays of numbers. However, the calculation for the total number of possible permutations may differ depending on the type of data being permuted.

Similar threads

  • General Math
Replies
2
Views
3K
  • General Math
Replies
1
Views
726
Replies
2
Views
2K
  • General Math
Replies
2
Views
1K
  • General Math
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
13
Views
2K
  • Math Proof Training and Practice
Replies
23
Views
559
Back
Top