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


Please Help Members By Posting Answers For Below Questions

Is array a dynamic data structure?

494


What is the complexity of arraylist?

474


Why quicksort is called quick?

494


What does arraylist remove return?

446


Tell me what should be done in the base case for this recursive problem?

472






Can you store different types in an array?

458


What is insertion sort technique?

479


Can you have an arraylist of arrays?

504


Define right-in threaded tree?

540


What is the difference between hashset and arraylist?

470


How does hashset work internally in java?

501


Define graph?

720


What happens if we put a key object in a hashmap which exists?

475


What is mean by sorting?

500


What is hashing technique?

530