Recall & Review
beginner
What is the main idea behind the Linear Search Algorithm?
Linear Search checks each item in a list one by one until it finds the target or reaches the end.
Click to reveal answer
beginner
How does Linear Search behave if the target is not in the list?
It checks every item and ends after the last one, returning a result that the target was not found.
Click to reveal answer
intermediate
What is the time complexity of Linear Search in the worst case?
The time complexity is O(n), where n is the number of items in the list, because it may check all items.
Click to reveal answer
beginner
Show a simple JavaScript code snippet for Linear Search.
function linearSearch(arr, target) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === target) {
return i;
}
}
return -1;
}Click to reveal answer
beginner
Why is Linear Search not efficient for large lists?
Because it checks each item one by one, it can take a long time if the list is very big.
Click to reveal answer
What does Linear Search do when it finds the target in the list?
✗ Incorrect
Linear Search stops as soon as it finds the target and returns its position.
What is the worst-case time complexity of Linear Search?
✗ Incorrect
In the worst case, Linear Search checks every item, so it takes O(n) time.
If the target is not in the list, what does Linear Search return in the example code?
✗ Incorrect
The example code returns -1 to indicate the target was not found.
Which of these is a key characteristic of Linear Search?
✗ Incorrect
Linear Search checks each item one by one without needing the list to be sorted.
Which data structure is Linear Search best suited for?
✗ Incorrect
Linear Search works well on unsorted lists or arrays where no order is guaranteed.
Explain how Linear Search works step-by-step on a list of numbers.
Think about looking for a name in a list by checking one by one.
You got /4 concepts.
Describe the advantages and disadvantages of using Linear Search.
Consider when it is easy to use and when it might be slow.
You got /4 concepts.