What is the average number of comparisons needed in a
sequential search to determine the position of an element in
an array of 100 elements, if the elements are ordered from
largest to smallest?

Answer Posted / nilavalagan

The element may be found at any place in the array.

Supposing that the element is in 1st position, no.of comparison = 1;
Element is in 2nd position, no.of comparison = 2;

In the same way,
for the element present in 100th positionn no.of comparison = 100;

Total no.of comparison = 1+2+3+....+100

Average no.of comparison = (1+2+3+..+100)/100

= (100*101)/2*100
(Remember n(n+1)/2)
=101/2 = 50.5

In general = (n+1)/2; if there are n elements.

Is This Answer Correct ?    15 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is the parent class of enumset class?

553


What is a matrix? Explain its uses with an example

566


What is array traversing?

462


How does max heap work?

486


Why heap sort is not used?

474






Is linkedlist thread safe?

455


What do you mean by 2-3 tree?

505


What do you mean by sorting?

447


How hashmap increases its size?

570


Which sorting algorithms are in place?

485


How does the bubble sort work?

493


Is radix sort stable?

494


Can you change size of array once created?

444


Which is better hashset or treeset?

488


What is the difference between collections class vs collections interface?

523