In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched.



Step 1: Initialize Array A and Variable X for searching element.
Step 2: Set i to 1 and initialize n as array size
Step 3: if i > n then go to step 8
Step 4: if A[i] = x then go to step 7
Step 5: Set i to i + 1
Step 6: Go to Step 3
Step 7: Print Element x Found at index i and go to step 9
Step 8: Print element not found
Step 9: Exit







Input / Output:

Enter number of elements in array: 5
Enter 5 integer(s)
Enter Value: 22
Enter Value: 23
Enter Value: 43
Enter Value: 56
Enter Value: 76

Enter a number to search:23
23 is present at location 2.



The time complexity of the above algorithm is: O(n). It is not widely used because for a value the whole array must be search that takes times for very large array size. There are Binary search we used instead of linear search. This programming steps is east to remember and a very good beginning for beginners.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner