Problem solving with programming: Forming the nth binary sequence
A binary sequence contains 0 and 1 onlyS.No Binary sequence
--------------------
1 0
2 1
3 00
4 01
5 10
...
Given a number k, we have to design an algorithm to print kth binary sequence.
Initial approach (not efficient):
Starting from the sequence 0, this algorithm iterates k times.
To get the next sequence, in each iteration we do the following.
check the last index of 0 in the number
- If it is found change that to 1 and all the digits after that to 0
- If it is not found, the next sequence contains all 0 which is one digit longer than previous
Read full article from Problem solving with programming: Forming the nth binary sequence