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
uranmaximum [27]
3 years ago
10

Suppose that an array of strings contains ["blueberry", "chocolate", "coconut", "coffee", "mint", "strawberry", "vanilla"]. How

many compares are used for a successful search for "mint" with binary search?
Computers and Technology
1 answer:
Mademuasel [1]3 years ago
4 0

Answer:

The answer is "4".

Explanation:

In the given question the answer is "4" because the array of indexing always starts from the "0" position and the "mint" element value store in the fourth position.

This position can also be defined by the program code, which is defined in the below section. please find the code as well as its output.

program:

#include<iostream> //defining header file

using namespace std;  

int BS(string Arr[], string val,int n) //defining method BS

{  

int length=0 ;//defining integer variable length  

int range = n-1; //defining range variable that takes one less value from n

while (length <= range)//defining while loop to check the length is less then equal to the range

{  

int max=length+(range-length)/2;//defining max to store value  

int rest; //defining integer variable rest  

if (val == (Arr[max])) //defining if block that check val equal to Arr

{

rest= 0; //use rest variable to assign value 0

}

if (rest==0)//defining if block that check rest equal to 0

{

return max;   //return max value

}

if (val > (Arr[max])) //defining if block that check val greater then Arr value

{

length=max+1; //use length variable that hold max+1 value  

}

else //defining else block

{

range= max-1; //use range variable that hold max-1 value  

}

}  

return -1; //return value -1

}  

int main()//defining main method  

{  

string Arr[]={"blueberry","chocolate","coconut","coffee","mint","strawberry","vanilla"};  

string val = "mint"; //defining string variable val that store "mint" value

int n=7;//defining integer variable n that store array element value  

cout<<BS(Arr,val,n); //use print method to call method "BS" and print value  

}

output:

4

You might be interested in
Consider two different implementations, M1 and M2, of the same instruction set. There are three classes of instructions (A, B, a
kkurt [141]

Answer:

(a) Calculate the average CPI for each machine, M1, and M2

Average CPI = Cycles per Instruction * Frequency of each  Instruction

                     = CPI * F

For Machine M1:

Cycles per Instruction/ Clocks per Instruction =  (60%)* 1 + (30%)*2 + (10%)*4

                                                                        = (0.60) * 1 + (0.30) * 2 + (0.10) * 4

                                                                          = 0.6 + 0.6 + 0.4

                                                                          = 1.6

For Machine M2:

Cycles per Instruction/ Clocks per Instruction=  (60%)*2 + (30%)*3 + (10%)*4

                                                                         = (0.60) *2 + (0.30) * 3 + (0.10) *4        

                                                                         = 1.2 + 0.9 + 0.4

                                                                          = 2.5

(b) Calculate the average MIPS ratings for each machine, M1 and M2.

MIPS rating can be found by using this formula

MIPS rating = Instruction Count / Execution Time * 10^6

                   = Instruction count  / IC X CPI * Clock cycle time * 10^6

                   = IC X Clock rate  / IC X CPI X 10^6

                   = Clock Rate/(CPI * 10^6)

MIPS rating for Machine M1:

The clock rate for M1 is 80 MHz and CPI calculated in (a) is 1.6 So:

MIPS rating = (80 * 10^6) / (1.6 * 10^6 )

                   =  80000000/ 1600000

                   =  50

MIPS rating for Machine M2:

The clock rate for M1 is 100 MHz and CPI calculated in (a) is 2.5 So:

MIPS rating = (100 * 10^6 ) / (2.5 * 10^6 )

                   =  100000000 / 2500000

                  =  40

(c) Which machine has a smaller MIPS rating?

  • M2 has a smaller MIPS rating which is 40.

Which individual instruction class CPI do you need to change, and by how much, to have this machine have the same or better performance as the machine with the higher MIPS rating.

Machine M1 has the higher MIPS rating than M2 and in order to make M2 perform better than M1, the CPI of instruction class A should be modified. Lets change the instruction class A CPI to 1 in place of 2.

Then:

Cycles per Instruction/ Clocks per Instruction= (60%)*1 + (30%)*3 + (10%)*4

                                                                       = (0.60 * 1) + (0.30 * 3) + (0.10 * 4)

                                                                       = 0.60 + 0.9 + 0.4

                                                                       = 1.9

Average MIPS rating = (100 * 10^6) / (1.9 * 10^6 )

                                   = 100000000 / 1900000

                                   =  52.6

Average MIPS rating is of M2 after changing instruction class A CPI is 52.6 which is better than the average MIPS rating of M1 which is 50.0

4 0
3 years ago
Your child has broken the RJ-45 port of your laptop by sticking clay into it and there are no wireless networks available in you
sesenic [268]

Answer:

آمل أن يساعد هذا Purchase and use a USB to RJ-45 adapter-yes

fiber_manual_record Enable NIC teaming to increase your bandwidth

Explanation:

67.185.94.80

6 0
3 years ago
3. Under which of the following categories does the artwork fall? ( 1 point )
Bumek [7]
Portrait is usually a painting of someone, still life is a very realistic drawing, monoprint is a print of an ex. leaf or other object.. its an ABSTRACT PAINTING
5 0
4 years ago
Read 2 more answers
As a ______________ you must be able to show that you know what to do to keep food safe
Natali [406]

         

<h2>\beta\beta \beta \geq \neq</h2>
6 0
4 years ago
How do i add an answer on brainly i click to add an answer and it sends me to the home page
cricket20 [7]

Answer:  try to just add as little as possible then add the answser or just reload your browser

Explanation:

7 0
3 years ago
Other questions:
  • Can someone fix this so that it only says "its a payday" on 15 and 30 and on all other days "sorry, it's not payday"
    9·1 answer
  • Because public key encryption requires the use of two different keys, it is also known as _____ encryption
    13·1 answer
  • The expectations I would discuss with Erica regarding the usage of the internet
    6·1 answer
  • Why are agorithms important?
    8·1 answer
  • "Find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the
    9·1 answer
  • 1. Why is it important for IT technicians to keep documentation on computers for which they are
    13·1 answer
  • Tell me the errors please
    14·1 answer
  • You designed a program to find the midpoint of two points. Which step below corresponds to finding the average of the x-coordina
    15·1 answer
  • Explain basic anatomy of computers.
    13·2 answers
  • A(n) Blank______ database model stores data in the form of logically related two-dimensional tables. Multiple choice question. w
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!