What is the average number of comparisons needed in a
sequential search to determine the position of an element in
an array of 100 elements, if the elements are ordered from
largest to smallest?
Answer Posted / gianni
the above answer of n+1/2 is correct if you assume it will
always be a successful search. you also need to take into
account the probability of the item NOT being in the list.
as such your final formula is actually
p/n * n(n+1)/2 + n(1-p) where p is the probability that the
item is in the list. That formula can be reduced ton(1-p/2)+p/2
assuming a probability of .5, you wind up with an answer of
(3n+1)/4 or ~3/4 of the list will be searched on average.
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What should be done in the base case for this recursive problem?
Give a real time example of stack
What you mean by sorting?
What is numeric array?
In what scenario, binary search can be used?
Why is bubble sort stable?
Tell me what should be done in the base case for this recursive problem?
What is a priority queue?
Can arraylist be empty?
What are the basic operations of stack?
What are some of the best practices relating to the java collection framework?
Will it create any problem if we add elements with key as user defined object into the treemap?
Is arraylist reference type?
What is peep stack?
Is a hashmap a dictionary?