must explicitly implement comparisonand ensure this comparison has basic properties such as transitivity (if the comparison is implemented incorrectlyyou may find lookup into sorted collection failseven when the item is present suppose we are given as input an array of studentssorted by descending gpawith ties broken on name in the program belowwe show how to use the library binary search routine to perform fast searches in this array in particularwe pass binary search custom comparator which compares students on gpa (higher gpa comes first)with ties broken on name student collections namedtuple ('student '('name ''grade_point_average ')def comp_gpa student )return (student grade_point_average student namedef search_student (students target comp_gpa ) bisect bisect_left (comp_gpa (sfor in students ]comp_gpa target )return < lenstudents and students [ =target assuming the -th element in the sequence can be accessed in ( timethe time complexity of the program is (log nbinary search is an effective search tool it is applicable to more than just searching in sorted arrayse it can be used to search an interval of real numbers or integers if your solution uses sortingand the computation performed after sorting is faster than sortinge (nor (log )look for solutions that do not perform complete sort consider time/space tradeoffssuch as making multiple passes through the data table top tips for searching know your searching libraries the bisect module provides binary search functions for sorted list specificallyassuming is sorted list to find the first element that is not less than targeted valueuse bisect bisect_left( ,xthis call returns the index of the first entry that is greater than or equal to the targeted value if all elements in the list are less than xthe returned value is len(ato find the first element that is greater than targeted valueuse bisect bisect_right( ,xthis call returns the index of the first entry that is greater than the targeted value if all elements in the list are less than or equal to xthe returned value is len(ain an interviewif it is alloweduse the above functionsinstead of implementing your own binary search search sorted array for first occurrence of binary search commonly asks for the index of any element of sorted array that is equal to specified element the following problem has slight twist on this