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
Refer to Table 8-4. Consider the data above (in billions of dollars) for an economy: Gross domestic product (in billions of doll
Whitepunk [10]

If one uses the data above (in billions of dollars), the Gross domestic product (in billions of dollars) for this economy equals  $1,200.

<h3>What is the GDP about?</h3>

Note that:

GDP (Gross Domestic Product):

Thus it will be :

Consumption + Investment + Government expenditure + (Export - Import)

Which is:

GDP = 800 + 200 + 300 + (100 - 200)

GDP = $1200 billions

See full question below

Consumption expenditures $800

Investment expenditures 200

Government purchases 300

Exports 100

Imports 200

Wages 800

8) Refer to Table above. Consider the data above (in billions of dollars) for an economy: Gross domestic product (in billions of dollars) for this economy equals

A) $2,200.

B) $1,600.

C) $1,400.

D) $1,200.

Learn more about GDP from

brainly.com/question/1383956

#SPJ1

6 0
1 year ago
A disadvantage of ethernet??
Blababa [14]
Ethernet is a wired internet connection. So, one obvious draw back is you can only go so far as your Ethernet cable will allow you.
3 0
3 years ago
Jeff has created a table to calculate the cost of raw materials that he purchases monthly. Cell A2 shows the fixed cost of the r
Luda [366]
=A2*D2
The above formula will allow calculation  of monthly cost of the first raw material.This is done by Multiplying the contents of cell A2 (Column A, Row 2) and cell D2 (Column D, Row 2). Here Cell A2 contains cost of the first raw material and Cell D2 contains number of units of the raw material produced  each month. After finding the monthly cost of the first raw material in this way, the monthly cost of other raw materials can simply be calculated by dragging down the formula to apply to the rows below.
3 0
3 years ago
Read 2 more answers
What would be the most popular piece of technology on Earth?
spin [16.1K]

Answer:

the smart phone

Explanation:

It is the most widley used and accepted

8 0
3 years ago
Read 2 more answers
What is Deep learning
vodomira [7]

Answer:

Deep learning is an AI function that mimics the workings of the human brain in processing data for use in detecting objects, recognizing speech, translating languages, and making decisions. Deep learning AI is able to learn without human supervision, drawing from data that is both unstructured and unlabeled.

3 0
3 years ago
Other questions:
  • The sum of all the minterms of a boolean function of n variables is equal to 1.
    7·1 answer
  • What is the purpose for the refresh button?
    10·2 answers
  • Is anyone really good at immerse 2 learn??
    9·1 answer
  • John has subscribed to a cloud-based service to synchronize data between his smartphone, tablet, and PC. Before allowing the dat
    10·1 answer
  • What is the positional weigh of the digit 7 in the octal number 7642 ?​
    15·1 answer
  • If you said the bottom margin, you are talking about what?
    13·2 answers
  • Add Try/Catch error checking To make sure that the user enters valid values in your program. To catch negative values passed to
    9·1 answer
  • How to make a project using PID and thermacouple
    11·1 answer
  • What do you hope will be in/added GTA 6?
    13·1 answer
  • You have received an update package for a critical application you are running on a virtual machine. You have been told to insta
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!