
February 29th, 2008, 09:35 PM
|
|
Registered User
|
|
Join Date: Feb 2008
Posts: 1
Time spent in forums: 8 m 54 sec
Reputation Power: 0
|
|
|
Generating binary sequences
Given n bits, I need to generate all possible n bit binary sequences in order of most zeros to least zeros. For the n Choose k sequences with k zeros, the order doesn't really matter.
Ie if n=3 I need to generate the sequence:
000, 001, 010, 100, 011, 101, 110, 111
How the hell do I do this as efficiently as possible (or at all)? Intuition tells me to form a binary tree of 0's and 1's and somehow parse it, but I can't seem to figure out how to do that.
Any suggestions? I'm using C++, though this seems to be more of an algorithmic question than depending on any specific language feature.
Thanks.
|