Is there any way to traverse all balanced bitvector?

35 Views Asked by At

Suppose a bit-vector with 2^n bits. It is a balanced bit-vector if it has exactly 2^(n-1) bit 1 (so does bit 0). Given n, can I print out all 2^n-bit balanced bit-vector in O(2^n)?

1

There are 1 best solutions below

0
MBo On

You can't.

Printing single 2^n bits vector takes O(2^n) time, and printing all possible vectors takes O(2^n*nCr(2^n, 2^(n-1))) - much more.