What is the average number of comparisons in a sequential search




















Correct me if m wrong. First consider smaller example So first you will visit first element and compare it with '2'. If it is '2' then your search will end at first element with only 1 comparison.

But if it is not equal to '2',then you compare it with second element. Now since our list is not sorted so it can be anything e.

Now consider our list containing 'n' elements. So avg. Shashank Kumar answered Jan 3, Should be added as best answer :. Searching an element in an array, the search starts from the first element till the last element. If the element is in the 1st position, the number of comparisons will be 1 and if the element is in the last position, the number of comparisons will be N. Sambhrant Maurya answered Aug 1, Jyotish Ranjan answered Apr Since it is a linear search we can find the element in any of the k position for a successful search.

Can you please explain ur logic. Next Qn. Answer: C. Related questions 28 votes. Kathleen asked in CO and Architecture Oct 9, Kathleen asked in Algorithms Oct 10, The program is erroneous. Under what conditions does the program fail? N] of integer; begin i Discussion Forum. The average number of key comparisons done in successful sequential search in a list of length n is Confused About the Answer? Ask for Details Here Know Explanation? Similar Questions:.

Hashing collision resolution techniques are:. Suppose we have a O n time algorithm that finds median of an unsorted array. Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot. Because:If elements is in 1st position no of cpmparision will be one and if the element is in the last position then no of comparisions will be N.

The element may be found at any place in the array. Supposing that the element is in 1st position, no. Given the same list and a target value of 90, the algorithm would be forced to examine all eight items to determine that this target does not occur anywhere in the list.

In the previous paragraph, we looked at the behavior of sequential search on a specific list of eight numbers given several different target values. Such a description would allow us to predict the average number of comparisons required to find an arbitrary key given only the size of the list instead of the actual values. Sequential search for the value To begin with, if the target item is not in the list, it will be necessary to look through the entire list to verify this fact.

Now, what if the item is in the list? How many comparisons would be required to find the item? Well, as the above example with eight items showed, it varies. Sometimes the target item will be right at the beginning of the list, so only one comparison is needed to find it.



0コメント

  • 1000 / 1000