Question

# The nuts and bolts problem is defined as follows. You are given a collection of n bolts of different widths, and n

corresponding nuts. You can test whether a given nut and bolt together, from which you learn whether the nut is too large, too small, or an exact match for the bolt. The differences in size between pairs of nuts or bolts can be too small to see by eye, so you cannot rely on comparing the sizes of two nuts or two bolts directly. You are to match each bolt to each nut.

1. Give an O(n 2 ) algorithm to solve the nuts and bolts problem.

2. Suppose that instead of matching all of the nuts and bolts, you wish to find the smallest bolt and its corresponding nut. Show that this can be done in only 2n − 2 comparisons.

3. Match the nuts and bolts in expected O(n log n) time.

### Recently Asked Questions

- Utilizing an array or vector, write a program that accept 20 numbers from the user (numbers can range from -100 to 100) OR 20 random numbers(numbers can range

- What would be the output for the following code? Example 1. my_list = ['p','r','o','b','e'] print(my_list[-1]) print(my_list[-5]) Example 2 odd = [2, 4, 6, 8]

- Please refer to the attachment to answer this question. This question was created from Take Test.docx.