1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Reil [10]
3 years ago
8

The ternary search algorithm locates an element in a list of increasing integers by successively splitting the list into three s

ub-lists of equal (or as close to equal as possible) size, and restricting the search to the appropriate piece. Specify the steps of this algorithm.
Mathematics
1 answer:
Zigmanuir [339]3 years ago
6 0

Answer:

Algorithm

The steps involved in this algorithm are:

(The list must be in sorted order)

• Step 1: Divide the search space (initially, the list) in three parts (with two mid-points: mid1 and mid2)

• Step 2: The target element is compared with the edge elements that is elements at location mid1, mid2 and the end of the search space. If element matches, go to step 3 else predict in which section the target element lies. The search space is reduced to 1/3rd. If the element is not in the list, go to step 4 or to step 1.

• Step 3: Element found. Return index and exit.

• Step 4: Element not found. Exit.

Complexity

• Worst case time complexity: O(log N)

• Average case time complexity: O(log N)

• Best case time complexity: O(1)

• Space complexity: O(1)

Algorithm

The steps involved in this algorithm are:

(The list must be in sorted order)

• Step 1: Divide the search space (initially, the list) in three parts (with two mid-points: mid1 and mid2)

• Step 2: The target element is compared with the edge elements that is elements at location mid1, mid2 and the end of the search space. If element matches, go to step 3 else predict in which section the target element lies. The search space is reduced to 1/3rd. If the element is not in the list, go to step 4 or to step 1.

• Step 3: Element found. Return index and exit.

• Step 4: Element not found. Exit.

Complexity

• Worst case time complexity: O(log N)

• Average case time complexity: O(log N)

• Best case time complexity: O(1)

• Space complexity: O(1)

#include <stdio.h>

int ternarySearch(int array[], int left, int right, int x)

{

  if (right >= left) {

    int intvl = (right - left) / 3;

    int leftmid = left + intvl;

    int rightmid = leftmid + intvl;

    if (array[leftmid] == x)

       return leftmid;

    if (array[rightmid] == x)

       return rightmid;

    if (x < array[leftmid]) {

      return ternarySearch(array, left, leftmid, x);

    }

    else if (x > array[leftmid] && x < array[rightmid]) {

      return ternarySearch(array, leftmid, rightmid, x);

    }

    else {

      return ternarySearch(array, rightmid, right, x);

    }

  }

  return -1;

}

int main(void)

{

  int array[] = {1, 2, 3, 5};

  int size = sizeof(array)/ sizeof(array[0]);

  int find = 3;

  printf("Position of %d is %d\n", find, ternarySearch(array, 0, size-1, find));

  return 0;

}

Step-by-step explanation:

You might be interested in
5. Car rental company A charges $30 a days and
olga nikolaevna [1]

Answer:

Step-by-step explanation:

I need  the answer for same question pleas

5 0
3 years ago
Read 2 more answers
How do u divide fractions​
Lelu [443]

Keep, change, flip

Example: 3/4 divided by 6/8

Step 1: keep 3/4

Step two: change the division sign to a multiplication sign

Step 3: flip 6/8 and make it 8/6

Step 4: multiply it, then that’s your answer to the division problem

8 0
3 years ago
How many times does 50 go into 70
elena55 [62]
One time because 50 x 50 equals 100 and that to large
4 0
3 years ago
Read 2 more answers
What fraction of the students in the class named baseball their favorite sport
mojhsa [17]

now, let's take a peek at the denominators, we have 3 and 8 and 12, we can get an LCD of 24 from that.

Let's multiply both sides by the LCD of 24, to do away with the denominators.

so, let's recall that a whole is "1", namely 500/500 = 1 = whole, or 5/5 = 1 = whole or 24/24 = 1 = whole.  So the whole class will yield a fraction of 1/1 or just 1.

\bf ~\hspace{7em}\stackrel{\textit{basketball}}{\cfrac{1}{3}}+\stackrel{\textit{soccer}}{\cfrac{1}{8}}+\stackrel{\textit{football}}{\cfrac{5}{12}}+\stackrel{\textit{baseball}}{x}~=~\stackrel{\textit{whole}}{1} \\\\[-0.35em] \rule{34em}{0.25pt}\\\\ \stackrel{\textit{multiplying both sides by }\stackrel{LCD}{24}}{24\left(\cfrac{1}{3}+\cfrac{1}{8}+\cfrac{5}{12}+x \right)=24(1)}\implies (8)1+(3)1+(2)5+(24)x=24 \\\\\\ 8+3+10+24x=24\implies 21+24x=24\implies 24x=3 \\\\\\ x=\cfrac{3}{24}\implies x=\cfrac{1}{8}

4 0
3 years ago
1/3y+11=1/2y-3<br><br> What is y???
olga55 [171]

Answer:

y=84

Step-by-step explanation:

\left(\frac{1}{3}\right)y+11=\left(\frac{1}{2}\right)y-3

Use distributive property.

\frac{1}{3}y+11=\frac{1}{2}y-3

\frac{1}{3}y+11-11=\frac{1}{2}y-3-11

\frac{1}{3}y=\frac{1}{2}y-14

\frac{1}{3}y-\frac{1}{2}y=\frac{1}{2}y-14-\frac{1}{2}y

-\frac{1}{6}y=-14

\left(-\frac{1}{6}y\right)\left(-6\right)=\left(-14\right)\left(-6\right)

y=84

6 0
3 years ago
Read 2 more answers
Other questions:
  • Which number can each term if the equation be multiplied by to eliminate the decimals before solving
    8·1 answer
  • Can anybody help me plzz​
    5·1 answer
  • Is it possible to have a triangle such that none of the exterior angles is obtuse? Please help and explain
    14·1 answer
  • 5x + y = 6
    12·1 answer
  • Find the value of x.
    13·1 answer
  • Which equation represents the line shown in the graph below? y = 5x + 2 y = 2x — 5 y = 2x + 5 y = 5x — 4
    6·1 answer
  • U<br>12 - 7 + 2<br>15 15<br>15<br>1​
    13·1 answer
  • Typing 731 words in 17 minutes
    5·1 answer
  • A textbook store sold a combined total of 354 history and sociology test books in a week. The number of history textbooks sold w
    15·2 answers
  • P-&gt;q is false and p is true.<br> q is<br> a.true<br> b.false
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!