

Looking through all of the items to report that the item was not found. In this case, the algorithm does not have to continue Not only is 54 not the item we are looking for, but no other elements beyond 54 can work either since the list is sorted. At this point, however, we know something extra. Figure 2 shows this process as the algorithm looks for the item 50. However, if the item is not present there is a slight advantage. We will still have the same number of comparisons to find the item. If the item we are looking for is present in the list, the chance of it being in any one of the n positions is still the same as before. What would happen to the sequential search if the items were ordered in some way? Would we be able to gain any efficiencyĪssume that the list of items was constructed so that the items were in ascending order, from low to high. We assumed earlier that the items in our collection had been randomly placed so that there is no relative order between the items. Table 1: Comparisons Used in a Sequential Search of an Unordered List Recall, however, that as n gets large, the coefficients, no matter what they are, become insignificant in our approximation, so the complexity of the sequential search, is O (n).

What about the average case? On average, we will find the item about halfway into the list that is, we will compare against n2 items. In the worst case, we will not discover the item until the very last comparison, the nth comparison. Place we look, at the beginning of the list. The block should accept a word to search for and a list of words as input, and return the. In the best case we will find the item in the first 1) Sequential search: Implement the block: find in unsorted list. There are actually three different scenarios that can occur. In the case where the item is in the list, the analysis is not so straightforward. If there are n items, then the sequential search requires n comparisons to discover that the item is not there. If the item is not in the list, the only way to know it is to compare it against every item present.
