Ternary Search is an efficient algorithm used for finding the maximum or minimum of a unimodal function, which is a function that increases and then decreases (or vice versa). Unlike binary search, which divides the search space into two halves, ternary search divides it into three parts. Given a unimodal function , the algorithm consists of evaluating the function at two points, and , which are calculated as follows:
where and are the current bounds of the search space. Depending on the values of and , the algorithm discards one of the three segments, thereby narrowing down the search space. This process is repeated until the search space is sufficiently small, allowing for an efficient convergence to the optimum point. The time complexity of ternary search is generally , making it a useful alternative to binary search in specific scenarios involving unimodal functions.
Start your personalized study experience with acemate today. Sign up for free and find summaries and mock exams for your university.