File tree 2 files changed +29
-7
lines changed
2 files changed +29
-7
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change 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
-
8
1
def sequentialSearch (alist , item ):
9
2
pos = 0
10
3
found = False
You can’t perform that action at this time.
0 commit comments