Linear Search Flashcards

1
Q

For the mechanism of linear search:
1) start at the _____ element of the list
2) compare the _____ element with the _____ value
3) If they match, _____ the index of the element
4) If they don’t match, ______ to the next element
5) Repeat steps ___ through _____ until the target is found or the list ends.

A

1) first
2) current, target
3) move
4) 2-4

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

What is the best-case time complexity for linear search?

A

O(1)

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

What is the worst-case time complexity for the linear search?

A

O(n)

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

Does linear search work well with unsorted lists?

A

yes!

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

Linear search is inefficient when the list is already ________

A

sorted

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