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
Does hashset maintain order?
What are the applications of stack?
Why do we use different types of data structures?
What is shell sort in data structure?
What do you mean by open addressing?
Which is faster array or list?
Does arraylist allow null values?
What is dangling pointer and how to avoid it?
What is the time complexity of hashmap get () and put () method?
Is map a data structure?
Why might quick sort might be better than merge sort?
Traverse the given tree using Inorder, Preorder and Postorder traversals. Inorder : D H B E A F C I G J Preorder: A B D H E C F G I J Postorder: H D E B F I J G C A
Is hashmap keyset ordered?
How to copy an array into another array?
Differentiate among cycle, path, and circuit?