This example shows how Sequential Search algorithm works.

Simple way to search for a key value k in an array a is to compare the values of the elements in a with k. The process starts with the first element of the array and k and comparison continues as long as either the comparison does not result in a success or the list of elements in the array are exhausted. This method of searching is known as sequential search or linear search.

The following code example will return the index of the array when a successful search is found for the given key value and when the search is unsuccessful, the function returns -1.

The complete source code

Output

Thanks for reading.

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.