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]
4 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]4 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
9.19 LAB: Words in a range (lists) Write a program that first reads in the name of an input file, followed by two strings repres
Anestetic [448]

Answer:

9.2. Métodos del Objeto File (Python para principiantes)

Explanation:

8 0
3 years ago
How can i setup a mesage room and also want to hangout ??????
bixtya [17]

Answer:

no

Explanation:

4 0
2 years ago
. prevalence of coronary artery disease in patients with isolated aortic valve stenosis. br heart j. 1984;51:121–4.
Sergio [31]

The study on the prevalence of coronary artery disease in patients with isolated aortic valve stenosis is given below.

<h3>What was the study about?</h3>

The prevalence of a High amount coronary artery disease (that is the lowering in luminal diameter by about  50%) is one that is seen in a lot of people such as about 88 consecutive patients and it is one where they have aortic stenosis that needs aortic valve replacement.

The study shows that the risk factors associated with coronary disease were said to be equally distributed in all of the patients with and without a good amount of luminal obstruction.

Therefore, one can say that the study on the prevalence of coronary artery disease in patients with isolated aortic valve stenosis is well done.

Learn more about coronary artery disease from

brainly.com/question/1347334

#SPJ4

5 0
2 years ago
Which of the following is a key component to your individual internet safety? government regulations
nexus9112 [7]
It is government regulations and acceptable use policy
3 0
3 years ago
Please write a Java program.
Marianna [84]

Answer:

public class Main

{

public static void main(String[] args) {

 int[] arr = {3, 1, 1, 2, 4, 4, 4, 6};

 

 int[] o = countOccurance(arr);

 for (int x: o)

     System.out.print(x + " ");

}

public static int[] countOccurance(int[] arr){

    int[] occ = new int[6];

    for (int x: arr)

        occ[x-1]++;

   

    return occ;

}

}

Explanation:

Create a function called countOccurance that takes one parameter, an array

Inside the function, initialize an array, occ, to hold the occurance counts

Create a for each loop to iterate the array, and increment the occurance of the numbers

When the loop is done, return the occ array

Inside the main, initialize an array

Call the function countOccurance and set it to a new array, o

Print the elements of the o to see the number of occurances of the numbers

5 0
3 years ago
Other questions:
  • Using Python
    14·1 answer
  • Explaim Why the shape of a cell is hexagonal
    15·1 answer
  • This is important I need help please
    14·1 answer
  • What does the Additional Clock tab do?
    11·1 answer
  • Reasons for the growth of decision-making systems include:
    13·1 answer
  • What is drop shipping and how it works on amazon?
    12·1 answer
  • Why is yo utu be down?<br> (You restrict talking about yo utu be, really)
    11·2 answers
  • If the tax percent is 15% and tax is $36 and percent discount is 10, what is the cost price?​
    12·1 answer
  • Write a boolean expression that is true if s references the string end.
    8·1 answer
  • These brainly bots need to stop!!
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!