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
(Game Design) Which of the following is NOT a name of a popular digital sculpting application?
Savatey [412]

Claymation option A

Because Claymation is not the game design application.it is also called clay animation.

7 0
2 years ago
How do i find the greatest common factor of two numbers?
Lilit [14]
You can list the numbers . keep listing them till you find the same numbers
8 0
2 years ago
Using Gen/Spec, classes can be organized by using a peer-to-peer inheritanc True/false
Fiesta28 [93]

Answer: True

Explanation: Gen/Spec is the known as the general specification standard for the classes.This standard helps in bringing out the peer-to-peer relations of class.

Gen/Spec is used in class diagram because it helps in the display of the access sharing and class specification in the general form for the required instances.Thus, this standard helps in the enhancement of the class diagram and its inheritance. So, the statement given in the question is true.

5 0
2 years ago
Write a program that calculates and displays the amount ofmoney available in a bank account that initially has $8000 deposited i
Leviafan [203]

Answer:

Written in Python

import math

principal = 8000

rate = 0.025

for i in range(1, 11):

    amount = principal + principal * rate

    principal = amount

    print("Year "+str(i)+": "+str(round(amount,2)))

Explanation:

This line imports math library

import math

This line initializes principal amount to 8000

principal = 8000

This line initializes rate to 0.025

rate = 0.025

The following is an iteration from year 1 to 10

for i in range(1, 11):

    This calculates the amount at the end of the year

    amount = principal + principal * rate

    This calculates the amount at the beginning of the next year

    principal = amount

    This prints the calculated amount

    print("Year "+str(i)+": "+str(round(amount,2)))

6 0
3 years ago
Can you create energy?
Katarina [22]
There is a set amount of energy in the universe and you cannot destroy or create energy.
3 0
2 years ago
Other questions:
  • The internet is an example of
    12·2 answers
  • Can you structure this code in if-statements?
    15·1 answer
  • You are going to write a program for Computer test which will read 10 questions from a file, order them randomly and provide the
    11·1 answer
  • Explain the use of keyboard shortcuts and key combinations. You are at the tenth page of a 20-page document. You need to make ch
    14·1 answer
  • I have to make a online presentation, which program is the best
    10·2 answers
  • Use HTML to create a web page
    10·1 answer
  • In a systems development life cycle (SDLC) model, the purpose of the _____ is to create a physical model that will satisfy all d
    10·1 answer
  • The printer prints 16 pages every minute. How many pages are printed in 6 minutes?
    14·2 answers
  • Consider the following code segment
    15·1 answer
  • If a filesystem has a block size of 4096 bytes, this means that a file comprised of only one byte will still use 4096 bytes of s
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!