@@ -5,6 +5,10 @@ def double_linear_search(array: list[int], search_item: int) -> int:
55 """
66 Iterate through the array from both sides to find the index of search_item.
77
8+ This algorithm searches for a target value from both the start and end of the
9+ array simultaneously, converging toward the middle. It returns the index of the
10+ first match found (prioritizing from the start when both ends match simultaneously).
11+
812 :param array: the array to be searched
913 :param search_item: the item to be searched
1014 :return the index of search_item, if search_item is in array, else -1
@@ -18,6 +22,45 @@ def double_linear_search(array: list[int], search_item: int) -> int:
1822 -1
1923 >>> double_linear_search([1, 5, 5, 10], 10)
2024 3
25+
26+ >>> double_linear_search([], 1)
27+ -1
28+
29+ >>> double_linear_search([42], 42)
30+ 0
31+
32+ >>> double_linear_search([42], 99)
33+ -1
34+
35+ >>> double_linear_search([1, 2, 3, 4, 5], 3)
36+ 2
37+
38+ >>> double_linear_search([1, 2, 3, 4, 5], 1)
39+ 0
40+
41+ >>> double_linear_search([1, 2, 3, 4, 5], 5)
42+ 4
43+
44+ >>> double_linear_search([10, 10, 10, 10], 10)
45+ 0
46+
47+ >>> double_linear_search([-5, -2, 0, 3, 7], -5)
48+ 0
49+
50+ >>> double_linear_search([-5, -2, 0, 3, 7], 0)
51+ 2
52+
53+ >>> double_linear_search([-5, -2, 0, 3, 7], 7)
54+ 4
55+
56+ >>> double_linear_search([1, 2, 3, 4, 5, 6, 7, 8, 9], 5)
57+ 4
58+
59+ >>> double_linear_search([1, 2, 3, 4, 5, 6, 7, 8, 9], 9)
60+ 8
61+
62+ >>> double_linear_search([100, 200, 300, 400], 250)
63+ -1
2164 """
2265 # define the start and end index of the given array
2366 start_ind , end_ind = 0 , len (array ) - 1
0 commit comments