Currently I am studying Data Structure and Algorithmic thinking with python by Narasimha Karumanchi. But I can't understand one question which is as follows:
Q. Generate all the binary strings with n-bits. Assume A[0..n-1] is an array of size n.
Sol:
def appendAtFront(x,L):
return [x+element for element in L]
def bitStrings(n):
if n == 0: return []
if n == 1: return ["0", "1"]
else:
return (appendAtFront("0", bitStrings(n-1) + appendAtFront("1", bitStrings(n-1))))
print(bitStrings(4))
OUTPUT:
['0000', '0001', '00010', '00011', '00100', '00101', '001010', '001011', '01000', '01001', '010010', '010011', '010100', '010101', '0101010', '0101011']
Can any one explain me what this question is asking?


The question is asking you to generate all possible binary strings of length n. In binary, each digit can be either 0 or 1, so for a binary string of length n, you can have 2^n possible combinations.
e.g.: