Skip to content

Commit ded9099

Browse files
author
Dmytro Litvinov
authored
Add type hints for searches/ternary_search.py (TheAlgorithms#2874)
1 parent bffb93a commit ded9099

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Diff for: searches/ternary_search.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
Space Complexity : O(1)
88
"""
99
import sys
10+
from typing import List
1011

1112
# This is the precision for this function which can be altered.
1213
# It is recommended for users to keep this number greater than or equal to 10.
1314
precision = 10
1415

1516

1617
# This is the linear search that will occur after the search space has become smaller.
17-
def lin_search(left, right, A, target):
18+
def lin_search(left: int, right: int, A: List[int], target: int):
1819
for i in range(left, right + 1):
1920
if A[i] == target:
2021
return i
2122

2223

2324
# This is the iterative method of the ternary search algorithm.
24-
def ite_ternary_search(A, target):
25+
def ite_ternary_search(A: List[int], target: int):
2526
left = 0
2627
right = len(A) - 1
2728
while True:
@@ -51,7 +52,7 @@ def ite_ternary_search(A, target):
5152

5253

5354
# This is the recursive method of the ternary search algorithm.
54-
def rec_ternary_search(left, right, A, target):
55+
def rec_ternary_search(left: int, right: int, A: List[int], target: int):
5556
if left < right:
5657

5758
if right - left < precision:
@@ -77,7 +78,7 @@ def rec_ternary_search(left, right, A, target):
7778

7879

7980
# This function is to check if the array is sorted.
80-
def __assert_sorted(collection):
81+
def __assert_sorted(collection: List[int]) -> bool:
8182
if collection != sorted(collection):
8283
raise ValueError("Collection must be sorted")
8384
return True

0 commit comments

Comments
 (0)