Creates a state space tree to iterate through each branch using DFS. We know that each state has exactly two children. It terminates when it reaches the end of the given sequence. :param sequence: The input sequence for which subsequences are generated. :param current_subsequen
(
sequence: list[Any], current_subsequence: list[Any], index: int
)
| 16 | |
| 17 | |
| 18 | def create_state_space_tree( |
| 19 | sequence: list[Any], current_subsequence: list[Any], index: int |
| 20 | ) -> None: |
| 21 | """ |
| 22 | Creates a state space tree to iterate through each branch using DFS. |
| 23 | We know that each state has exactly two children. |
| 24 | It terminates when it reaches the end of the given sequence. |
| 25 | |
| 26 | :param sequence: The input sequence for which subsequences are generated. |
| 27 | :param current_subsequence: The current subsequence being built. |
| 28 | :param index: The current index in the sequence. |
| 29 | |
| 30 | Example: |
| 31 | >>> sequence = [3, 2, 1] |
| 32 | >>> current_subsequence = [] |
| 33 | >>> create_state_space_tree(sequence, current_subsequence, 0) |
| 34 | [] |
| 35 | [1] |
| 36 | [2] |
| 37 | [2, 1] |
| 38 | [3] |
| 39 | [3, 1] |
| 40 | [3, 2] |
| 41 | [3, 2, 1] |
| 42 | |
| 43 | >>> sequence = ["A", "B"] |
| 44 | >>> current_subsequence = [] |
| 45 | >>> create_state_space_tree(sequence, current_subsequence, 0) |
| 46 | [] |
| 47 | ['B'] |
| 48 | ['A'] |
| 49 | ['A', 'B'] |
| 50 | |
| 51 | >>> sequence = [] |
| 52 | >>> current_subsequence = [] |
| 53 | >>> create_state_space_tree(sequence, current_subsequence, 0) |
| 54 | [] |
| 55 | |
| 56 | >>> sequence = [1, 2, 3, 4] |
| 57 | >>> current_subsequence = [] |
| 58 | >>> create_state_space_tree(sequence, current_subsequence, 0) |
| 59 | [] |
| 60 | [4] |
| 61 | [3] |
| 62 | [3, 4] |
| 63 | [2] |
| 64 | [2, 4] |
| 65 | [2, 3] |
| 66 | [2, 3, 4] |
| 67 | [1] |
| 68 | [1, 4] |
| 69 | [1, 3] |
| 70 | [1, 3, 4] |
| 71 | [1, 2] |
| 72 | [1, 2, 4] |
| 73 | [1, 2, 3] |
| 74 | [1, 2, 3, 4] |
| 75 | """ |
no test coverage detected