Searching algorithms Flashcards

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

When to use linear search?

A

unordered list

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

When to use binary search?

A

ordered list

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

Define linear search

A

process sequentially through an unordered list

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

Best case of linear search

A

O(1)

first element in list

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

Worst case of linear search

A

O(n)

last element in list

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

Define binary search

A

calculates midpoints in an ordered list of items to find the required element

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

best case of binary search

A

element in the middle of the list

O(1)

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

worst case of binary search

A

element is found in last comparison

O(logn + 1)

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

average case of binary search

A

O(logn)

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

advantages of binary search

A
  • much more efficient, as it only focuses on one half of the list
  • worst case is still shorter than linear worst case
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

disadvantages of binary search

A

only works on ordered lists

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