retagged by
886 views
1 votes
1 votes

retagged by

2 Answers

2 votes
2 votes
let X be a random variable denoting number of comparisons made by the algorithm before terminates.

total number of permutations possible using the numbers present in the array = $\frac{5!}{2!}$ = 60(as x presents 2 times.and assume that other numbers are not repeated)

so, p(X=1)=$\frac{4!}{60}$=$\frac{24}{60}$

p(X=2)=$\frac{3*1*3!}{60}$=$\frac{18}{60}$

p(X=3)=$\frac{3*2*1*2!}{60}$=$\frac{12}{60}$

p(X=4)=$\frac{3!*1}{60}$=$\frac{6}{60}$

so expected no of comparisons=1*$\frac{24}{60}$+2*$\frac{18}{60}$+3*$\frac{12}{60}$+4*$\frac{6}{60}$

                                                        =2
reshown by
0 votes
0 votes
In the worst case , it will require Atmost 4 comparisons to as x is present 2 times already in the worst case it will be at (n-1)th and nth position int the array !!

Related questions

2 votes
2 votes
1 answer
1
0 votes
0 votes
0 answers
3
S Ram asked Feb 1, 2017
324 views
can someone provide me the detailed description for this answer?