Revised Search Algorithm
Updated a GitHub repository
#Day15 #100DaysOfCode
linear search is rarely used because it is comparatively slower than other searching method.
starting from the leftmost position of the array, traverse till the end of the array, stops when the element is found, returns its index. otherwise returns -1.
time complexity is O(n)
binary search. only works for sorted array. there are two methods: iterative and recursive. always find the element at the middle portion of the array.
starting from the middle position. if x is larger than a[mid], find x in the right hand side of a[mid]. if x is smaller than a[mid], find x in the left hand side of a[mid].
time complexity O(logn)
binary search only works for arrays, not linked lists.