mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
[mypy] Add/fix type annotations for backtracking algorithms (#4055)
* Fix mypy errors for backtracking algorithms * Fix CI failure
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user