Answer
procedure ternary search $(x: $ an integer $a_1, a_2, ... , a_n: $ list of integers$)$
$i:= 1$
$m := n$
while $i
Work Step by Step
This algorithm is an extension of the binary search to ternary search. It proceeds as follows:
First it splits the list into threes by defining four indices, at the beginning, after a third, after two-thirds and the end. Note how we use the floor function to get integer indices.
After this, we try to place our $x$ value in one of these intervals. Depending on which conditional is true, we modify the endpoints of the interval. Notice that with each step, the range should be getting decreased by a third.
Finally, our algorithm terminates when $i\ge j$ indicating that we have only one element in our array. We check if this element is equal to the target and return the index if it's the required result, $0$ otherwise.