We consider the problem of transforming a list L of records sorted on some key into two sublists L 1 and L 2 where, for each distinct key in L, L 1 contains the first record of L that possesses the key and L 2 contains all records of L with duplicate keys. We desire that our duplicate-key extraction algorithm perform the transformation in place and be stable (that is, records within each sublist must obey the original order given by L). This operation is useful in database and related file processing environments whenever only distinct keys need be considered. Moreover, stability in extraction insures that L can be efficiently restored at a later time with a stable merge of L 1 and L 2. Any procedure for performing duplicate-key extraction on a list of size n must require at least O(n) time and O(1) extra space, although the obvious algorithm for achieving either bound alone violates the other bound. We design a stable algorithm, using block-rearrangement techniques, and show that it is optimal in the theoretical sense that it achieves both lower bounds simultaneously. We also prove that its worst-case number of key comparisons and record exchanges sum to no more than 6 n, suggesting that the algorithm has practical application as well.
This is a preview of subscription content, access via your institution.
Buy single article
Instant access to the full article PDF.
Price excludes VAT (USA)
Tax calculation will be finalised during checkout.
Huang, B.-C, Langston, M.A.: Stable Duplicate-Key Extraction with Optimal Time and Space Bounds. Proc. 24th Allerton Conf. Commun. Control Comput., pp. 288–295, 1986
Huang, B.-C., Langston, M.A.: Practical In-Place Merging. Commun. ACM 31, 348–352 (1988)
Huang, B.-C., Langston, M.A.: Stable Set and Multiset Operations in Optimal Time and Space. Proc. 7th ACM Symp. Principles Database Syst. pp. 288–293, 1988
Huang, B.-C., Langston, M.A.: Fast Stable Merging and Sorting in Constant Extra Space. Computer Science Department Technical Report CS-87-170, Washington State University, 1987
Horvath, E.C.: Stable Sorting in Asymptotically Optimal Time and Extra Space. J. ACM 25, 177–199 (1978)
Knuth, D.E.: The Art of Computer Programming, Vol. 3: Sorting and Searching. Reading, MA: Addison-Wesley 1973
Kronrod, M.A.: An Optimal Ordering Algorithm Without a Field of Operation. Dok. Akad, Nauk SSSR 186, 1256–1258 (1969)
Mannila, H., Ukkonen, E.: A Simple Linear-Time Algorithm for In Situ Merging. Inf. Proc. Lett. 18, 203–208 (1984)
Salowe, J.S., Steiger, W.L.: Stable Unmerging in Linear Time and Constant Space. Computer Science Department Technical Report, Rutgers University, 1985
Salowe, J.S., Steiger, W.L.: Simplified Stable Merging Tasks. J. Algorithms 8, 557–571 (1987)
Trabb Pardo, L.: Stable Sorting and Merging with Optimal Space and Time Bounds. SIAM J. Comput. 6, 351–372 (1977)
This author's research has been supported in part by the Washington State University Graduate Research Assistantship Program
This author's research has been supported in part by the National Science Foundation under grants ECS-8403859 and MIP-8603879, and by the Office of Naval Research under contract N0001488-K-0343
About this article
Cite this article
Huang, B.C., Langston, M.A. Stable duplicate-key extraction with optimal time and space bounds. Acta Informatica 26, 473–484 (1989). https://doi.org/10.1007/BF00289147