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
I need help with these please :) I suck at math
nikitadnepr [17]
1)
you have similar triangles(ABC, ADE), so their side length ratios are equal

8/2=4/CE
CE*4=4
CE=1


2)
angle bisector theorem:
CD/DA=BC/BA

CD/DA=10/8
I:AD=10CD/8

we also know AC=AD+CD=6
II:CD=6-AD

insert II in I:

AD=10(6-AD)/8
=5(6-AD)/4
=(30-5AD)/4
4AD=30-5AD
9AD=30
3AD=10
AD=10/3
8 0
3 years ago
F-20f=21 what’s the answer
Virty [35]

\bold{[ \ Answer \ ]}

\boxed{\bold{F \ = \ -\frac{21}{19} }}

\bold{[ \ Explanation \ ]}

  • \bold{Solve: \ f \ - \ 20f \ = \ 21}

-----------------------------------

  • \bold{Add \ Similar \ Elements:f-20f=-19f}

\bold{-19f=21}

  • \bold{Divide \ Both \ Sides \ By \ -19}

\bold{\frac{-19f}{-19}=\frac{21}{-19}}

  • \bold{Simplify}

\bold{F \ = \ -\frac{21}{19}}

\boxed{\bold{[] \ Eclipsed \ []}}

5 0
3 years ago
Using the Pythagorean theorem, find the length of a leg of a right triangle if the other leg is 8 foot long and the hypotenuse i
Lemur [1.5K]
⓵ The pythagorean theorem is calculated by using this formula : a² + b² = c²

“a” is the length of one of the legs
“b” is the length of the other leg
“c” is the length of the hypotenuse

⓶ Now that you have the formula, replace the letters in the formula with the information that you have :

8² + b² = 10²

⓷ Now that this is done, you need to isolate the “b²” in order to find the length of the other leg of the triangle :

8² + b² = 10²
-8² -8²

↓

b² = 36
√b² √36

↓

b = 6

So the final answer is : the length of the other leg of the triangle is ↠ 6 feet

I really hope this helped, if there’s anything just let me know! ☻
6 0
3 years ago
Read 2 more answers
Equivalent to 2(b + 3c)
Kay [80]
When solved using the distributive property, it will equal 2b+6c
8 0
3 years ago
Read 2 more answers
What is 52 -78+93 /5^3
const2013 [10]

Answer:

35.8

= 36(when rounded off)

6 0
2 years ago
Other questions:
  • A man started walking a kilometer a day. If, instead of walking a kilometer everyday, he walked 90% of the distance he walked th
    10·1 answer
  • What characteristics make terms "like terms?"
    10·2 answers
  • Describe a real-life multiplication situation for which an estimate makes sense . Explain why it makes sense
    9·1 answer
  • 3+ 6 x 2<br> witch operation should i do first ?
    10·2 answers
  • Which best summarizes Pythagorean Theorem
    13·1 answer
  • Use repeated subtraction to divide 35÷4=<br> please I need an example
    14·2 answers
  • What is the inverse of f(x)=2x-4<br>​
    11·1 answer
  • Please helpppppp
    5·1 answer
  • What ratio is equivalent to TanA?
    9·1 answer
  • A variable x has a binomial distribution with probability of success 0.3 for each trial.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!