• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE | GATE-CS-2002 | Question 35

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 in A, what is the expected number of comparisons made by the algorithm before it terminates ?

(A)

n

(B)

n - 1

(C)

2n

(D)

n/2

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments