0% found this document useful (0 votes)
7 views9 pages

Linear Search

Uploaded by

soniyavaidya1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Linear Search

Uploaded by

soniyavaidya1204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Linear Search

The linear search algorithm is


defined as a sequential search
algorithm that starts at one end
and goes through each element
of a list until the desired element
is found; otherwise, the search
continues till the end of the
dataset.
Algorithm for Linear Search Algorithm:
1. Start: Begin at the first element of the collection of
elements.
2.Compare: Compare the current element with the
desired element.
3. Found: If the current element is equal to the
desired element, return true or index to the current
element.
4. Move: Otherwise, move to the next element in the
collection.
5. Repeat: Repeat steps 2-4 until we have reached
the end of collection.
6. Not found: If the end of the collection is reached
without finding the desired element, return that the
Step 1: Start from the first element
(index 0) and compare key with each
element (L[i]).
L=[10,50,70,20,40,3
0]
10 50 70 20 40 30

K 70
=
Step 2: Comparing key with next element L[1].
SInce not equal, the iterator moves to the next
element as a potential match.

10 50 70 20 40 30

K 70
Step 2: Now when comparing L[2] with key, the value
matches. So the Linear Search Algorithm will yield a
successful message and return the index of the element when
key is found (here 2).

10 50 70 20 40 30

K 70
10 50 70 20 40 30

K K K=
=
= 70 70 70

You might also like