Forgot Password ?
New password will be sent to following email id
Discrete Binary Search
( Linear Search )
As the name suggests, search is an operation of finding an item from the given collection of items. <br><br> For example, consider an array <b>A</b> containing <b>N</b> elements and you need to find all the locations of an element <b>X</b>. The basic approach will be traverse all elements of the array and if current array element is equal to <b>X</b> than print the location (index) of current element. <br><br> This is exactly what <b>linear search</b> is all about. Linear search relies on the technique of traversing a list from start to end by exploring properties of all the elements that are found on the way. <br><br> Consider another example, there is an array <b>A</b> of <b>N</b> elements and you need to tell whether an element <b>X</b> is present in array <b>A</b> or not. Basic approach is to traverse array and compare each element of <b>A</b> with <b>X</b>. Time complexity of this approach is <b>O(N)</b> in worst case. Now consider if there are <b>M</b> queries and in each query you need to tell whether an element <b>X</b> is present in the array or not. If we use the above mentioned basic approach, time complexity will be <b>O(M × N)</b> which is quite high for larger values of <b>M</b> and <b>N</b>. <br><br> So here comes the existence of <b>binary search algorithm</b> which solves the above problem in an efficient way.