/* Program to search data in given array using ternary search */ #include #include // Function to search data in a given array int Ternary_search(int *arr,int l,int r,int to_search) { //split current array into 3 part int Mid1=l+(r-l)/3,Mid2=r-(r-l)/3; // data not found condition if(l>r) return -1; // if data found in Mid1 index then return index number else if(arr[Mid1]==to_search) return Mid1; // if data found in Mid2 index then return the index number else if(arr[Mid2]==to_search) return Mid2; //else if data not found at index Mid1 and Mid2 then search in middle part of array else if(arr[Mid1]to_search) { Mid1=Mid1+1; Mid2=Mid2-1; } // if data is less than Mid index data then search in before index number of current else if(arr[Mid1]>to_search) { Mid2=Mid1-1; Mid1=l; } // if data is less than Mid index data then search in after index number of current else if(arr[Mid2]