Matching nuts and bolts in O(n log n) time

Given a set of n nuts of distinct widths and a set of n bolts such that each nut corresponds to a unique bolt of the same width, how should we match every nut with its corresponding bolt by comparing nuts with bolts? (No comparison is allowed between two nuts or two bolts.) The problem can be natura...

Full description

Saved in:
Bibliographic Details
Published inSIAM journal on discrete mathematics Vol. 11; no. 3; pp. 347 - 372
Main Authors KOMLOS, J, UAN MA, SZEMEREDI, E
Format Journal Article
LanguageEnglish
Published Philadelphia, PA Society for Industrial and Applied Mathematics 01.08.1998
Subjects
Online AccessGet full text

Cover

Loading…
More Information
Summary:Given a set of n nuts of distinct widths and a set of n bolts such that each nut corresponds to a unique bolt of the same width, how should we match every nut with its corresponding bolt by comparing nuts with bolts? (No comparison is allowed between two nuts or two bolts.) The problem can be naturally viewed as a variant of the classic sorting problem as follows. Given two lists of n numbers each such that one list is a permutation of the other, how should we sort the lists by comparisons only between numbers in different lists? We give an O(n log n)-time deterministic algorithm for the problem. This is optimal up to a constant factor and answers an open question posed by Alon et al. [Proceedings of the 5th Annual ACM-SIAM Symposium on Discrete Algorithms, 1994, pp. 690--696]. Moreover, when copies of nuts and bolts are allowed, our algorithm runs in optimal O(log n) time on n processors in Valiant's parallel comparison tree model. Our algorithm is based on the AKS sorting algorithm with substantial modifications.
ISSN:0895-4801
1095-7146
DOI:10.1137/S0895480196304982