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
What do you understand by cloud computing? list the advantages of clould computing.​
LenaWriter [7]

Answer:

Cloud infrastructures support environmental proactivity, powering virtual services rather than physical products and hardware, and cutting down on paper waste, improving energy efficiency, and (given that it allows employees access from anywhere with an internet connection) reducing commuter-related emissions.

Explanation:

3 0
2 years ago
Read 2 more answers
What is an example of a source that is less likely to be copyrighted?
Ivahew [28]
An example would be a: motorized vehicle aka a car or a bike etc.
8 0
3 years ago
Read 2 more answers
A characteristic often associated with entrepreneurship is
FromTheMoon [43]

Answer:

with small businesses

Explanation:

to make a lager profit

3 0
2 years ago
Traceability of requirements is helpful in the followingexcept
larisa86 [58]

Answer: D)  Identifying GUI's for a particular requirement

Explanation:

 Traceability of requirements is helpful except identifying GUI's for a particular requirements as, traceability in project management describe the relationships between two or more element throughout in the development process and outline the relationship between the customer requirement by traceability matrix. And the requirement of traceability is so important because it creating a downstream flow of software and test cases in software requirement but not helpful in GUI identification.

6 0
3 years ago
The following code will create a zombie child process because the child process is terminated and the parent process is busy in
Georgia [21]

Answer:

what on earth

Explanation:

5 0
3 years ago
Other questions:
  • What customization feature can you use to create a cohesive look and feel for your presentations
    5·1 answer
  • When a communication exchange that does not verify the identity of the endpoints of a communication and accepts any properly for
    10·1 answer
  • The algorithm credited to Euclid for easily finding the greatest common divisor of two integers has broad significance in crypto
    11·1 answer
  • Plot element is typically the turning point in the most intense moment of a story
    8·1 answer
  • What dose AUP stand for??????????
    15·2 answers
  • Which of the following is NOT a valid name for a function?
    5·1 answer
  • What happens if none of the selector values match selector in a simple case expression in pl/sql
    6·1 answer
  • Which important aspect of the Roman Empire did the barbarians destroy?
    14·2 answers
  • The Power of If Worksheet
    13·2 answers
  • The function that overloads the ____ operator for a class must be declared as a member of the class.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!