+2 votes
in Class 12 by kratos

Write the algorithm for linear search.

1 Answer

+6 votes
by kratos
 
Best answer

Linear_search(Array, ele, N)
Step 1: loc = -l
Step 2 : for i = 0 to N-l repeat step 3 through step step 5
Step 3 : if (Array[i] = ele ) then step 4 through step 5
Step 4 : loc = i Step 5 : goto step
Step 6 : if (loc >=0 ) then step 7 otherwise step 8
Step 7 : output “The search element found at location “, loc
Step 8 : output “Search is unsuccessful”
Step 9 : exit.

...