![]() If the value being sought occurs k times in the list, and all orderings of the list are equally likely, the expected number of comparisons is The worst case is when the value is not in the list (or occurs only once at the end of the list), in which case n comparisons are needed. Else, the search terminates unsuccessfully.įor a list with n items, the best case is when the value is equal to the first element of the list, in which case only one comparison is needed. If L i = T, the search terminates successfully return i. ![]() This variation requires a sentinel that is greater than the target. ≤ L n−1, the search can establish the absence of the target more quickly by concluding the search once L i exceeds the target. If the list is ordered such that L 0 ≤ L 1. Else, the search terminates unsuccessfully.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |