Linear Search
Linear search is used to search a key element from multiple element.Sequential search is made over all items one by one.Linear search is less used today because it is slower than binary search and hashing.Linear search or sequential search is a method for finding a particular value in a list, that consists of checking every one of its elements, one at a time and in sequence, until the desired one is found. Linear search is the simplest search algorithm.Linear searches don’t require the collection to be sorted.
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 used to search a key element from multiple elements. Binary search is faster than linear search. In case of binary search, array elements must be in ascending order.
In case of binary search, array elements must be in ascending order. If you have unsorted array, you can sort the array using Arrays.sort(arr) method.
TIME COMPLEXITY
Time Complexity measures the time taken for running an algorithm and it is commonly used to count the number of elementary operations performed by the algorithm to improve the performance. Lets starts with simple example to understand the meaning of Time Complexity .
