Skip to content

Commit 07e9f7f

Browse files
authored
Merge pull request deutranium#90 from Hamzakam/linear-search
Created readme.md for Linear Search.
2 parents 04a24fe + 40da96e commit 07e9f7f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

searchingAlgo/linearSearch/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Linear Search
2+
3+
- Searches For an Element by Traversing through the entire list.
4+
- Time Complexity:
5+
- Worst Case Complexity:O(n)
6+
- Best Case Complexity:O(1)
7+
- Average Case Complexity:O(n/2)
8+
- Worst Case Space Complexity:O(1)
9+
10+
### Logic
11+
12+
1. Iterate through Each Element and compare each Element till you find the element.
13+
2. If element is found,return the index.
14+
3. Otherwise return -1 or False representing that element is not found.
15+
4. Pseudo Code:
16+
17+
function linear_search(list,n)
18+
let i ← 0
19+
while i < len(list)
20+
if element = n
21+
return i
22+
return -1
23+
24+
### Instruction for Running code:
25+
- C
26+
```
27+
gcc LinearSearch.c
28+
./a.out
29+
```
30+
31+
- Cpp
32+
```
33+
g++ LinearSearch.cpp
34+
./a.out
35+
```
36+
- JavaScript
37+
```
38+
node LinearSearch.js
39+
```
40+
- Python
41+
```
42+
python3 LinearSearch.py
43+
```

0 commit comments

Comments
 (0)