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 / ranjit
Gianni, Your answer would be correct if the list was unordered. Since it is a sorted list (descending order), one does not have to go through the whole list in order to determine that the element is not present. Thus, the problem is to simply traverse the list until you find a number <= the number, x, you are looking for. This can be done with (n+1)/2 comparisons on average. Probability of x being present in the list is not a factor.
Shyam, as I explained in the above para, the fact that the list is sorted is relevant. If it was unsorted, Gianni would be absolutely right.
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What is difference between data type and data structure?
What is best time complexity?
What is circular queue in data structure?
How can we remove loops in a linked list? What are the functions of fast and slow pointers?
How remove all from arraylist?
What are examples of data structures?
Differentiate between collection and collections.
What does a treemap do?
How to reference all the elements in a one-dimension array?
Is array part of collection framework?
What is fibonacci search?
Where is data structure used?
Which language is best for data structures and algorithms?
Is int a data structure?
We know that Arrays are objects so why cannot we write strArray.length()?