7
7
Space Complexity : O(1)
8
8
"""
9
9
import sys
10
+ from typing import List
10
11
11
12
# This is the precision for this function which can be altered.
12
13
# It is recommended for users to keep this number greater than or equal to 10.
13
14
precision = 10
14
15
15
16
16
17
# 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 ):
18
19
for i in range (left , right + 1 ):
19
20
if A [i ] == target :
20
21
return i
21
22
22
23
23
24
# 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 ):
25
26
left = 0
26
27
right = len (A ) - 1
27
28
while True :
@@ -51,7 +52,7 @@ def ite_ternary_search(A, target):
51
52
52
53
53
54
# 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 ):
55
56
if left < right :
56
57
57
58
if right - left < precision :
@@ -77,7 +78,7 @@ def rec_ternary_search(left, right, A, target):
77
78
78
79
79
80
# This function is to check if the array is sorted.
80
- def __assert_sorted (collection ) :
81
+ def __assert_sorted (collection : List [ int ]) -> bool :
81
82
if collection != sorted (collection ):
82
83
raise ValueError ("Collection must be sorted" )
83
84
return True
0 commit comments