The element being searched for is not found in an array of
100 elements. What is the average number of comparisons
needed in a sequential search to determine that the element
is not there, if the elements are completely unordered?
Answer Posted / tek002
The question is asking for the average number of
comparisons, not the particular realization... On average
you need 50 comparisons since the element you are searching
could just as likely be at the end of the array, as in the
beginning of the array. (for a brute force sequential
search)
If you really want to be fancy, you can actually do it with
10 (sqrt(N)) steps. Since a comparison search is an oracle
based search, you can implement the Grover's Algorithm
which is a unsorted database searching algorithm which is
the best known oracle based search for unsorted databases
(in fact is is provably the best oracle based search for
unsorted arrays).
| Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
What is the need of sorting?
Why quicksort is called quick?
What is the difference between null and void?
What is sorted map?
Define right-in threaded tree?
What are linked list?
What are linear and non linear data structures?
What are stacks? Give some of its applications.
How to create your own data structure in java?
What is difference between list and array?
Which sorting is best and why?
What are the major data structures used in the hierarchical data model?
How to search binary in a sorted array?
What is complete binary tree in data structure?
Provide an algorithm to reverse a linked list without using recursion.