Skip to content

Commit 25bd6dd

Browse files
authored
Create Linear_Search.py
1 parent 02adb1f commit 25bd6dd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Linear_Search.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Linear Search in Python
2+
3+
4+
def linearSearch(array, n, x):
5+
6+
7+
for i in range(0, n):
8+
if (array[i] == x):
9+
return i
10+
return -1
11+
12+
13+
array = [2, 4, 0, 1, 9]
14+
x = 1
15+
n = len(array)
16+
result = linearSearch(array, n, x)
17+
if(result == -1):
18+
print("Element not found")
19+
else:
20+
print("Element found at index: ", result)

0 commit comments

Comments
 (0)