Skip to content

Commit 7ed425e

Browse files
ak4522912trekhleb
authored andcommitted
Added Linear Search (trekhleb#20)
Added algorithm for the basic and useful linear search
1 parent 48195d4 commit 7ed425e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Linear Search
2+
In computer science, linear search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched.
3+
Linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list.
4+
5+
##References-
6+
-[Wikipedia] https://en.wikipedia.org/wiki/Linear_search
7+
-[Youtube] https://www.youtube.com/watch?v=SGU9duLE30w
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function linearSearch(array, Find){
2+
for(let i = 0; i < array.length; i++){
3+
if(array[i] === Find) return i;
4+
5+
}
6+
return -1;
7+
}

0 commit comments

Comments
 (0)