Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
4rostyPs authored Feb 16, 2023
0 parents commit 0834316
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions binarySearchAlg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#binary search alg

sampleList = [1,2,3,4,5,6,7,8,9]
element = 103
low = 0
high = len(sampleList)-1
mid = (low+high)//2
while low <= high:
if element == sampleList[mid]:
print(mid)
break
elif element < sampleList[mid]:
high = mid - 1
mid = (low+high)//2
else:
low = mid + 1
mid = (low+high)//2
print("End")
8 changes: 8 additions & 0 deletions linearSearchAlg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#linear search alg

sampleList = [1,6,7,8,9,2,3,4,5]
element = 3
for i in range(len(sampleList)):
if element == sampleList[i]:
print(i)
break

0 comments on commit 0834316

Please sign in to comment.