forked from HarshCasper/NeoAlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbilinear.py
More file actions
32 lines (27 loc) · 705 Bytes
/
Copy pathbilinear.py
File metadata and controls
32 lines (27 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
''' Bilinear search is searching algorithm where it is search for a element from the both end.
It is a improved version of linear search.
'''
def bilinear(x,arr):
siz = len(arr)
p = 0
i = 0
j = siz-1
while i<j:
if arr[i] != x and arr[j] != x:
i+=1
j-=1
else:
p = 1
break
if p == 1:
return True
else:
return False
if __name__ == "__main__":
print('enter the list:')
l = list(map(int,input().split(' ')))
ele = int(input("enter the element to check:"))
if bilinear(ele,l):
print('element found')
elif bilinear(ele,l)==False:
print("element not found")