0
$\begingroup$

In a list of 15 entries (city names) if searching for a particular name what is the average number of comparisons using linear search? Worst case it would 15 comparisons and best case it would be 1 comparison. Is the following calculation the average number of comparisons? If not, how do I calculate the average? Thank you.

(15 + 14 +13+ 12 + 11 + 10 + 9 + 8 +7 +6 +5 +4 + 3+ 2+ 1) / 15 = 8

$\endgroup$
2
  • $\begingroup$ I wrote analysis in details on cs.stackexchange.com/questions/129614/… does this help? $\endgroup$
    – zkutch
    Oct 17 '20 at 12:03
  • $\begingroup$ 15 entries: how many different names? What part of searches shall be expected to yield not in this list? $\endgroup$
    – greybeard
    Oct 17 '20 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.