Searching algorithms Flashcards

1
Q

What is a linear search?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a binary search?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is a binary search more efficient than a linear search?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a downside of a binary search?

A

it only works if the list is ordered

How well did you know this?
1
Not at all
2
3
4
5
Perfectly