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
yan [13]
3 years ago
9

(20 points) Given a collection of n nuts and a collection of n bolts, arranged in an increasing order of size, give an O(n) time

algorithm to check if there is a nut and a bolt that have the same size. The sizes of the nuts and bolts are stored in the sorted arrays NUT S[1..n] and BOLT S[1..n], respectively. Your algorithm can stop as soon as it finds a single match (i.e, you do not need to report all matches).
Computers and Technology
1 answer:
Blababa [14]3 years ago
6 0

Answer:

Check the explanation

Explanation:

Keep two iterators, i (for nuts array) and j (for bolts array).

while(i < n and j < n) {

if nuts[i] == bolts[j] {

We have a case where sizes match, output/return

}

else if nuts[i] < bolts[j] {

what this means is that the size of nut is lesser than that of bolt and we should go to the next bigger nut, i.e., i+=1

}

else {

what this means is that the size of bolt is lesser than that of nut and we should go to the next bigger bolt, i.e., j+=1

}

}

Since we go to each index in both the array only once, the algorithm take O(n) time.

You might be interested in
How to remove negative feedback on amazon?
Svetlanka [38]
1. go back to the feedback you submitted
2.Locate the order, and then click remove 
3.select a reason for the removal and click to remove the feedback button.

(But why would you write a rude comment in the first place to begin with?)
3 0
3 years ago
You often need to have several applications open at the same time. Which requirement is related to this need?
Musya8 [376]

Answer:

processor speed is the answer but not sure

5 0
3 years ago
write a function that counts the number of times the value of y occurs in the first n values in array x. y is an integer variabl
mixer [17]

Answer:

Following are the function of count:

void count(int y,int x[],int n) // function definition of count

{

int k,count=0;  // variable declaration

for(k=0;k<n;++k) // iterating over the loop

   {

   if(x[k]==y) //check the conndition number of times the value of y occurs

   {

   count++; // increment of count by 1

   }

   }

Explanation:

Following are the code in c language

#include <stdio.h> // header file  

void count(int y,int x[],int n) // function definition of count

{

int k,count=0;  // variable declaration

for(k=0;k<n;++k) // iterating over the loop

   {

   if(x[k]==y) //check the conndition number of times the value of y occurs

   {

   count++; // increment of count by 1

   }

   }

   printf(" the number of times the value of y occurs :%d",count); // display count value

   }

int main() // main method

{

   int x[100],y,n,k; // variable declarartion

   printf(" Enter the number of terms n :");

   scanf("%d",&n); // input the terms

   printf(" Enter the array x :");

   for(k=0;k<n;++k) // input array x

   {

   scanf("%d",&x[k]);

   }

   printf("Enter the value of y:");

   scanf("%d",&y);// input value y by user

    count(y,x,n); // calling function

   return 0;

}

In the given program we declared an array x ,variable  y and n respectively Input the array x ,y,n  by user after that we call the function count .In the count function we iterate the loop from o position to array length-1 and check the number of times the value of y occurs by using if statement  i.e  if(x[k]==y) if the condition of if block is true then we increment the count variable Otherwise not .Finally display the count variable which describe the number of count.

Output

Enter the number of terms n :5

1

2

2

56

5

Enter the value of y:2

the number of times the value of y occurs :2

Enter the number of terms n :5

1

2

3

56

5

Enter the value of y:26

the number of times the value of y occurs :0

7 0
2 years ago
The color encoding we’re using is RGB.What does this mean,in terms of the amount of memory required to represent color? Is there
DanielleElmas [232]

Answer:

RGB

Explanation:

R=red

G=Green

B=Blue

RGB is standard scheme of colors ,rest of the colors use to be make by mixing three of these colors. These are standard colors use for monitor,computer and Tv screen.

RBG plays an vital role in the memory of the computer. For example the JPG file is RBG-24 bit file. So it is easy to upload the file that is JPG and it is easy to edit and upload. This file is taking less RAM so the editors usually keeps the JPG file along with them because it is easy to compress and edit the file.

Hence it is proved that RGB color coding is very efficient for the usage of the memory because it is already a compressed file and use the RAM so efficiently, so the quality of task done by CPU would never be compromised by using RGB.

Large photo is usually composed of more colors and the computer use to struggle alot for such iamge files.

The RGB code (0-255 for each of R, G, B) carrirs  16777216 possible matches. It's not almost "every new color," but it made up more than most of the colors humans can easily identifies.

we must say that RGB is not the perfect choice for making every possible color that is existing but it is quite helpful in making every unique color that a human could identify. RGB is mostly makes the light color with the combination of these three colors.

RGB is not the best for making every possible color but it is so useful as far as the computer memory is concern it uses very less memory and it file is quite light. Uploading of JPG file is easy ,it takes less time and memory.

On clouds the memory is most important element so, mostly the RGB are preferred colors and these are enough to represent in compute scheme.

8 0
3 years ago
#Write a function called get_integer that takes as input one #variable, my_var. If my_var can be converted to an integer, #do so
DiKsa [7]

Answer:

#here is function in python

#function that return integer if input can be converted to int

#if not it will return a string "Cannot converted!!"

def get_integer(inp):

   try:

       return int(inp)

   except:

       return "Cannot convert!!"

print()

#call the function with different inputs

print(get_integer("5"))

print(get_integer("Boggle."))

print(get_integer(5.1))

print()

Explanation:

Define a function get_integer() with a parameter.In this function there is try  and except.First try will execute and if input can be converted to integer then  it will convert it into integer and return it.If it will not able to convert  the input into integer then except will return a string "Cannot convert!!".In the function get_integer(), there is no use of any conditionals or type function.

Output:

5

Cannot convert!!

5  

6 0
2 years ago
Other questions:
  • Marie uses a browser to visit a blog. What is the unique identifier of the blog?
    5·1 answer
  • Complete the recursive function raisetopower(). ex: if userbase is 2 and userexponent is 4, then raisedvalue is assigned with 16
    5·1 answer
  • Which of the following statements is true?
    12·1 answer
  • Read the following paragraph:
    9·2 answers
  • Define a function CoordTransform() that transforms its first two input parameters xVal and yVal into two output parameters xValN
    7·2 answers
  • In order to use an object in a program, its class must be defined.
    9·1 answer
  • Robert works in a call center and receives a call from Kathy. Kathy says she can no longer access the online reporting applicati
    13·1 answer
  • Describe Relational Query Languages and Operations.
    15·1 answer
  • 14. Which of the following is NOT likely to be one of the future development gaming industry?
    7·1 answer
  • What are the disadvantages of vector images when compared to bitmap images?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!