Google News
logo
CPP - Interview Questions
What is searching? Explain linear and binary search.
Finding the location of a given element in a given data structure is called searching.
 
There are two types of search :
 
1. Linear Search : In this, the element to be searched is compared one by one with each element of given list, starting with first element. The process of comparisons remain continue until the element is not found or list gets exhausted.
 
2. Binary Search : It is another technique of searching an element in a given list in minimum possible comparisons. But for applying binary search on a list, there are two pre-conditions :

     (i)  The elements of list must be arranged either in ascending or descending order.
     (ii) The list must be of finite size and should be in form of linear array.
Advertisement