''' This is a type of divide and conquer algorithm which divides the search space into 3 parts and finds the target value based on the property of the array or list (usually monotonic property). Time Complexity : O(log3 N) Space Complexity : O(1) ''' from __future__ import print_function import sys try: raw_input # Python 2 except NameError: raw_input = input # Python 3 # This is the precision for this function which can be altered. # It is recommended for users to keep this number greater than or equal to 10. precision = 10 # This is the linear search that will occur after the search space has become smaller. def lin_search(left, right, A, target): for i in range(left, right+1): if(A[i] == target): return i # This is the iterative method of the ternary search algorithm. def ite_ternary_search(A, target): left = 0 right = len(A) - 1; while(True): if(left