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
vitfil [10]
3 years ago
9

Suppose we are performing a binary search on a sorted array called numbers initialized as follows: // index 0 1 2 3 4 5 6 7 8 9

10 11 12 13 14 int[] numbers = {-5, -1, 0, 3, 9, 14, 19, 24, 33, 41, 56, 62, 70, 88, 99}; int index = binarySearch(numbers, 18); Write the indexes of the elements that would be examined by the binary search (the mid values in our algorithm's code).
Computers and Technology
1 answer:
konstantin123 [22]3 years ago
6 0

Answer:

The indexes of the elements that would be examined by the binary search are

7 11 9

numbers[7] = 39

numbers[11] = 57

numbers[9] = 42

The values that would be returned from the search are    

39 57 42

Explanation:

The complexity of searching a value in an array using binary search is O (log n). It follows divide and conquer principle. First we have to sort the elements in the array. Here in our case the array is already sorted.

   target = (search for the value) =42

numbers[] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

here assign min= 0 (minimum index)

max= 14 (maximum index)    

Instead of searching for the target in a sequential manner we are searching by examining the middle term in the array by using the following formula. middle = ( min + max )/2

step 1) middle = (0 + 14)/2 = 7 numbers[middle]=numbers[7] = 39

compare target value with numbers[middle]

i.e target = 42 > 39 , the target value is greater than the numbers[middle]. so we have to move to upper part of the array.

Then min= middle+1 = 7+1 = 8

max= (unchanged) 14

 

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

step 2) middle = (8+ 14)/2 = 11 numbers[middle]=numbers[11] = 57

compare target value with numbers[middle]

i.e target =  42 < 57 ,the target value is lesser than the numbers[middle] .

Then min= (unchanged) 8

max= middle -1 =11-1 =10

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

step 3) middle = (8+10)/2 = 9   numbers[middle]=numbers[9] = 42

i.e target =  42 = 42

Here stop the process. In this way we found our target using binary search.

You might be interested in
Where does change management play a major role in transforming a client
nevsk [136]

To manage a modern IT environment characterized by hybrid complexity and exponential data growth — and to make that same IT a driver of growth and innovation for the business — you need to build intelligence into every layer of your infrastructure.

3 0
3 years ago
What is the output?
olga55 [171]

Answer:

The output is 28

Explanation:

Required

Determine the output of the code segment

The first line initializes "answer" to 0

The next two lines iterate through lists [2,4] and [3,5

Each of these lists have two elements; So, the number of iterations is 2 * 2 i.e. 4.

In the first iteration

numA = 2, numB = 3, answer = 0

So:

answer = answer + numA + numB= 0 + 2 + 3 = 5

In the second iteration

numA = 2, numB = 5, answer = 5

So:

answer = answer + numA + numB= 5 + 2 + 5 = 12

In the third iteration

numA = 4, numB = 3, answer = 12

So:

answer = answer + numA + numB= 12 + 4 + 3 = 19

In the fourth iteration

numA = 4, numB = 5, answer = 19

So:

answer = answer + numA + numB= 19 + 4 + 5 = 28

Lastly, the value of "answer" is printed

<em>Hence, the output is 28</em>

7 0
3 years ago
A ___________ variable is used to add up a set of values. fill in the blank
TEA [102]

Answer:

dependent variable -- As it depends on the other variables, changes when they change

3 0
3 years ago
Engineers at Edison Laboratories developed a _____ strip that allowed them to capture sequences of images on film.
maxonik [38]

Answer:

Kinetoscope

Explanation:

4 0
2 years ago
Read 2 more answers
This is the formula for the future worth of an investment over time with consistent additional monthly payments and a steady rat
stepladder [879]

Answer:

The code is given in C++ below

Explanation:

#include <iostream>

using namespace std;

int main()

{

float fv,pv,r,k,n,pmt,totalmoneyinvested;

pv=1000.00;

r=6/100;

k=12; //The value of k should be 12 for monthly installments

n=45;

pmt=250;

totalmoneyinvested=pv+(pmt*12*45); //The total money you invested

 

fv=pv*(1+r/k)*n*k+pmt*((1+r/k)*n*k-1)*(1+r/k)*r/k;

 

cout<<"Initial Investment:"<<" $"<<pv;

cout<<"\nRate Of Return:6%";

cout<<"\nLength of Time:"<<n<<"year";

cout<<"\nMonthly Payment:"<<" $"<<pmt;

cout<<"\nFinal Amount:"<<" $"<<fv;

cout<<"\nThe Money You Invested Is $"<<totalmoneyinvested<<" And The Final Amount Is $"<<fv;

return 0;

}

4 0
3 years ago
Other questions:
  • I. Given the following Java code fragment, what is output? int a, b; String c, d, e; String x = new String("I LOVE"); String y =
    14·1 answer
  • What are an administrator's choices for managing file permissions on a drive formatted as fat32?
    10·1 answer
  • Ar count = 10;
    13·1 answer
  • Ada lovelace designed the first computer
    7·1 answer
  • Can a spreadsheet be filtered only by one column at a time?
    11·1 answer
  • give an example of a technical issue you were not able to resolve on your first attempt. What troubleshooting steps did you take
    13·1 answer
  • Which of the following is not an advantage of e-commerce for consumers?
    13·2 answers
  • Discuss seven multimedia keys​
    8·1 answer
  • Please help me in this question​
    7·2 answers
  • Which of these is not the correct method for moving text in a document in Word 2016?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!