Showing posts with label Searching Algorithm. Show all posts
Showing posts with label Searching Algorithm. Show all posts

Wednesday, July 3, 2013

Linear or Sequential Search Algorithm | Searching Algorithm

Linear or Sequential Search Algorithm is one of simplest search algorithms but no very efficient. The objective of linear search algorithm is to look through an array of data to find a particular item, x. The item, x, is compared to every item in the array from the first item to any stage where a match is found. If a match is not found then item x is not in the array and the solution is 0.

The Best and Worst Case for the Linear Search Algorithm
The Best Case for the linear search algorithm is when only one comparison is required between x and the array A[1], A[2],...A[n]. This occurs when x is the first term in the array.

The Worst Case occurs when algorithm requires n comparison. This occurs when x = A[n], or when x does not appear in the array.