Skip to content

Commit cd632f0

Browse files
Merge pull request #652 from dhrjklt/dhrjklt49
Linear search readme
2 parents b3ef921 + 5b02987 commit cd632f0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Search/LinearSearch/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Linear Search
2+
3+
Given an array arr[] of n elements, write a function to search a given element x in arr[].
4+
5+
A simple approach is to do linear search, i.e
6+
7+
1.Start from the leftmost element of arr[] and one by one compare x with each element of arr[]
8+
9+
2.If x matches with an element, return the index.
10+
11+
3.If x doesn’t match with any of elements, return -1.
12+
13+
14+
# The time complexity of above algorithm is O(n).
15+
16+
Linear search is rarely used practically because other search algorithms such as the binary search algorithm and hash tables allow significantly faster searching comparison to Linear search.

0 commit comments

Comments
 (0)