Given a list L=[5,6,75,85,95]
If we need to search for the element 85, then how many comparisons will it make to find the element using linear search?
Given a list L=[5,6,75,85,95]
If we need to search for the element 85, then how many comparisons will it make to find the element using linear search?
Solution
Linear search checks elements one by one from the start of the list until it finds a match. It compares 85 with 5, 6, 75 and then 85, so the search stops at the 4th element after 4 comparisons.
Option 2: 3 is the index of 85 (counting from 0), but the number of comparisons is the position, which is index + 1.
Option 4: 5 is the length of the list, which is the worst-case count. The search stops as soon as 85 is found, so 95 is never compared.
Related questions:
2026: 26 May Shift 1
2025: 14 May Shift 1
2026: 29 May Shift 2
2025: 14 May Shift 1
2026: 11 May Shift 2