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
The purpose of a method's postcondition is to
anyanavicka [17]
The answer that would best complete the given statement above would be option 5. The purpose of a method's postcondition is to describe the conditions that are true when the method completes. On the other hand, precondition describes the conditions that are true before the method is complete. Hope this helps.
7 0
3 years ago
If classes C1 and C2 both implement an interface Cint, which has a method whichIsIt, and if C1 c = new C1( ); is performed at on
Assoli18 [71]

Answer:

FALSE

Explanation:

Because C1 and C2 implement the same interface, they both implement whichIsIt. The variable c is known as a polymorphic variable, meaning that it can change from being an C1 to a C2. So, the message c.whichIsIt( ); may invoke C1's whichIsIt or C2's whichIsIt. This can only be known at runtime.

5 0
3 years ago
In a relational database, a ____ would ensure that two customers with the same name don’t get confused with each other.
earnstyle [38]

Answer: Primary key

Explanation: Relational databases are those databases which are commonly found in the form of tables . It works in the relation pattern for accessing the data in the database

Primary key is a major factor which is found in the relational databases for the identification of the data in the table's column.It is considered as the unique value that corresponds to the values of rows in the table of relational database.

6 0
3 years ago
What is an algorithm?
hichkok12 [17]
D. Both A and C. In my opinion though...
8 0
3 years ago
Why did we decide to send a message as a sequence of two options rather than modifying our devices to represent more options?
yaroslaw [1]

Answer:

Following are the solution to this question:

Explanation:

Please find the complete question in the attachment file.

The binary message is also an XML text SMS, which is used to represent in binary character. It may also flag the binary text as binary, and it can attach the UDH as just the start of its message. In this question, we assume that you can include A and B because there could be no more than 2 choices in such a binary message.

8 0
2 years ago
Other questions:
  • The EPA requires the use of precise forms called ?
    14·1 answer
  • You can add multiple worksheets to a workbook by clicking the home tab on the ribbon, pressing and holding ____, and then clicki
    6·1 answer
  • In what country was the English royal family and nobility living before the Restoration?
    6·1 answer
  • The number of pixels displayed on the screen is known as ________.
    13·1 answer
  • _______ allows you to add formatting such as shapes and colors to text. a. worddraw b. wordart c. worddesign d. wordshapes
    10·2 answers
  • Sorting Records in a Form
    12·1 answer
  • The metric unit used for length
    5·1 answer
  • Select the correct answer from each drop-down menu.
    14·1 answer
  • A file extension of .xlsx means that the file contains what?
    9·1 answer
  • What two characteristics describe an ftp connection?.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!