Count all binary numbers with equal 1 and 0

I am implementing a binary representation of a two-way equalization algorithm, and I am wondering what is the best way to iterate through all combinations of N bits having equal (N / 2) 1 and 0. I am trying to find the fastest way and not the simplest code. Thank.

+3
source share
1 answer

It is simple (N choose N/2); you choose which bits are 0s, the remaining 1s.

If you have 10 bits and you want 5 zeros and 5 units, there are (10 choose 5) = 252possibilities.


See also:


, (n k). k n/2, ; , , , .

, - , , : , , ? .

, .

+2

Source: https://habr.com/ru/post/1741032/


All Articles