GATE CS 2002 · Arrays & Matrix Representation

MCQ · 1 mark · Problem PROG-DSTR-0247

Consider the following algorithm for searching for a given number x in an unsorted array A[1.....n] having n distinct values :(1) Choose an i uniformly at random from [1....n](2) If A[i] = x then stop else Goto 1;Assuming that x is present A, What is the expected number of comparisons made by the algorithm before it terminates?
  1. A
    n
  2. B
    n-1
  3. C
    2n
  4. D
    n/2

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionOfficial GATE Answer Key: Option A.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/840/gate2002-2-10

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