You are given a collection of n bolts of different widths and n corresponding nuts. You are allowed to try a nut and bolt together, from which you can determine whether the nut is larger than the bolt, smaller than the bolt, or matches the bolt exactly. However, there is no way to compare two nuts together or two bolts together. The problem is to match each bolt to each nut. Design an algorithm for this problem with Θ(n log n) average-case complexity (in terms of nut-bolt comparisons). Explain why your algorithm has Θ(n log n) average-case complexity. You may use any result given in class without explicitly solving recurrence equations. I know that one can use Quicksort to get nlogn but I just don't know how to implement it. Thank you so much.
You are given a collection of n bolts of different widths and n corresponding nuts. You
are allowed to try a nut and bolt together, from which you can determine whether the
nut is larger than the bolt, smaller than the bolt, or matches the bolt exactly. However,
there is no way to compare two nuts together or two bolts together. The problem is
to match each bolt to each nut.
Design an
Explain why your algorithm has Θ(n log n) average-case complexity. You may use any result given in class without explicitly solving recurrence equations.
I know that one can use Quicksort to get nlogn but I just don't know how to implement it.
Thank you so much.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images