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
Post A Comment:
0 comments: