Searching
Searching
Searching Techniques
Sequential Search
Sequential search is also called as Linear Search.
Sequential search starts at the beginning of the list and checks every element of the list.
It is a basic and simple search algorithm.
Sequential search compares the element with all the other elements given in the list. If
the element is matched, it returns the value index, else it returns -1.
The above figure shows how sequential search works. It searches an element or value
from an array till the desired element or value is not found. If we search the element
25, it will go step by step in a sequence order. It searches in a sequence order. Sequential
search is applied on the unsorted or unordered list when there are fewer elements in a
list.
Linear search is implemented using following steps...
Example
Consider the following list of elements and the element to be searched...
Binary Search
The above array is sorted in ascending order. As we know binary search is applied on
sorted lists only for fast searching.