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
kykrilka [37]
3 years ago
12

I have six nuts and six bolts. Exactly one nut goes with each bolt. The nuts are all different sizes, but it’s hard to compare t

hem to each other. (Same for the bolts.) But if I try a nut and a bolt together, it’s easy to see if the nut is smaller than, the same size as, or larger than the bolt. Find a way to use quicksort to match up the nuts and bolts.
Computers and Technology
1 answer:
juin [17]3 years ago
7 0

Answer:

Explanation:

In order to arrange the corresponding nuts and bolts in order using quicksort algorithm, we need to first create two arrays , one for nuts and another for bolts namely nutsArr[6] and boltsArr[6]. Now, using one of the bolts as pivot, we can rearrange the nuts in the nuts array such that the nuts on left side of the element chosen (i.e, the ith element indexed as nutArr[i]) are smaller than the nut at ith position and nuts to the right side of nutsArr[i] are larger than the nut at position "I". We implement this strategy recursively to sort the nuts array. The reason that we need to use bolts for sorting nuts is that nuts are not comparable among themselves and bolts are not comparable among themselves(as mentioned in the question)

The pseudocode for the given problem goes as follows:

// method to quick sort the elements in the two arrays

quickSort(nutsArr[start...end], boltsArr[start...end]): if start < end: // choose a nut from nutsArr at random randElement = nutsArr[random(start, end+1)] // partition the boltsArr using the randElement random pivot pivot = partition(boltsArr[start...end], randElement) // partition nutsArr around the bolt at the pivot position partition(nutsArr[start...end], boltsArr[pivot]) // call quickSort by passing first partition quickSort(nutsArr[start...pivot-1], boltsArr[start...pivot-1]) // call quickSort by passing second partition quickSort(nutsArr[pivot+1...end], boltsArr[pivot+1...end])

// method to partition the array passed as parameter, it also takes pivot as parameter

partition(character array, integer start, integer end, character pivot)

{

       integer i = start;

loop from j = start to j < end

       {

check if array[j] < pivot

{

swap (array[i],array[j])

               increase i by 1;

           }

 else check if array[j] = pivot

{

               swap (array[end],array[j])

               decrease i by 1;

           }

       }

swap (array[i] , array[end])

       return partition index i;

}

You might be interested in
You have just built a new system from scratch. you turn the computer on but the system boot fails and sounds a beep code. what m
IgorLugansk [536]
The issue would be that the memory was not installed or was not detected by the system. If this happens, the system boot will fail and a beep code is heard. The system would not show anything since all of the software are in the memory which was not installed or detected.
4 0
3 years ago
Which of the following is NOT an advantage of owning a car?
AnnyKZ [126]

Smaller down and monthly payments than leasing a car

Option A.

<u>Explanation:</u>

If you lease a car, then the amount of money that a person has to pay in the form of monthly payments and installments is less when compared to when a person owns a car.

When you own a car, the monthly payment made is more than the monthly payments compared to when the car has to be leased. This is the disadvantage of owning a car, that the payment is more to be made.

8 0
3 years ago
Who benefits the most from billing by the second for cloud resources, such as virtual machines?.
scoundrel [369]

Clients that run numerous virtual machines.

<h3>What is a virtual machine?</h3>
  • A virtual machine is the virtualization or emulation of a computer system in computing.
  • The functionality of a physical computer is provided by virtual machines, which are built on computer architectures.
  • Their use may necessitate specialized hardware, software, or a combination of both.
  • Virtual machines' primary function is the simultaneous operation of several operating systems on a single piece of hardware.
  • Without virtualization, running two different physical units would be necessary to run different operating systems, such as Windows and Linux.
  • Through the use of virtualization technologies, virtual machines are made possible.
  • Multiple virtual machines (VMs) can run on a single machine thanks to virtualization, which simulates virtual hardware using software.
  • The real machine is referred to as the host, and any virtual machines running on it as the guests.

To learn more about virtual machines, refer to:

brainly.com/question/27961159

#SPJ4

7 0
1 year ago
Which smb share option should you enable if you don't want users to see files they don't have at least read permission to?
BigorU [14]
Enable all of them. have a nice day


5 0
3 years ago
A company has a popular gaming platform running on AWS. The application is sensitive to latency because latency can impact the u
AysviL [449]
Yetwywywywywywyyw would
8 0
2 years ago
Other questions:
  • Branching is so called because <br>​
    5·2 answers
  • When are numbered lists generally used?
    14·2 answers
  • In what decade did the Internet begin to be used widely by the public and not just government entities?
    5·2 answers
  • The United States is the only country in the world in which organs and tissue transplants are performed. True or False?
    8·1 answer
  • Which of the following is a step in paraphrasing? Skim the original information to get a sense of what it is about. Select a few
    15·2 answers
  • What is the purpose of the domain name​
    5·1 answer
  • How do you go about inserting additional worksheets into a workbook?
    15·1 answer
  • In an oblique drawing, which lines can be measured accurately, if there is no foreshortening?
    10·1 answer
  • WIRELESS DATA TRANSMISSION METHODS​
    8·1 answer
  • Imagine that you wanted to write a program that asks the user to enter in 5 grade values. The user may or may not enter valid gr
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!