Searching in Array
Searching in Array
To locate a particular item or element in an array is called search. Suppose a specific (info) information is given in an array. Searching refers to the operation of finding the location of info in an array and displaying an appropriate message. The search is said to be successful, if info appears, in the array else it is known as unsuccessful search.
- Linear Search
- Binary Search
Linear Search :
In linear search, each element of an array element is compared one-by-one with the given ITEM to be searched. Unit either desired element is found or the end of the list is reached. This method, which traverses the array sequentially to locate the given ITEM is called linear search.
Binary Search :
If you want to locate an item in an ordered list for a particular number then, this can be done efficiently by using a binary search. This is a searching technique in which each comparison either locates an item for the target value or divides the remaining list in half. Because the array (list) is in the order (ascending or descending), it will only be necessary to repeat this process on one of the two segments, thereby reducing the remaining search operation very rapidly.