Linear Search And Binary Search
Linear Search
linear search is a single search algorithm.In this type of search ,a sequential search is made over all items one by one.Every item is checked and if a match is found then that particular item is returned ,otherwise the search continues till the end of the data collection.The linear search is inefficient .If the array being searched is 20,000 elements,the algorithm will have to look at all 20,000 elements in order to find a value in the last element.In an average case ,an item is just as likely to be found near the beginning of the array as near the end.The maximum number of comparisons is always N.
TIME COMPLEXITY
The time complexity of linear search algorithm is O(n) where n is the number of elements in the target array, which shows its slower than binary search algorithm.
Binary Search
Binary search is a process of searching an element from sorted array by repeatedly dividing the search interval in half.Binary search is faster than linear search.Although binary search is a very optimised way of searching a particular element but the array must be sorted on which you want to perform the search process.
TIME COMPLEXITY
Its time complexity is O(log(N)). This time complexity is a marked improvement on the O(N) time complexity of Linear search.
