2.1 Comparing linear and binary searches Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

binary search vs linear search

A

binary search is more efficient but the list has to be sorted

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

best case scenario for linear and binary

A

linear: the search item is the first one (1 selection)
binary: the search item is the median (1 selection)

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

worst case

A

linear: the search item is the last one (e.g. 500 with 500 selections)
binary: the search item is the last median selected (e.g. 10 selections in a list going up to 500)

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

average case

A

linear: 500 + 1/2 = 250.5

(251 selections)

binary: 9 + 1/2 = 5

(6 selections)

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

Describe one benefit and one drawback of using a binary search rather than a linear search [4]

A

a benefit of the binary search is that it uses a strategy to minimise the number of comparisons that are made and is therefore more effective than a linear search when there are a lot of items in a list

a drawback of using the binary search is that the list has to be ordered
sorting the data will take time and reduce the overall efficiency

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

A student has the following names of friends stored in a list.

Alice, Ann, Claire, David, Mary, Matt, Peter, Stephen, Zoe

Show the stages of a binary search to find the name Ann in the above data [2]

A

the median item is ‘Mary’

the sub list to the left is selected

the median of this list is Ann, which is the search item

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