Searching and Sorting 567
Searching is a technique of finding accurate location of an element in the given data list or set of the
elements like an array, list, or trees. For example, consider an array of 10 elements. These data
elements are stored in successive memory locations. We need to search an element from the array.
In the searching operation, if we want to find a particular element says n, the n is compared with
all the elements and when the exact match is found then the search process is terminated. In case,
no such element exists in the array, the entire array is searched.
If the given element is present in the collection of elements or array then the search process is
said to be successful as per Fig. 16.1. It means that the given element belongs to the array. The
search is said to be unsuccessful if the given element does not exist in the array as per Fig. 16.2. It
means that the given element does not belong to the array or collection of the items.
Fig. 16.1 Successful search
Fig. 16.2 Unsuccessful search
The complexity of any searching method is determined from the number of comparisons among
collected elements in order to find the element. The time required for the operation is dependent
on the complexity of the operation or algorithm.