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 is the biggest advantage of linked lists?
How can I study data structures and algorithms?
What is an ordered list?
What is sorted map?
What is the difference between hashset and hashtable?
How do I sort hashset?
How expression trees are gets represented in data structure?
What is the minimum number of queues that can be used to implement a priority queue?
What are the advantages of selecetion sort?
Difference between arraylist and linkedlist?
Are sets sorted?
What is meant by linked list?
How can you insert a node at the end of linked list?
What is the use of data structure?
What can be stored in an arraylist?