...
ER-Model
August 26, 2024
ER-Model
August 26, 2024

Searching

Question 2

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
Question 2 Explanation: 
Correct Answer: A
Question 2 Explanation: 
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!