Skip to content

Commit c06dcd4

Browse files
committed
Linear Search
1 parent 49d8b7f commit c06dcd4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Data Structures and Algorithms Patterns implemented in Python.
2121
- [x] [Depth First Search](Graphs/dfs.py)
2222
- [x] [Searching Alogorithms](Searching-Algo)
2323
- [x] [Binary Search](Searching-Algo/binarysearch.py)
24+
- [x] [Linear Search](Searching-Algo/linearsearch.py)
2425

Searching-Algo/linearsearch.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''
2+
Linear Search
3+
Linear search is also called as sequential search algorithm. It is the simplest searching algorithm. In Linear search, we simply traverse the list completely and match each element of the list with the item whose ___location is to be found. If the match is found, then the ___location of the item is returned; otherwise, the algorithm returns NULL.
4+
'''
5+
6+
def linearsearch(n,t):
7+
for i in range(len(n)):
8+
if t==n[i]:
9+
return i
10+
return -1
11+
12+
a = [1,2,4,5,8]
13+
print(linearsearch(a,8)) #4

0 commit comments

Comments
 (0)