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

Differentiate bfs and dfs?

561


How would you reverse the characters of an array?

528


How do you find the index of an element in an arraylist?

429


How do I rearrange rows in numbers?

459


What is a bubble sort and how do you perform it?

653






Why sorting is done?

492


Which interface treemap implements?

553


Differentiate between hashset and hashmap.

509


What is a Stack? Explain with example?

549


Can treeset contain null?

495


What is difference between static and dynamic array?

447


Tell me the difference between structure and array?

463


What does stack top do?

480


How do you represent a linked list?

503


What is data and its type?

484