Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Lines changed: 7 additions & 0 deletions
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
Lines changed: 7 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /