Write an algorithm to search an element using  linear search algorithm.

Algorithm for linear search algorithm steps:
Step 1 : START
Step 2 : input N
Step 3 : for I← 0 to N -1
Read A [ I ]
Step 4 : LOC = -1
Step 5 : For I = 0 to N- 1 do
Step 6 : If ( ELEMENT = A[I]) Then
Step 7: LOC = I
Step 8 : Goto step 9


[ end if ]
[ end for ]
Step 9 : If ( LOC > = 0 ) then
Step 10: Print “ ELEMENT Found in location “ , LOC.
Step 11: else
Step 12: Print “ ELEMENT not found ”
Step 13 : Stop.


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: