Friday 10 October 2014

Linear Search-sequential search in DATA STRUCTURE


Linear Search OR Sequential Search
In computer science, linear search or sequential search is a method for finding a particular value in a list, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found
Linear search is usually very simple to implement, and is practical when the list has only a few elements, or when performing a single search in an unordered list.
When many values have to be searched in the same list, it often pays to pre-process the list in order to use a faster method.
Linear searches don't require the collection to be sorted
For a list with n items, the best case is when the value is equal to the first element of the list, in which case only one comparison is needed.
The worst case is when the value is not in the list (or occurs only once at the end of the list), in which case n comparisons are needed.
 

0 comments:

Post a Comment