Assume that the numList has seven elements [8, -4, 7, 17, 0, 2, 19] so, n = 7. We need to search for the key, say 17 in numList. Table 6.1 shows the elements in the given list along with their index values.
| Index in numList | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| Value | 8 | -4 | 7 | 17 | 0 | 2 | 19 |
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Linear Search checks each element of the list one by one from the start until the target is found or the list ends — it is the simplest search algorithm, requiring no pre-sorted data.
This is a plain theory question that asks you to explain the concept of Linear Search using the given example. The core idea is straightforward: when you have an unsorted list and need to find a specific value, you have no shortcuts — you must look at every element in order until you either find what you're looking for or run out of elements.
Why Linear Search is the right tool here. The list [8, -4, 7, 17, 0, 2, 19] is not sorted. If it were sorted, you could use Binary Search, which is much faster. But since the values are in arbitrary order, the only reliable method is to start at index 0 and move forward, comparing each element to the key (17). This is exactly what Linear Search does — it trades speed for simplicity and works on any list.
How the search proceeds for key = 17:
- Start at index 0: value is 8. Not equal to 17. Move to next.
- Index 1: value is -4. Not equal. Move on.
- Index 2: value is 7. Not equal. Move on.
- Index 3: value is 17. Match found. The search stops here.
The algorithm returns the index where the key was found, which is 3. If the key were not present (say we searched for 100), the search would go through all seven elements and then return a failure indicator, typically -1 or None. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.