If the key is the last element, how many comparisons does linear search make?
An comparisons
Btwo comparisons
Cfour comparisons
Dnine comparisons
Answer & Solution
Correct answer: A. n comparisons
1. Linear search stops only when it finds the key.
2. A key at the end is reached only after everything else.
3. If the key is the last element, linear search makes n comparisons.
4. Here n is the number of elements in the list.
_Source: syllabus Computer Science, Ch 5 'Sorting' and Ch 6 'Searching'_
Keep practising Sorting and Searching
Browse all Sorting and Searching questions for IGNOU MCA, or explore more Computer Science topics.