Ternary search is an efficiency that can be used to find an element in a sorted array. Use this tag for question-related to ternary search only and not the ternary operator.
Ternary search
Ternary search is an efficient searching algorithm (divide and conquer algorithm) that divides a sorted array/list into 3 parts by creating 2 midpoints then compares the element-to-be-found (say x) with the 2 midpoints.
- if the x < midpoint1: then the array is shortened to the first of the 3 parts and the function is called again recursively.
- elif x > midpoint2: then the last part of the array is given recursively to the function.
- finally, if neither of the conditions is satisfied then the middle portion of the array is passed recursively.
- This process is continued until the element is found.