UGC-NET Jun 2015 · Linear Search & Binary Search

MCQ · 2 marks · Problem PROG-SRCH-0004

The average case occurs in Linear Search Algorithm when
  1. A
    The item to be searched is in some where middle of the Array
  2. B
    The item to be searched is not in the array
  3. C
    The item to be searched is in the last of t he array
  4. D
    The item to be searched is either in the last or not in the array

Solve it on GATE DA practice →More Searching & Sorting Algorithms problems

Show the worked solutionLinear search compares the key with the elements one by one. If the item is equally likely to be at any of the \(n\) positions, the expected number of comparisons is\[\frac{1+2+\cdots+n}{n}=\frac{n+1}{2},\]which is what happens when the item is around the middle of the array.(B), (C), (D) Item at the end or absent needs \(n\) comparisons — that is the worst case, not the average.Answer: A

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com