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
Is hashmap synchronized?
What is the structure of an array?
Which sorting algorithms are in place?
Can list contain null values?
Give a good data structure for having n queues ( n not fixed) in a finite memory segment. You can have some data-structure separate for each queue. Try to use at least 90% of the memory space.
Can we sort hashmap?
What is sorting explain?
What is difference between hashmap and treemap?
What is the difference between a stack and an array?
What is hashing in cyber security?
What is a Queue? Explain its operation with example?
How do you sort a collection in descending order?
What are linked lists used for?
What do you mean by Logical Error
Explain implementation of traversal of a binary tree.