Americas
Europe
Q27E
Expert-verifiedThe ternary search algorithm locates an element in a list of increasing integers by successively splitting the list into three sublists of equal (or as close to equal as possible) size, and restricting the search to the appropriate piece. Specify the steps of this algorithm.
The ternary search algorithm is given as:
\user1 procedure ternary search ( integers with integer)
\user1while
Algorithm will return , which is the position of searched element in the list.
Algorithm for Binary Search:
\user1 procedure binary search ( a : integer, )
{i is left endpoint of search interval}
{ j is right endpoint of search interval}
\user1while
Make changes in,
\user1while
First change is divide using 3 instead of dividing by 2 .
The algorithm based on above conditions given as:
\user1 procedure ternary search ( integers with integer)
\user1while
94% of StudySmarter users get better grades.
Sign up for free