I want to create all possible variations to traverse a data structure. When I traverse i can either go left (L) or right (R). So my plan for this is to genereate all possible paths, before I traverse the data structure. Each character should serve as an instruction for traversing.
I need a method to generate the following:
private List<String> createPaths(int len){
List<String> result = new ArrayList<>();
// no clue how to generate them
return result;
}
for len = 1 the results should be: {L,R}
for len = 2 the results should be: {LL,LR,RR,RL}
for len = 3 the results should be: {LLL,LLR,LRL,LRR,RLL,RLR,RRL,RRR}
I have already tried to solve it with the help of the binary numbers, but I failed.