Skip to content

Commit 81fc74a

Browse files
authored
Add files via upload
1 parent b831317 commit 81fc74a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Searching/Binary_Search.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ def binary_search(arr:list[int],target:int,low:int,high:int)->int:
99
return binary_search(arr,target,low,mid-1)
1010
else:
1111
return -1
12-
12+
#main function to test the binary_search function
1313
if __name__=="__main__":
1414
arr=[1,7,13,15,20,50]
1515
target=15
16+
print("Binary Search")
1617
result=binary_search(sorted(arr),target,0,len(arr)-1)
1718
if result!=-1:
1819
print(f"Found element at index {result}")
1920
else:
20-
print("Not found")
21+
print("Not found")

Searching/Linear_Search.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ def linear_search(arr:list[int],target:int)->int:
44
if arr[i]==target:
55
return i
66
return -1
7-
7+
#main function to test the linear_search function
88
if __name__=="__main__":
99
arr=[1,7,13,15,20,50]
1010
target=7
11+
print("Linear Search")
1112
result=linear_search(arr,target)
1213
if result!=-1:
1314
print(f"Element at index {result}")
1415
else:
15-
print("Element not found.")
16+
print("Element not found.")

0 commit comments

Comments
 (0)