[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

@@ -6,11 +6,11 @@
Wikipedia: https://en.wikipedia.org/wiki/Hamiltonian_path
"""
from __future__ import annotations
from typing import List
def valid_connection(
graph: list[list[int]], next_ver: int, curr_ind: int, path: list[int]
graph: List[List[int]], next_ver: int, curr_ind: int, path: List[int]
) -> bool:
"""
Checks whether it is possible to add next into path by validating 2 statements
@@ -47,7 +47,7 @@ def valid_connection(
return not any(vertex == next_ver for vertex in path)
def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int) -> bool:
def util_hamilton_cycle(graph: List[List[int]], path: List[int], curr_ind: int) -> bool:
"""
Pseudo-Code
Base Case:
@@ -108,7 +108,7 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
return False
def hamilton_cycle(graph: list[list[int]], start_index: int = 0) -> list[int]:
def hamilton_cycle(graph: List[List[int]], start_index: int = 0) -> List[int]:
r"""
Wrapper function to call subroutine called util_hamilton_cycle,
which will either return array of vertices indicating hamiltonian cycle