[mypy] Add/fix type annotations for backtracking algorithms (#4055)

* Fix mypy errors for backtracking algorithms

* Fix CI failure
This commit is contained in:
Dhruv Manilawala
2020-12-24 18:16:21 +05:30
committed by GitHub
parent 0ccb213c11
commit f3ba9b6c50
7 changed files with 101 additions and 109 deletions

View File

@ -1,13 +1,12 @@
"""
In this problem, we want to determine all possible subsequences
of the given sequence. We use backtracking to solve this problem.
Time complexity: O(2^n),
where n denotes the length of the given sequence.
"""
from typing import Any, List
"""
In this problem, we want to determine all possible subsequences
of the given sequence. We use backtracking to solve this problem.
Time complexity: O(2^n),
where n denotes the length of the given sequence.
"""
def generate_all_subsequences(sequence: List[Any]) -> None:
create_state_space_tree(sequence, [], 0)
@ -32,15 +31,10 @@ def create_state_space_tree(
current_subsequence.pop()
"""
remove the comment to take an input from the user
if __name__ == "__main__":
seq: List[Any] = [3, 1, 2, 4]
generate_all_subsequences(seq)
print("Enter the elements")
sequence = list(map(int, input().split()))
"""
sequence = [3, 1, 2, 4]
generate_all_subsequences(sequence)
sequence = ["A", "B", "C"]
generate_all_subsequences(sequence)
seq.clear()
seq.extend(["A", "B", "C"])
generate_all_subsequences(seq)