, Volume 69, Issue 2, pp 294–314 | Cite as

Necklaces, Convolutions, and X+Y

  • David Bremner
  • Timothy M. Chan
  • Erik D. Demaine
  • Jeff Erickson
  • Ferran Hurtado
  • John Iacono
  • Stefan Langerman
  • Mihai Pǎtraşcu
  • Perouz Taslakian


We give subquadratic algorithms that, given two necklaces each with n beads at arbitrary positions, compute the optimal rotation of the necklaces to best align the beads. Here alignment is measured according to the p norm of the vector of distances between pairs of beads from opposite necklaces in the best perfect matching. We show surprisingly different results for p=1, p even, and p=∞. For p even, we reduce the problem to standard convolution, while for p=∞ and p=1, we reduce the problem to (min,+) convolution and \((\operatorname {median},+)\) convolution. Then we solve the latter two convolution problems in subquadratic time, which are interesting results in their own right. These results shed some light on the classic sorting X+Y problem, because the convolutions can be viewed as computing order statistics on the antidiagonals of the X+Y matrix. All of our algorithms run in o(n 2) time, whereas the obvious algorithms for these problems run in Θ(n 2) time.


Necklace alignment Cyclic swap distance Convolution Sorting X+Y All pairs shortest paths 



This work was initiated at the 20th Bellairs Winter Workshop on Computational Geometry held January 28–February 4, 2005. We thank the other participants of that workshop—Greg Aloupis, Justin Colannino, Mirela Damian-Iordache, Vida Dujmović, Francisco Gomez-Martin, Danny Krizanc, Erin McLeish, Henk Meijer, Patrick Morin, Mark Overmars, Suneeta Ramaswami, David Rappaport, Diane Souvaine, Ileana Streinu, David Wood, Godfried Toussaint, Remco Veltkamp, and Sue Whitesides—for helpful discussions and contributing to a fun and creative atmosphere. We particularly thank the organizer, Godfried Toussaint, for posing the problem to us. The last author would also like to thank Luc Devroye for pointing out the easy generalization of the 2 necklace alignment problem to p for any fixed even integer p.


  1. 1.
    Aloupis, G., Fevens, T., Langerman, S., Matsui, T., Mesa, A., Nuñez, Y., Rappaport, D., Toussaint, G.: Algorithms for computing geometric measures of melodic similarity. J. Comput. Music 30(3), 67–76 (2006) CrossRefGoogle Scholar
  2. 2.
    Ardila, Y.J.P., Clifford, R., Iliopoulos, C.S., Landau, G.M., Mohamed, M.: Necklace swap problem for rhythmic similarity measures. Int. J. Comput. Methods 5(3), 351–363 (2008) CrossRefzbMATHMathSciNetGoogle Scholar
  3. 3.
    Baran, I., Demaine, E.D., Pǎtraşcu, M.: Subquadratic algorithms for 3SUM. Algorithmica 50(4), 584–596 (2008). Special issue of selected papers from the 9th Workshop on Algorithms and Data Structures, 2005 CrossRefzbMATHMathSciNetGoogle Scholar
  4. 4.
    Bellman, R., Karush, W.: Mathematical programming and the maximum transform. J. Soc. Ind. Appl. Math. 10(3), 550–567 (1962) CrossRefzbMATHMathSciNetGoogle Scholar
  5. 5.
    Bernstein, D.J.: Fast multiplication and its applications. In: Buhler, J., Stevenhagen, P. (eds.) Algorithmic Number Theory. MSRI Publications, vol. 44 (2008) Google Scholar
  6. 6.
    Blum, M., Floyd, R.W., Pratt, V., Rivest, R.L., Tarjan, R.E.: Time bounds for selection. J. Comput. Syst. Sci. 7(4), 448–461 (1973) CrossRefzbMATHMathSciNetGoogle Scholar
  7. 7.
    Bussieck, M., Hassler, H., Woeginger, G.J., Zimmermann, U.T.: Fast algorithms for the maximum convolution problem. Oper. Res. Lett. 15(3), 133–141 (1994) CrossRefzbMATHMathSciNetGoogle Scholar
  8. 8.
    Cardinal, J., Kremer, S., Langerman, S.: Juggling with pattern matching. Theory Comput. Syst. 39(3), 425–437 (2006) CrossRefzbMATHMathSciNetGoogle Scholar
  9. 9.
    Chan, T.M.: All-pairs shortest paths with real weights in O(n 3/logn) time. Algorithmica 50, 236–243 (2008) CrossRefzbMATHMathSciNetGoogle Scholar
  10. 10.
    Chan, T.M.: More algorithms for all-pairs shortest paths in weighted graphs. SIAM J. Comput. 39, 2075–2089 (2010) CrossRefzbMATHMathSciNetGoogle Scholar
  11. 11.
    Clifford, P., Clifford, R.: Self-normalised distance with don’t cares. In: Ma, B., Zhang, K. (eds.) Combinatorial Pattern Matching. Lecture Notes in Computer Science, vol. 4580, pp. 63–70. Springer, Berlin (2007) CrossRefGoogle Scholar
  12. 12.
    Clifford, P., Clifford, R.: Simple deterministic wildcard matching. Inf. Process. Lett. 101(2), 53–54 (2007) CrossRefzbMATHMathSciNetGoogle Scholar
  13. 13.
    Clifford, P., Clifford, R., Iliopoulos, C.: Fourier transform methods for δ and (δ,γ) matching and other measures of string similarity. Tech. Rep. TR-04-09, King’s College, London (2004) Google Scholar
  14. 14.
    Clifford, P., Clifford, R., Iliopoulos, C.: Faster algorithms for δ, γ-matching and related problems. In: Combinatorial Pattern Matching. Lecture Notes in Computer Science, vol. 3537, pp. 71–90. Springer, Berlin (2005) CrossRefGoogle Scholar
  15. 15.
    Cohn, H., Kleinberg, R., Szegedy, B., Umans, C.: Group-theoretic algorithms for matrix multiplication. In: Proceedings of the 46th Annual IEEE Symposium on Foundations of Computer Science, pp. 379–388 (2005) Google Scholar
  16. 16.
    Colannino, J., Damian, M., Hurtado, F., Iacono, J., Meijer, H., Ramaswami, S., Toussaint, G.: An O(nlogn)-time algorithm for the restriction scaffold assignment. J. Comput. Biol. 13(4), 979–989 (2006) CrossRefMathSciNetGoogle Scholar
  17. 17.
    Cole, R., Hariharan, R.: Verifying candidate matches in sparse and wildcard matching. In: Proceedings of the 34th Annual ACM Symposium on Theory of Computing, Montréal, Canada, pp. 592–601 (2002) Google Scholar
  18. 18.
    Cooley, J.W., Tukey, J.W.: An algorithm for the machine calculation of complex Fourier series. Math. Comput. 19, 297–301 (1965) CrossRefzbMATHMathSciNetGoogle Scholar
  19. 19.
    Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 2nd edn. MIT Press, Cambridge (2001) zbMATHGoogle Scholar
  20. 20.
    Demaine, E.D., Mitchell, J.S.B., O’Rourke, J.: Problem 41: Sorting X+Y (pairwise sums). In: The Open Problems Project (2006). Google Scholar
  21. 21.
    Demaine, E.D., O’Rourke, J.: Open problems from CCCG 2005. Proceedings of the 18th Canadian Conference on Computational Geometry, Kingston, Canada (2006) Google Scholar
  22. 22.
    Díaz-Báñez, J.M., Farigu, G., Gómez, F., Rappaport, D., Toussaint, G.T.: El compás flamenco: a phylogenetic analysis. In: Proceedings of BRIDGES: Mathematical Connections in Art, Music, and Science, Winfield, KS, pp. 61–70 (2004) Google Scholar
  23. 23.
    Erickson, J.: Lower bounds for linear satisfiability problems. Chic. J. Theor. Comput. Sci. 8 (1999) Google Scholar
  24. 24.
    Felzenszwalb, P.F., Huttenlocher, D.P.: Distance transforms of sampled functions. Tech. Rep. TR2004-1963, Faculty of Computing and Information Science, Cornell University (2004) Google Scholar
  25. 25.
    Fischer, M.J., Paterson, M.S.: String-matching and other products. In: Complexity of computation. SIAM-AMS Proceedings, vol. VII, pp. 113–125. Am. Math. Soc., New York (1974) Google Scholar
  26. 26.
    Frederickson, G.N., Johnson, D.B.: The complexity of selection and ranking in X+Y and matrices with sorted columns. J. Comput. Syst. Sci. 24(2), 197–208 (1982) CrossRefzbMATHMathSciNetGoogle Scholar
  27. 27.
    Fredman, M.L.: How good is the information theory bound in sorting? Theor. Comput. Sci. 1(4), 355–361 (1976) CrossRefzbMATHMathSciNetGoogle Scholar
  28. 28.
    Fredman, M.L.: New bounds on the complexity of the shortest path problem. SIAM J. Comput. 5(1), 83–89 (1976) CrossRefzbMATHMathSciNetGoogle Scholar
  29. 29.
    Gauss, C.F.: Werke, vol. 3. Königlichen Gesellschaft der Wissenschaften, Göttingen (1866) Google Scholar
  30. 30.
    Heideman, M.T., Johnson, D.H., Burrus, C.S.: Gauss and the history of the fast Fourier transform. Arch. Hist. Exact Sci. 34(3), 265–277 (1985) CrossRefzbMATHMathSciNetGoogle Scholar
  31. 31.
    Indyk, P.: Faster algorithms for string matching problems: Matching the convolution bound. In: Proceedings of the 39th Annual Symposium on Foundations of Computer Science, Palo Alto, CA, pp. 166–173 (1998) Google Scholar
  32. 32.
    Kalai, A.: Efficient pattern-matching with don’t cares. In: Proceedings of the 13th Annual ACM-SIAM Symposium on Discrete Algorithms, San Francisco, CA, pp. 655–656 (2002) Google Scholar
  33. 33.
    Maragos, P.: Differential morphology. In: Mitra, S., Sicuranza, G. (eds.) Nonlinear Image Processing, pp. 289–329. Academic Press, New York (2000) Google Scholar
  34. 34.
    Moreau, J.J.: Inf-convolution, sous-additivité, convexité des fonctions numériques. J. Math. Pures Appl., Neuv. Sér. 49, 109–154 (1970) zbMATHMathSciNetGoogle Scholar
  35. 35.
    Rockafellar, R.T.: Convex Analysis. Princeton Mathematical Series. Princeton University Press, Princeton (1970) zbMATHGoogle Scholar
  36. 36.
    Schönhage, A., Paterson, M., Pippenger, N.: Finding the median. J. Comput. Syst. Sci. 13(2), 184–199 (1976) CrossRefzbMATHGoogle Scholar
  37. 37.
    Steiger, W.L., Streinu, I.: A pseudo-algorithmic separation of lines from pseudo-lines. Inf. Process. Lett. 53(5), 295–299 (1995) CrossRefzbMATHMathSciNetGoogle Scholar
  38. 38.
    Strömberg, T.: The operation of infimal convolution. Diss. Math. 352, 58 (1996) Google Scholar
  39. 39.
    Toussaint, G.: The geometry of musical rhythm. In: Revised Papers from the Japan Conference on Discrete and Computational Geometry, Tokyo, Japan. Lecture Notes in Computer Science, vol. 3742, pp. 198–212 (2004) CrossRefGoogle Scholar
  40. 40.
    Toussaint, G.T.: A comparison of rhythmic similarity measures. In: Proceedings of the 5th International Conference on Music Information Retrieval, Barcelona, Spain, pp. 242–245 (2004) A longer version appears as Technical Report SOCS-TR-2004.6, School of Computer Science, McGill University, August 2004 Google Scholar

