Monday 14 December 2015

Q24,P2,J15. .The average case occurs in the linear search algorithm when.

A) The item is searched is in some where middle of array.
B) The item to be searched is not in array.
C) The item is to be searched is in the last of array.
D) The item to be searched is either in the last or not in the array.

Answer A.
Explanation.
 let there are n elements to be searched linearly.
1st element will take 1 search.
2nd element will take 2 search.
--
--
n th element will take n search.

Average search will take. (1+2+3-----n)/n
= n(n+1)/2n  hence approximately  n/2.
when  item is not there it will search whole list.
last element will take n search  time.
Hence option A is the correct

No comments:

Post a Comment

Note: only a member of this blog may post a comment.