I am given a sequential algorithm that does a routine search
on an unordered list. N = 20.
The probability that the value x does NOT appear in the list
is exactly 60%, and the probability that x DOES appear is 40%.
The 3 questions that I could not get were:
A) What is the avg number of element comparisons performed
when n = 20 and x does NOT appear in the List.
(my answer was 20, is this correct?)
B) What is the avg number of element comparisons peformed
when n = 20 and x DOES appear in the list?
C) What is the avg number of element comparisons performed
when n = 20. This should be a single number answer they said.
Answer Posted / ranjit
The second answer is partially correct.
a) 20. It will take 20 comparisons to determine that x does not appear in the unordered list of size N.
b) Assuming that x is equally likely to be in any of the 20 positions in the list, the average number of comparisons will be (1 + 2 + ... + 20)/20 = 10.5.
c) 20*0.6 + 10.5*0.4 = 16.2
| Is This Answer Correct ? | 9 Yes | 0 No |
Post New Answer View All Answers
Which sorting algorithm has minimum number of swaps?
Explain what do you mean by insertion sort, bubble sort and selection sort? Also, explain the differences among the functionalities of the three sorts.
Is array a collection?
What is the minimum number of queues that can be used to implement a priority queue?
What does bubble sort do?
What is array and its types with example?
Why quicksort is better than merge sort?
What is an recursive algorithm?
Can we add elements to final list?
What are the disadvantages of circular list?
What are arrays used for?
What are doubly linked lists?
What is the two-dimensional array?
Is arraylist a class?
What are red-black trees?