2 13 LINEAR AND BINARY SEARCH COMPARISON BINARY
2 -13 LINEAR AND BINARY SEARCH COMPARISON
BINARY SEARCH VS LINEAR SEARCH • >Linear >Binary -Is also know as the sequential search -use a method to locate specific values -Searches for a specific value -method halves the number of elements checked -checks every element in the list -reduce the time taken to locate an item
LINEAR SEARCH -Linear search ( Sequential Search) is the most fundamental and important of all algorithms. It is simple to understand implement, yet there are more subtleties to it than most programmers realize. It's the most obvious search algorithm: going through a list or array one element at a time, in order. It isn't terribly efficient. However, if the search space doesn't have any additional structure--i. e. it can be completely random--then it's also the best you can do in general.
BINARY SEARCH • Binary search is an efficient algorithm for finding an item from an ordered list of items. It works by repeatedly dividing in half the portion of the list that could contain the item, until you've narrowed down the possible locations to just one.
DIFFERENCES • A linear search looks down a list, one item at a time, without jumping. The time taken to search the list gets bigger at the same rate as the list does. • A binary search is when you start with the middle of a sorted list, and see whether that's greater than or less than the value you're looking for, which determines whether the value is in the first or second half of the list. Jump to the half way through the sublist, and compare again etc. In complexity terms search - the number of search operations grows more slowly than the list does, because you're halving the "search space" with each operation. •
- Slides: 5