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
beginner
Show the basic steps of Linear Search in simple terms.
1. Start from the first item. 2. Compare it with the target. 3. If it matches, stop and return the position. 4. If not, move to the next item. 5. Repeat until found or list ends.
Click to reveal answer
intermediate
Why is Linear Search not efficient for large lists?
Because it checks every item one by one, it can take a long time if the list is big or the target is near the end or missing.
Click to reveal answer
beginner
Can Linear Search be used on unsorted lists? Why or why not?
Yes, Linear Search works on unsorted lists because it checks each item without assuming any order.
Click to reveal answer
What does Linear Search do when it finds the target element?
ADeletes the element
BContinues searching the rest of the list
CSorts the list
DStops and returns the position
✗ Incorrect
Linear Search stops immediately when it finds the target and returns its position.
What is the best case time complexity of Linear Search?
AO(log n)
BO(n)
CO(1)
DO(n^2)
✗ Incorrect
If the target is the first element, Linear Search finds it immediately, so best case is O(1).
Which of these lists can Linear Search be applied to?
AOnly unsorted lists
BBoth sorted and unsorted lists
COnly sorted lists
DOnly lists with unique elements
✗ Incorrect
Linear Search works on any list, sorted or unsorted, because it checks each element one by one.
If a list has 100 elements and the target is not present, how many checks does Linear Search do?
A100
B1
C50
D0
✗ Incorrect
Linear Search checks every element until the end if the target is not found, so 100 checks.
Which of these is NOT a step in Linear Search?
ADivide the list into halves
BMove to next element if no match
CStop when target is found
DCompare current element with target
✗ Incorrect
Dividing the list into halves is part of Binary Search, not Linear Search.
Explain how Linear Search works step-by-step on a list.
Think about checking each item one by one.
You got /5 concepts.
Describe when Linear Search is a good choice and when it is not.
Consider list size and order.
You got /4 concepts.
Practice
(1/5)
1. What is the main idea behind the Linear Search Algorithm?
easy
A. Check each element one by one until the target is found or list ends
B. Divide the list into halves repeatedly to find the target
C. Sort the list first then search using binary method
D. Use a hash table to find the target instantly
Solution
Step 1: Understand linear search process
Linear search checks each element in order from start to end.
Step 2: Compare with other search methods
Other methods like binary search divide the list, but linear search does not.
Final Answer:
Check each element one by one until the target is found or list ends -> Option A
Quick Check:
Linear search = check elements one by one [OK]
Hint: Linear search checks elements one by one [OK]
Common Mistakes:
Confusing linear search with binary search
Thinking linear search requires sorted list
Assuming instant search with hash tables
2. Which of the following is the correct syntax to start a linear search loop in C for an array arr of size n?
easy
A. for (int i = 0; i < n; i++)
B. for (int i = 0; i <= n; i++)
C. for (int i = 1; i < n; i++)
D. for (int i = 1; i <= n; i++)
Solution
Step 1: Understand array indexing in C
Arrays in C start at index 0 and go up to n-1 for size n.
Step 2: Choose correct loop condition
The loop should run from 0 to less than n, so i < n is correct.
Final Answer:
for (int i = 0; i < n; i++) -> Option A
Quick Check:
Loop from 0 to n-1 = for(i=0; i<n; i++) [OK]
Hint: Array index starts at 0, loop till i < n [OK]
Common Mistakes:
Using <= n causes out-of-bounds access
Starting loop at 1 misses first element
Confusing array size with last index
3. What will be the output of the following C code?
int arr[] = {4, 2, 7, 1, 9};
int n = 5;
int target = 7;
int index = -1;
for (int i = 0; i < n; i++) {
if (arr[i] == target) {
index = i;
break;
}
}
printf("%d", index);
Hint: Stop loop when target found, print index [OK]
Common Mistakes:
Printing value instead of index
Not breaking loop and printing last index
Confusing index with element value
4. Find the error in this linear search code snippet in C:
int linearSearch(int arr[], int n, int target) {
for (int i = 1; i <= n; i++) {
if (arr[i] == target) {
return i;
}
}
return -1;
}
medium
A. The array parameter should be a pointer, not an array
B. The function should return the element, not the index
C. The return -1 should be inside the loop
D. Loop starts at 1 and goes to <= n, causing out-of-bounds access
Solution
Step 1: Check loop indexing for array access
Array indices in C start at 0 and go to n-1, but loop starts at 1 and goes to n, causing out-of-bounds at arr[n].
Step 2: Identify correct loop bounds
Loop should start at 0 and run while i < n to avoid invalid access.
Final Answer:
Loop starts at 1 and goes to <= n, causing out-of-bounds access -> Option D
Quick Check:
Array index out-of-bounds due to wrong loop limits [OK]
Hint: Array index starts at 0, loop i < n [OK]
Common Mistakes:
Starting loop at 1 instead of 0
Using <= n instead of < n in loop condition
Returning element instead of index
5. You have an unsorted array arr with 10 elements where some elements repeat. You want to find the first occurrence index of the number 5 using linear search. Which approach is best to handle duplicates and return the correct index?
hard
A. Sort the array first, then use binary search to find 5
B. Traverse entire array, count all 5s, then return last index of 5
C. Traverse from start to end, return index immediately when 5 is found
D. Use a hash map to store counts, then find index of 5
Solution
Step 1: Understand requirement for first occurrence
We want the first index where 5 appears, so searching from start is needed.
Step 2: Choose approach that stops at first match
Linear search that returns immediately on first 5 found gives correct first occurrence index.
Final Answer:
Traverse from start to end, return index immediately when 5 is found -> Option C
Quick Check:
Stop at first match to get first occurrence [OK]
Hint: Return index immediately on first match [OK]
Common Mistakes:
Counting all occurrences then returning last index
Sorting changes original order, losing first occurrence
Using hash map adds unnecessary complexity
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.