StudySmarter AI is coming soon!

- :00Days
- :00Hours
- :00Mins
- 00Seconds

A new era for learning is coming soonSign up for free

Suggested languages for you:

Americas

Europe

Q27E

Expert-verifiedFound in: Page 203

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<y-1$

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

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<j$

Make changes in,

\user1while $i<j$

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<y-1$

94% of StudySmarter users get better grades.

Sign up for free