2222- O(1) - only a constant amount of extra space is used (for variables)
2323"""
2424
25-
2625from typing import Any , List , Optional
2726
2827
@@ -56,7 +55,7 @@ def linear_search(collection: List[Any], target: Any) -> int:
5655 numbers = [64 , 34 , 25 , 12 , 22 , 11 , 90 ]
5756 target_number = 22
5857 result = linear_search (numbers , target_number )
59-
58+
6059 print ("Example 1: Searching for a number" )
6160 print (f"Collection: { numbers } " )
6261 print (f"Target: { target_number } " )
@@ -70,7 +69,7 @@ def linear_search(collection: List[Any], target: Any) -> int:
7069 fruits = ["apple" , "banana" , "cherry" , "date" , "elderberry" ]
7170 target_fruit = "cherry"
7271 result = linear_search (fruits , target_fruit )
73-
72+
7473 print ("Example 2: Searching for a string" )
7574 print (f"Collection: { fruits } " )
7675 print (f"Target: { target_fruit } " )
@@ -84,7 +83,7 @@ def linear_search(collection: List[Any], target: Any) -> int:
8483 numbers = [1 , 3 , 5 , 7 , 9 ]
8584 target_number = 4
8685 result = linear_search (numbers , target_number )
87-
86+
8887 print ("Example 3: Target not found" )
8988 print (f"Collection: { numbers } " )
9089 print (f"Target: { target_number } " )
@@ -97,7 +96,7 @@ def linear_search(collection: List[Any], target: Any) -> int:
9796 # Example 4: Empty collection
9897 empty_list : List [int ] = []
9998 result = linear_search (empty_list , 5 )
100-
99+
101100 print ("Example 4: Empty collection" )
102101 print (f"Collection: { empty_list } " )
103102 print (f"Target: 5" )
0 commit comments