The nuts and bolts problem is defined as follows. You are given a collection of n bolts of different widths, and n corresponding nuts.
View the step-by-step solution to:

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.

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
• -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents