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]
3 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]3 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
Can someone tell me what this means Higfaa
Arisa [49]

Answer:

it's a Jamaican slang

Explanation:

it depends on the wah it is used

7 0
2 years ago
Microsoft Word cannot be used to create personalized web<br> pages.<br> OTrue<br> False
Georgia [21]

Answer:

False

Explanation:

Because Microsoft can be used to create personalized web

5 0
2 years ago
A simple system is to be designed to allow for the selling of old books. There are two different types of users: buyers and sell
VMariaS [17]
Yes yes yes yes yeah yes
7 0
3 years ago
On Microsoft teams, how do teachers know that you are on a different page?
emmasim [6.3K]

Answer:

they can view if you left the page on the teacher side of the website

Explanation:

i have made a page just for this

6 0
3 years ago
Read 2 more answers
Please help me with these short questions &gt;..
Thepotemich [5.8K]

Answer:

bmjcmbbobnkpkkjkbk

Explanation:

vuvkopbbkvkhovjlplbkp

6 0
2 years ago
Other questions:
  • Exterior brick veneers are used to support the entire weight of the roof structure
    12·2 answers
  • What are some ways to accept data typed into a cell? Check all that apply.
    15·1 answer
  • A downloaded executable file may contain harmful software known as
    13·2 answers
  • Your mom wants to purchase a computer. She has heard about how the Windows 8 operating system is best-geared for a touch-enabled
    8·1 answer
  • To find your personal learning style you can
    5·2 answers
  • What is the traditional cognitive perspective ofHCL?
    12·1 answer
  • a machine needs a minimum of 100 sec to sort 1000 names by quicksort what is the approximate worst case time needed to sort 100
    13·1 answer
  • A multi-national retail company has multiple business divisions with each division having its own AWS account. The engineering t
    9·1 answer
  • Choose the true statement below. (html)
    5·1 answer
  • Leslie’s parents put a big dry-erase board on the refrigerator and let the kids write suggestions for how to organize and assign
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!