Question: Here is a variation on sorting. The problem is to sort a collection of n nuts and n bolts by size. It is assumed that
Here is a variation on sorting. The problem is to sort a collection of n nuts and n bolts by size. It is assumed that for each bolt in the collection, there is a corresponding nut of the same size, but initially we do not know which nut goes with which bolt. The differences in size between two nuts or two bolts can be too small to see by eye, so you cannot rely on comparing the sizes of two nuts or two bolts directly. Instead, you can only compare the sizes of a nut and a bolt by attempting to screw one into the other (assume this comparison to be a constant time operation). This operation tells you that either the nut is bigger than the bolt, the bolt is bigger than the nut, or they are the same size. What is the minimum number of comparisons needed to sort the nuts and bolts in the worst case?
Step by Step Solution
3.43 Rating (159 Votes )
There are 3 Steps involved in it
This problem is known as the Nuts and Bolts problem and one way to solve it uses a variation of the ... View full answer
Get step-by-step solutions from verified subject matter experts