Copyright information

© Springer Science+Business Media New York 2012

Authors and Affiliations

  • David Bremner
    • 1
  • Timothy M. Chan
    • 2
  • Erik D. Demaine
    • 3
  • Jeff Erickson
    • 4
  • Ferran Hurtado
    • 5
  • John Iacono
    • 6
  • Stefan Langerman
    • 7
  • Mihai Pǎtraşcu
    • 8
  • Perouz Taslakian
    • 9
  1. 1.Faculty of Computer ScienceUniversity of New BrunswickFrederictonCanada
  2. 2.School of Computer ScienceUniversity of WaterlooWaterlooCanada
  3. 3.Computer Science and Artificial Intelligence LaboratoryMassachusetts Institute of TechnologyCambridgeUSA
  4. 4.Computer Science DepartmentUniversity of IllinoisUrbana-ChampaignUSA
  5. 5.Departament de Matemàtica Aplicada IIUniversitat Politècnica de CatalunyaBarcelonaSpain
  6. 6.Department of Computer and Information SciencePolytechnic UniversityBrooklynUSA
  7. 7.Directeur de Recherches du FRS-FNRS, Départment d’InformatiqueUniversité Libre de BruxellesBrusselsBelgium
  8. 8.AT&T Labs—ResearchFlorham ParkUSA
  9. 9.College of Science and EngineeringAmerican University of ArmeniaYerevanArmenia

Personalised recommendations