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
2
Q
What is the best-case time complexity for linear search?
A
O(1)
3
Q
What is the worst-case time complexity for the linear search?
A
O(n)
4
Q
Does linear search work well with unsorted lists?
A
yes!
5
Q
Linear search is inefficient when the list is already ________
A
sorted