Skip to content

Commit 0b8a494

Browse files
Added Binary Search and Modified Linear Search
1 parent 5db8309 commit 0b8a494

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

Diff for: BinarySeach.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def binarySearch(alist, item):
2+
3+
first = 0
4+
last = len(alist)-1
5+
found = False
6+
7+
while first<=last and not found:
8+
9+
midpoint = (first + last)//2
10+
if alist[midpoint] == item:
11+
found = True
12+
print("Found")
13+
else:
14+
15+
if item < alist[midpoint]:
16+
17+
last = midpoint-1
18+
else:
19+
first = midpoint+1
20+
if found == False:
21+
22+
print("Not found")
23+
return found
24+
print("Enter numbers seprated by space")
25+
s = input()
26+
numbers = list(map(int, s.split()))
27+
trgt =int( input('enter a single number to be found in the list '))
28+
binarySearch(numbers, trgt)
29+

Diff for: LinearSearch.py

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
def search_linear(x,y):
2-
n = len( x )
3-
for i in range(n):
4-
if theValue[i] == y:
5-
return True
6-
return false
7-
81
def sequentialSearch(alist, item):
92
pos = 0
103
found = False

0 commit comments

Comments
 (0)