• :00Days
• :00Hours
• :00Mins
• 00Seconds
A new era for learning is coming soon Suggested languages for you:

Europe

Answers without the blur. Sign up and see all textbooks for free! Q27E

Expert-verified Found in: Page 203 ### Discrete Mathematics and its Applications

Book edition 7th
Author(s) Kenneth H. Rosen
Pages 808 pages
ISBN 9780073383095 # The 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 ( ${x}_{1},{x}_{2},....,{x}_{n}$ integers with $n\ge 1,a$ integer)

$v:=1\phantom{\rule{0ex}{0ex}}y:=m$

\user1while $v

Algorithm will return $location$ , which is the position of searched element in the list.

See the step by step solution

## Step 1: Algorithm

Algorithm for Binary Search:

\user1 procedure binary search ( a : integer, ${x}_{1},{x}_{2},..,{x}_{n}:increa\mathrm{sin}g$ )

$i:=1${i is left endpoint of search interval}

$j:=n$ { j is right endpoint of search interval}

\user1while $i

## Step 2: convert binary search to ternary search

Make changes in,

\user1while $i

First change is divide using 3 instead of dividing by 2 .

The algorithm based on above conditions given as:

\user1 procedure ternary search ( ${x}_{1},{x}_{2},...,{x}_{n}$ integers with $n\ge 1,a:$ integer)

$v:=1\phantom{\rule{0ex}{0ex}}y:=m$

\user1while $v ### Want to see more solutions like these? 