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
Which of the following is part of Connections Academy's AUP regarding the use of the school'supplied technology
sergey [27]
A)technology supplied by connections should only be used for school purposes
6 0
3 years ago
Read 2 more answers
I analyze data, as a consultant, for companies making important business decisions. In order to get my point across, which of th
ladessa [460]

Answer:

3

Explanation:

I've just taken the test and made a 100. 3 is the most logical answer aswell, it has more of an effect than the others.

4 0
3 years ago
Which of the following savings vehicles usually requires a high minimum balance
GuDViN [60]
A Savings Vehicle is an effective way to hold your savings. It could be a savings account. But some requires a high minimum balance such as Certificate of Deposit (CD). It is generally issued by commercial banks.  It is a time deposit too and restricts you from withdrawing funds.
7 0
3 years ago
List five things that could cause premature bearing failure
Wewaii [24]
Smoking, Drinking, Use of drugs, problems with uterus, Problems with cervix or placenta.


6 0
2 years ago
In order to send a photo in a text message from your cell phone to your cousin's cell phone who lives in New Zealand, is it nece
Nata [24]

Answer: No, because all you need is WiFi for both devices and a messaging app to do it for free like iMessage.

Explanation: Please correct me if I am wrong! :)

8 0
2 years ago
Other questions:
  • All of the following are parts of the word processing window except _____. \
    9·1 answer
  • Which of the following is not a job title associated with a career in visual and audio technology? master control operator produ
    9·1 answer
  • Which one of the following is not possible to view in the debug logs?
    8·1 answer
  • Define Class in C++. Briefly discuss.
    9·1 answer
  • E-mail has made it very easy to send a message to more than one person at any time of day from just about anywhere. If you wante
    12·2 answers
  • Enum Digits {0, 1};
    10·1 answer
  • Attackers need a certain amount of information before launching their attack. One common place to find information is to go thro
    11·1 answer
  • An ip address in the address range 169.254.x.y, used by a computer when it cannot successfully lease an ip address from a dhcp s
    6·1 answer
  • Code Problem 3 in Python 2.
    5·1 answer
  • What are the difference among the whole note, half note and quarter note ? (this is music)
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!