Problem:
I want to generate all possible combination from 36 characters that consist of alphabet and numbers in a fixed length string. Assume that the term "fixed length" is the upper bound for my string length.
Some of these combinations are listed below:
a
b
c
.
.
z
0
1
.
.
9
.
.
.
aaaaaa
aaaaab
.
.
99999999999999999998
99999999999999999999 // end of the list
I don't want to store them in memory or disk because I calculate something on them and if they don't meet the goal result, well, I don't need it anymore.
Approaches:
1. For the first try, I choose recursion to create strings. But it's so awful in using memory.
2. For the second try, I use DFS algorithm because it's nearly optimal in using memory as it's around O(bm). But as time view, it's very time-consuming.
Is there any other way to do this more optimized?
UPDATE
Here is possible outputs for length 2 and 3 character:
a
b
c
aa
ab
ac
ba
bb
bc
ca
cb
cc