Linear Search
Linear Search
OUTCOMES
Linear search Algorithm
Complexity analysis
Binary search normal description
Linear search
A linear search is the basic and simple search algorithm.
A linear search searches an element or value from an array till
the desired element or value is not found and it searches in a
sequence order.
It compares the element with all the other elements given in the
list and if the element is matched it returns the value index else
it return -1.
Linear Search is applied on the unsorted or unordered list when
there are fewer elements in a list.
Complexity
O(n)
Binary search
Binary Search: Search a sorted array by repeatedly dividing the search
interval in half. Begin with an interval covering the whole array.
If the value of the search key is less than the item in the middle of the
interval, narrow the interval to the lower half.
Otherwise narrow it to the upper half. Repeatedly check until the value
is found or the interval is empty.
complexity
O(log n)
For an array of size N, it eliminates until 1 element
remains. N, N/2, N/4, N/8, ..., 4, 2, 1 How many divisions
does it take?
0->N
1->N/2
Queries??