What is Searching?(Linear/Sequential Search) - CodeTextPro

What is searching?

Ans: The searching operation is used to search an element in an array.

I/P: An array A[l.......u] of n elements and the key-value.
O/P: Return the index position with a successful message.
DS: An array A[l.......u]

  1. i=0, found=0, location=0 //found=0 indicates search is not finished and unsuccessful.
  2. while(i<=u) and found=0
  3. if(A[i]=key) then
  4. found=1
  5. location=i
  6. else
  7. i=i+1
  8. End if
  9. End while
  10. if found=1 then
  11. Print"Search is successful: Key is present in the array at location"
  12. else
  13. Print"Search is unsuccessful: Key is not present in the array"
  14. End if
  15. Stop.

Post a Comment