Linear search
Sequentially looking in an array / From Wikipedia, the free encyclopedia
Dear Wikiwand AI, let's keep it short by simply answering these key questions:
Can you list the top facts and stats about Linear search?
Summarize this article for a 10 years old
In computer science, linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched.[1]
Class | Search algorithm |
---|---|
Worst-case performance | O(n) |
Best-case performance | O(1) |
Average performance | O(n) |
Worst-case space complexity | O(1) iterative |
Optimal | Yes |
A linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list. If each element is equally likely to be searched, then linear search has an average case of n+1/2 comparisons, but the average case can be affected if the search probabilities for each element vary. Linear search is rarely practical because other search algorithms and schemes, such as the binary search algorithm and hash tables, allow significantly faster searching for all but short lists.[2]
Oops something went wrong: