Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

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.

Short Answer

Expert verified

The ternary search algorithm is given as:

\user1 procedure ternary search ( x1,x2,....,xnintegers with n1,ainteger)

v:=1y:=m

\user1whilev<y-1

Algorithm will returnlocation , which is the position of searched element in the list.

Step by step solution

01

Algorithm

Algorithm for Binary Search:

\user1procedurebinary search ( a : integer,x1,x2,..,xn:increasing )

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

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

\user1whilei<j

02

convert binary search to ternary search

Make changes in,

\user1whilei<j

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

The algorithm based on above conditions given as:

\user1 procedure ternary search ( x1,x2,...,xnintegers with n1,a:integer)

v:=1y:=m

\user1whilev<y-1

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Study anywhere. Anytime. Across all devices.

Sign-up for free