Skip to content

Commit af477c2

Browse files
committed
Linear Search README file added
1 parent 303d995 commit af477c2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Searching/Linear Search/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Linear Search
2+
3+
**Linear search** is a very simple search algorithm. In this type of search, a sequential search is made over all items one by one. Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data collection.
4+
5+
![Linear Search](linear_search.gif)
6+
7+
8+
#### JavaScript Implementation
9+
10+
Though it is very easy in JavaScript to find index of an item in a list using [indexOf method](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf?v=example):
11+
12+
`list.indexOf(item)`
13+
14+
but sometimes you might need to do some customization on the searching algorithm. Like- *'finding the last occurrence of the item in the list'* etc. This linear search implementation will help you to do that.
15+
16+
#### Complexity Analysis
17+
- Worst Case - O(n)
18+
- Best Case - O(1)
19+
- Average Case - O(n)
20+
21+
22+
### More on this topic
23+
- https://en.wikipedia.org/wiki/Linear_search
24+
- https://www.tutorialspoint.com/data_structures_algorithms/linear_search_algorithm.htm
36.7 KB
Loading

0 commit comments

Comments
 (0)