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
What is the autput the following machine when the intut is 4
ch4aika [34]

Input is 4.

Process machine:

Input > - 7 > ÷ 3 > Output

Solve:

(Input) 4 - 7 = <u>-3</u>

          <u>-3</u> ÷ 3 = <u>-1 </u>(Output)

Input = 4

Output = -1

3 0
3 years ago
Identifiy the initial amount a and the decay factor b in the exponential function y=5×0.5^×
xenn [34]

Answer:

a=5\\ \\b=0.5

Step-by-step explanation:

Given the exponential decay function y=5\cdot (0.5)^x

When x=0, then

y=5\cdot (0.5)^0=5\cdot 1=5,

so the initial amount is a=5

The exponential decay function y=a\cdot b^x has the decay factor b.

In your case, the eexponential decay factor is b=0.5

6 0
3 years ago
The scatterplot shows the time it takes for a new hot plate to boil various amounts of water, and one lab group’s attempt at a l
Alinara [238K]

Answer:

The correct option is;

The line of best fit is not reasonable because it has more points below it than above it.

Step-by-step explanation:

Here we note that there are a total of seven points in the scatter plot and there are five of the points below the line of best fit and just two above the line.

Of the five points below the line of best fit, four are just about touching the underside of the line while one of the two points above the line is just about touching the line.

The proper positioning of the line can be reviewed, therefore, with a line drawn through the four points presently touching the underside of the line of best fit.

3 0
3 years ago
Read 2 more answers
Solve the equation negative 3X +9 equals three(2x+3) + 3(x-4) + 1
timofeeve [1]

Answer:

1

Step-by-step explanation:

-3x+9=3(2x+3)+3(x-4)+1

Distributive property in the parenthesis

-3x+9=6x+9+3x-12+1

Combine Like Terms

-3x+9=9x-2

Get the x’s on one side

-3x+9=9x-2

+3.  +2    +3. +2

11=11x

Divide by 11 on both sides

11/11=1

5 0
3 years ago
I was wondering what is the best math to take after Algebra 2
Elan Coil [88]
The best math that i think you should take would be calculus.
7 0
3 years ago
Read 2 more answers
Other questions:
  • A binomial probability experiment is conducted with the given parameters. Compute the probability of x successes in the n indepe
    11·1 answer
  • HELP....my last photo didn't work does this one?
    11·1 answer
  • Probability that exactly one jack, one queen, and one king have been picked from the deck when the first ace turns up
    12·1 answer
  • Answer?350x+22,000=410x+16,000 true?
    7·1 answer
  • If the probability that 20 or fewer kids in a group of 25 like pizza is 57%, what is the probability that at least 21 kids in th
    12·1 answer
  • A tree grows three feet per year. What happens to the growth of the
    13·1 answer
  • Please help me and if you can, could you please explain. Thank you :D
    13·2 answers
  • (h-9)(-6)<br><br><br> ............
    7·1 answer
  • A survey is being conducted to decide on how much time people spend watching sports on television. Tell whether the given sample
    5·1 answer
  • 48/8 = 42/x
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!