Question: Write a JAVA recursive function (i.e. using a decrease-and-conquer algorithm) that will generate an ArrayList of all the patterns of a given length. It does
Write a JAVA recursive function (i.e. using a decrease-and-conquer algorithm) that will generate an ArrayList of all the patterns of a given length. It does not matter what order the patterns appear on the list. Make an alternative list that contains only the patterns that do not have any repeated adjacent digits.
For example, if your function is called with an argument of N=3, the following would be the contents of the ArrayList. These are strings, not numbers: [000, 001, 002, 010, 011, 012, 020, 021, 022, 100, 101, 102, 110, 111, 112, 120, 121, 122, 200, 201, 202, 210, 211, 212, 220, 221, 222]
Here is the list for N=4 (81 patterns): [0000, 0001, 0002, 0010, 0011, 0012, 0020, 0021, 0022, 0100, 0101, 0102, 0110, 0111, 0112, 0120, 0121, 0122, 0200, 0201, 0202, 0210, 0211, 0212, 0220, 0221, 0222, 1000, 1001, 1002, 1010, 1011, 1012, 1020, 1021, 1022, 1100, 1101, 1102, 1110, 1111, 1112, 1120, 1121, 1122, 1200, 1201, 1202, 1210, 1211, 1212, 1220, 1221, 1222, 2000, 2001, 2002, 2010, 2011, 2012, 2020, 2021, 2022, 2100, 2101, 2102, 2110, 2111, 2112, 2120, 2121, 2122, 2200, 2201, 2202, 2210, 2211, 2212, 2220, 2221, 2222]
Alternative list for N=4: [0101, 0102, 0120, 0121, 0201, 0202, 0210, 0212, 1010, 1012, 1020, 1021, 1201, 1202, 1210, 1212, 2010, 2012, 2020, 2021, 2101, 2102, 2120, 2121]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
