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
Norma-Jean [14]
4 years ago
5

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 t

o 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:
kari74 [83]4 years ago
8 0

Answer:

See explaination

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] {

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

}

else {

this means that size of bolt is smaller 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
Which track-type can be used to control the master output levels of output and bus paths? Hint: When assigned to an active outpu
ss7ja [257]

Answer:

Master Fader

Explanation:

Master Fader is the core of any DL Series framework with a demonstrated, intuitive work process that comes out on top in industrial applications.

With a totally adjustable User Interface that is versatile for clients of any aptitude level, Master Fader is the most versatile control application accessible.

It can be used to control bus path or the levels of master output of the output.

4 0
4 years ago
You designed a program to find the midpoint of two points. Which step below corresponds to finding the average of the x-coordina
MrRa [10]

Answer:

Perform any needed calculations or data manipulations.

Explanation:

just did the test

hope it helps

8 0
3 years ago
Convert the following C program to C++.
ki77a [65]

Answer:

The program equivalent in C++ is:

<em>#include <cstdio></em>

<em>#include <cstdlib></em>

#define SIZE 5

using namespace std;

<em>int main(int argc, char *argv[]) {</em>

<em>int numerator = 25;</em>

<em>int denominator = 10;</em>

<em>FILE * inPut = fopen(argv[1], "r");</em>

<em>FILE * outPut = fopen(argv[2], "w");</em>

<em>float result = (float)numerator/denominator;</em>

<em>fprintf(outPut,"Result is %.2f\n", result);</em>

<em>float arr[SIZE];</em>

<em>for(int i = 0; i < SIZE; i++) {</em>

<em>fscanf(inPut, "%f", &arr[i]);</em>

<em>fprintf(outPut, "%7.4f\n", arr[i]);</em>

<em>}</em>

<em>return 0;</em>

<em>}</em>

Explanation:

See attachment for explanation.

Each line were numbered with equivalent line number in the C program

Download cpp
8 0
3 years ago
Choose the correct statement:_______.
olga2289 [7]

Answer:

d. A String is a class data type so a String variable holds a reference to a location in memory

It depends on which programing language or scripting language...

Explanation:

If it's Java then D is the correct answer...

6 0
3 years ago
Help please!, explain what is missing and what needs to be changed if anything.
german

Using the computer language in JAVA to write a function code that output numbers in reverse

<h3>Writting the code in JAVA:</h3>

<em>import java.util.Scanner;</em>

<em>public class LabProgram {</em>

<em>    public static void main(String[] args) {</em>

<em>        Scanner scnr = new Scanner(System.in);</em>

<em>        int[] userList = new int[20];</em>

<em>        int numElements;</em>

<em>        numElements = scnr.nextInt();</em>

<em>        for (int i = 0; i < numElements; ++i) {</em>

<em>            userList[i] = scnr.nextInt();</em>

<em>        }</em>

<em>        for (int i = numElements - 1; i >= 0; --i) {</em>

<em>            System.out.print(userList[i] + " ");</em>

<em>        }</em>

<em>        System.out.println();</em>

<em>    }</em>

<em>}</em>

See more about JAVA at brainly.com/question/12975450

#SPJ1

8 0
2 years ago
Other questions:
  • How to upgrade from office home to office professional
    13·1 answer
  • A __________ acts as separate network that rests outside the secure network perimeter so untrusted users can access web servers
    10·1 answer
  • Write the definition of a function printDottedLine, which has no parameters and doesn't return anything. The function prints to
    10·1 answer
  • Write a program that accepts a time as an hour and minute. Add 15 minutes to the time, and output the result. Example 1: Enter t
    11·1 answer
  • Which of the following is a scam in which a perpetrator sends an official looking e-mail that attempts to obtain a user’s person
    7·2 answers
  • Keith is researching a controversial topic and wants to use a website he found as an information source. Which of the following
    11·2 answers
  • You are network administrator for an Active Directory forest with a single domain. Then network has three sites with one domain
    12·1 answer
  • How does computer science play a role in art?
    6·1 answer
  • Hey how was your day 50 points
    10·2 answers
  • In query design view you can add .............. to limit the number of records shown in the resulting datasheet
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!