rằng loại chèn sẽ làm là hơn . Một vấn đề đòi hỏi một phút thời gian máy tính sử dụng sắp xếp chèn có thể sẽ yêu cầu chỉ một Mergesort sử dụng hoặc hai thứ hai. Sự xuất hiện của biểu n lg n trong tính toán trước đó không có nghĩa là tình cờ, nhưng liên quan chặt chẽ với các giới hạn thấp hơn được thành lập trong 8,5 mục, | 276 Chapter 7 Searching int list_size if searches 0 list_size 0 cout Exiting test endl The number of searches must be positive. endl The number of list entries must exceed 0. endl return int i target found_at Key comparisons 0 Random number Timer clock for i 0 i searches i target 2 0 list_size - 1 1 if sequential_search the_list target found_at not_present cout Error Failed to find expected target target endl print_out Successful Key comparisons searches Key comparisons 0 for i 0 i searches i target 2 0 list_size if sequential_search the_list target found_at success cout Error Found unexpected target target at found_at endl print_out Unsuccessful Key comparisons searches The details of embedding this function into a working program and writing the output function print_out are left as a project. Exercises E1. One good check for any algorithm is to see what it does in extreme cases. Determine what sequential search does when a there is only one item in the list. b the list is empty. c the list is full. E2. Trace sequential search as it searches for each of the keys present in a list containing three items. Determine how many comparisons are made and thereby check the formula for the average number of comparisons for a successful search. Section Sequential Search 277 sentinel Programming Projects Wit E3. If we can assume that the keys in the list have been arranged in order for example numerical or alphabetical order then we can terminate unsuccessful searches more quickly. If the smallest keys come first then we can terminate the search as soon as a key greater than or equal to the target key has been found. If we assume that it is equally likely that a target key not in the list is in any one of the n 1 intervals before the first key between a pair of successive keys or after the last key then what is the average number of comparisons for .