File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
searchingAlgo/linearSearch Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments