Searching algorithms Flashcards
What is a linear search?
the simplest searching algorithm
Starting at the beginning of the data set, each item of data is examined until a match is made. Once the item is found, the search ends.
What is a binary search?
starts at the middle of the list
if the value at the middle point is less than the value to be found, the lower half of the list is ignored and the upper half is searched
if the value at the middle is greater than the value to be found, the upper half is ignored and the lower part is searched
search moves to the middle of the remaining items and repeats until the item is found
Why is a binary search more efficient than a linear search?
a binary search would require less steps to find the value
eg. if you were looking for 99/100, a liner search would take 99 steps but a binary would only take 7
What is a downside of a binary search?
it only works if the list is ordered