Added Linear Search (#20)

Added algorithm for the basic and useful linear search
This commit is contained in:
ak4522912 2018-05-26 03:13:50 +05:30 committed by Oleksii Trekhleb
parent 48195d4720
commit 7ed425ed3a
2 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#Linear Search
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.
Linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list.
##References-
-[Wikipedia] https://en.wikipedia.org/wiki/Linear_search
-[Youtube] https://www.youtube.com/watch?v=SGU9duLE30w

View File

@ -0,0 +1,7 @@
function linearSearch(array, Find){
for(let i = 0; i < array.length; i++){
if(array[i] === Find) return i;
}
return -1;
}