In computer science, a binary search or half-interval search algorithm finds the position of a target value within a sorted array.
- Binary search can interact poorly with the memory hierarchy (i.e. caching), because of its
- For in-memory searching, if the interval to be searching is small, a linear search may have superior performance simply because it exhibits better locality of reference.
- Binary search algorithm employs recursive approach and this approach requires more stack space.
- Programming binary search algorithm is very difficult and error prone
In computer science, linear search or sequential search is a method for finding a particular value in a list that checks each element in sequence until the desired element is found or the list is exhausted. The list need not be ordered.
Linear search is usually very simple to implement, and is practical when the list has only a few elements, or when performing a single search in an unordered list. When many values have to be searched in the same list, it often pays to pre-process the list in order to use a faster method. For example, one may sort the list and use binary search, or build any efficient search data structure from it. Should the content of the list change frequently, repeated re-organization may be more trouble than it is worth.
Source by: penjee.com