Can someone please tell how to generate n-bit strings(all possible combinations) i.e. counting bits form 0 to 2^n-1 using Divide and Conquer Approach.
I was able to do this with the following algorithm, but the space complexity as well as time complexity are of O(2^n). Can someone give me a better algorithm (using Divide and conquer) which requires less space than this.
ArrayList generate(int n)
{
if(n==1)
{
Create an arrayList and store strings "0" and "1";
}
else
{
generate(n-1)
now recompose the solution to get 2^n strings and return this arraylist
"PROBLEM here is that the length of the array list is also getting
exponential"
}
}