Skip to content
Exercises · Q2

Q.Use the linear search program to search the key with value 8 in the list having duplicate values such as [42, -2, 32, 8, 17, 19, 42, 13, 8, 44]. What is the position returned? What does this mean?

Goa GbshseTextbookSubjective· 3mImportance★★★★★
53% · 9/17 Questions
✓ Free question

Linear search returns the first occurrence of the key in the list. For the given list, the key 8 first appears at index 3 (0‑based), so the position returned is 3.

This is a plain theory question that asks you to trace a linear search on a list with duplicates. The core idea is simple: linear search scans from left to right and stops as soon as it finds a match. It does not continue looking for later duplicates.

Let’s walk through the list step by step. The list is:

[42, -2, 32, 8, 17, 19, 42, 13, 8, 44]

We are searching for the key 8. The algorithm starts at index 0 and checks each element in order.

IndexElementMatch?Action
042NoContinue
1-2NoContinue
232NoContinue
38YesReturn index 3

The search stops immediately at index 3. It never reaches the second 8 at index 8.

Watch out

A common mistake is to think linear search returns the last occurrence or all occurrences. It does not — it returns only the first match. If you need all positions, you must modify the algorithm to keep scanning and collect indices.

What does this mean?

The returned position 3 tells us that the key 8 is present in the list, and its first appearance is at index 3 (0‑based). In 1‑based terms (if the question expects that), it would be position 4. But standard programming uses 0‑based indexing, so the answer is 3.

✓Final answer

The position returned is 3 (0‑based index), meaning the first occurrence of the key 8 is at the fourth element of the list.

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.