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
What is the time complexity of Linear Search in the worst case?
The worst-case time complexity is O(n), where n is the number of items in the list.
Click to reveal answer
intermediate
In which scenario is Linear Search preferred over other search algorithms?
When the list is small or unsorted, Linear Search is simple and effective without extra setup.
Click to reveal answer
beginner
What does Linear Search return if the target is not found in the list?
It returns -1 or a special value indicating the target is not present.
Click to reveal answer
beginner
Show a simple TypeScript code snippet for Linear Search.
function linearSearch(arr: number[], target: number): number {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === target) {
return i;
}
}
return -1;
}Click to reveal answer
What does Linear Search do when it finds the target element?
✗ Incorrect
Linear Search stops immediately and returns the index when it finds the target.
What is the best case time complexity of Linear Search?
✗ Incorrect
Best case is when the target is the first element, so it takes constant time O(1).
Which of these lists is Linear Search most suitable for?
✗ Incorrect
Linear Search works well on small or unsorted lists where other methods add overhead.
If the target is not in the list, what does Linear Search return?
✗ Incorrect
Linear Search returns -1 to indicate the target was not found.
How does Linear Search check elements in the list?
✗ Incorrect
Linear Search checks each element one by one from the start to the end.
Explain how Linear Search works step-by-step on a list of numbers.
Think about looking for a name in a phone book by checking every entry.
You got /4 concepts.
Describe when you would choose Linear Search over other search methods.
Consider situations where sorting or complex structures are not worth the effort.
You got /4 concepts.