Question
You have n pairs of nuts and bolts (the bolts screw into the nuts) that have been dropped onto a table with the nuts on
You have n pairs of nuts and bolts (the bolts screw into the nuts) that have been dropped onto a table with the nuts on one side and the bolts on another side; however you cannot tell whether one nut is bigger than another nut or whether one bolt is bigger than another bolt. You can attempt to screw a bolt into a nut and this will tell you either that the nut matches the bolt, or that the bolt is too large or too small for the nut. Call this a nut/bolt comparison. Give a randomized algorithm that will match all nuts with their corresponding bolts with expected O(n log n) number of nut/bolt comparisons.
Hint: does this problem look similar to QuickSort?
Please give a complete answer and also please don't copy and paste other answers because they are wrong thanks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started