Andrej Brodnik Alejandro López-Ortiz Venkatesh Raman Alfredo Viola (Eds.) Festschrift Space-Efficient Data Structures, Streams,
LNCS 8066 and Algorithms Papers in Honor of J. Ian Munro on the Occasion of His 66th Birthday
123 Lecture Notes in Computer Science 8066 Commenced Publication in 1973 Founding and Former Series Editors: Gerhard Goos, Juris Hartmanis, and Jan van Leeuwen
Editorial Board David Hutchison Lancaster University, UK Takeo Kanade Carnegie Mellon University, Pittsburgh, PA, USA Josef Kittler University of Surrey, Guildford, UK Jon M. Kleinberg Cornell University, Ithaca, NY, USA Alfred Kobsa University of California, Irvine, CA, USA Friedemann Mattern ETH Zurich, Switzerland John C. Mitchell Stanford University, CA, USA Moni Naor Weizmann Institute of Science, Rehovot, Israel Oscar Nierstrasz University of Bern, Switzerland C. Pandu Rangan Indian Institute of Technology, Madras, India Bernhard Steffen TU Dortmund University, Germany Madhu Sudan Microsoft Research, Cambridge, MA, USA Demetri Terzopoulos University of California, Los Angeles, CA, USA Doug Tygar University of California, Berkeley, CA, USA Gerhard Weikum Max Planck Institute for Informatics, Saarbruecken, Germany Andrej Brodnik Alejandro López-Ortiz Venkatesh Raman Alfredo Viola (Eds.)
Space-Efficient Data Structures, Streams, and Algorithms
Papers in Honor of J. Ian Munro on the Occasion of His 66th Birthday
13 Volume Editors Andrej Brodnik University of Ljubljana, Faculty of Computer and Information Science Ljubljana, Slovenia and University of Primorska, Department of Information Science and Technology Koper, Slovenia E-mail: [email protected] Alejandro López-Ortiz University of Waterloo, Cheriton School of Computer Science Waterloo, ON, Canada E-mail: [email protected] Venkatesh Raman The Institute of Mathematical Sciences Chennai, India E-mail: [email protected] Alfredo Viola Universidad de la República, Facultad de Ingeniería Montevideo, Uruguay E-mail: viola@fing.edu.uy
ISSN 0302-9743 e-ISSN 1611-3349 ISBN 978-3-642-40272-2 e-ISBN 978-3-642-40273-9 DOI 10.1007/978-3-642-40273-9 Springer Heidelberg Dordrecht London New York
Library of Congress Control Number: 2013944678
CR Subject Classification (1998): F.2, E.1, G.2, H.3, I.2.8, E.5, G.1
LNCS Sublibrary: SL 1 – Theoretical Computer Science and General Issues
© Springer-Verlag Berlin Heidelberg 2013 This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher’s location, in ist current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Typesetting: Camera-ready by author, data conversion by Scientific Publishing Services, Chennai, India Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com) J. Ian Munro Preface
This volume contains research articles and surveys presented at Ianfest-66, a con- ference on space-efficient data structures, streams, and algorithms held during August 15–16, 2013, at the University of Waterloo, Canada. The conference was held to celebrate Ian Munro’s 66th birthday. Just like Ian’s interests, the articles in this volume encompass a spectrum of areas in- cluding sorting, searching, selection and several types of, and topics in, data structures including space-efficient ones. Ian Munro completed his PhD at the University of Toronto, around the time when computer science in general, and analysis of algorithms in particular, was maturing to be a field of research. His PhD thesis resulted in the classic book The Computational Complexity of Algebraic and Numeric Problems with his PhD supervisor Allan Borodin. He presented his first paper in STOC 1971, the same year and conference in which Stephen Cook (also from the same university) presented the paper on what we now call “NP-completeness.” Knuth’s first two volumes of The Art of Computer Programming were out, and the most influential third volume was to be released soon after. Hopcroft and Tarjan were developing important graph algorithms (for planarity, biconnected components etc). Against this backdrop, Ian started making fundamental contributions in sort- ing, selection and data structures (including optimal binary search trees, heaps and hashing). He steadfastly stayed focused on these subjects, always taking an expansive view, which included text search and data streams at a time when few others were exploring these topics. While the exact worst case comparison bound to find the median is still open, he closed this problem in 1984 along with his student Walter Cunto for the average case. His seminal work on implicit data structures with his student Hendra Suwanda marked his focus on space-efficient data structures. This was around the time of “megabyte” main memories, so space was becoming cheaper, though, as usual, the input sizes were becoming much larger. He saw early on that these trends will continue making the focus on space-efficiency more, rather than less, important. This trend has continued with the development of personal computing in its many forms and multilevel caches. His unique expertise helped contribute significantly to the Oxford English Dictionary (OED) project at Wa- terloo, and the founding of the OpenText as a company dealing with text-based algorithms. His invited contribution at the FSTTCS conference titled Tables brought the focus of work on succinct data structures in the years to come. His early work with Mike Paterson on selection is regarded as the first paper in a model that has later been called the “streaming model,” a model of intense study in the modern Internet age. In this model, his other paper “Frequency estimation of VIII Preface internet packet streams with limited space” with Erik Demaine and Alejandro L´opez-Ortiz has received over 300 citations. In addition to his research, Ian is an inspiring teacher. He has supervised (or co-supervised) over 20 PhD students and about double the number of Master’s students. For many years, Ian has been part of the faculty team that coached Canadian high school students for the International Olympiad in Informatics (IOI). He has led the Canadian team and served on the IOI’s international scientific committee. Ian also gets a steady stream of post-doctoral researchers and other visi- tors from throughout the world. He has served in many program committees of international conferences and in editorial boards of journals, and has given ple- nary talks at various international conferences. He has held visiting positions at several places including Princeton University, University of Washington, AT&T Bell Labaratories, University of Arizona, University of Warwick and Universit`e libre de Bruxelles. Through his students and their students and other collab- orators, he has helped establish strong research groups in various parts of the world including Chile, India, South Korea, Uruguay and in many parts of Eu- rope and North America. He also has former students in key positions in leading companies of the world. His research achievements have been recognized by his election as Fellow of the Royal Society of Canada (2003) and Fellow of the ACM (2008). He was made a University Professor in 2006. Ian has a great sense of generosity, wit and humor. Ian, his wife, Marilyn, and his children, Alison and Brian, are more than a host to his students and collaborators; they have helped establish a long-lasting friendship with them. At 66 Ian is going strong, makes extensive research tours, supervises many PhD students and continues to educate and inspire students and researchers. We wish him and his family many more years of fruitful and healthy life. We thank a number of people that made this volume possible. First and foremost, we thank all the authors who came forward to contribute their articles on a short notice, all anonymous referees, proofreaders, and the speakers at the conference. We thank Marko Grguroviˇc, Wendy Rush and Jan Vesel for collecting and verifying data about Ian’s students and work. We thank Alfred Hofmann, Anna Kramer and Ronan Nugent at Springer for their enthusiastic support and help in producing this Festschrift. We thank Alison Conway at Fields Institute at Toronto for maintaining the conference website and managing registration, and Fields Institute for their generous financial support, and University of Waterloo for their infrastructural and organizational support. This volume contains surveys on emerging, as well as established, fields in data structures and algorithms, written by leading experts, and we feel that it will become a book to cherish in the years to come.
June 2013 Andrej Brodnik Alejandro L´opez-Ortiz Venkatesh Raman Alfredo Viola Curriculum Vitae J. Ian Munro
Current Position
University Professor and Canada Research Chair in Algorithm Design
Address
Cheriton School of Computer Science University of Waterloo Waterloo, Ontario Canada, N2L 3G1 https://cs.uwaterloo.ca/~imunro/
Personal Information
Born: July 10, 1947 Married: to Marilyn Miller Two children: Alison and Brian
Education
Ph.D., Computer Science, University of Toronto, 1971 M.Sc., Computer Science, University of British Columbia, 1969 B.A. (Hons), Mathematics, University of New Brunswick, 1968
Experience
1971-present: Professor, University of Waterloo, Ontario, Canada
Professional Interests
Data structures, particularly fast and space-efficient structures. The design, analysis and implementation of algorithms. Bioinformatics. Database systems and data warehousing, particularly efficiency issues. X Curriculum Vitae J. Ian Munro
Co-authors 1. Brian Allen 45. Lukasz Golab 2. Stephen Alstrup 46. Mordecai Golin 3. Helmut Alt 47. Alexander Golynski 4. Lars Arge 48. Gast´on H. Gonnet 5. Diego Arroyuelo 49. Roberto Grossi 6. J´er´emy Barbay 50. Gwena¨el Joret 7. Michael A. Bender 51. Torben Hagerup 8. David Benoit 52. Ang`ele M. Hamel 9. Therese Biedl 53. E. R. Hansen 10. Allan Borodin 54. Nicholas J. A. Harvey 11. Prosenjit Bose 55. Meng He 12. Gerth Stølting Brodal 56. Bryan Holland-Minkley 13. Andrej Brodnik 57. John Iacono 14. Jean Cardinal 58. Lars Jacobsen 15. Svante Carlsson 59. X Richard Ji 16. Luca Castelli Aleardi 60. Rapha¨el M. Jungers 17. Pedro Celis 61. Kanela Kaligosi 18. Timothy Chan 62. T. Kameda 19. David R. Clark 63. Johan Karlsson 20. Francisco Claude 64. Rolf G. Karlsson 21. Gordon Cormack 65. Marek Karpinski 22. Joseph C. Culberson 66. Paul E. Kearney 23. Walter Cunto 67. Graeme Kemkes 24. David DeHaan 68. James A. King 25. Erik D. Demaine 69. Alejandro L´opez-Ortiz 26. Martin L. Demaine 70. Stefan Langerman 27. David P. Dobkin 71. Per-Ake˚ Larson 28. Reza Dorrigiv 72. Anna Lubiw 29. Stephane Durocher 73. Kurt Mehlhorn 30. Amr Elmasry 74. Peter Bro Miltersen 31. Martin Farach-Colton 75. Pat Morin 32. Arash Farzan 76. Moni Naor 33. Paolo Ferragina 77. Yakov Nekrich 34. Amos Fiat 78. Patrick K. Nicholson 35. Faith E. Fich 79. Andreas Nilsson 36. Jeremy T. Fineman 80. B. John Oommen 37. Samuel Fiorini 81. Mark H. Overmars 38. Rudolf Fleischer 82. Linda Pagli 39. Gianni Franceschini 83. Thomas Papadakis 40. Robert Fraser 84. Michael S. Paterson 41. Michael L. Fredman 85. Derek Phillips 42. Travis Gagie 86. Patricio V. Poblete 43. W. Morven Gentleman 87. M. Ziaur Rahman 44. Pedram Ghodsnia 88. Ra´ul J. Ram´ırez Curriculum Vitae J. Ian Munro XI
89. Rajeev Raman 103. Alan Siegel 90. Venkatesh Raman 104. Matthew Skala 91. Theis Rauhe 105. Philip M. Spira 92. Manuel Rey 106. Adam J. Storm 93. Edward L. Robertson 107. Hendra Suwanda 94. Doron Rotem 108. David J. Taylor 95. Alejandro Salinger 109. Mikkel Thorup 96. Jeffrey S. Salowe 110. Kamran Tirdad 97. Peter Sanders 111. Frank Wm. Tompa 98. Srinivasa Rao Satti 112. Troy Vasiga 99. Jeanette P. Schmidt 113. Alfredo Viola 100. Allen J. Schwenk 114. Derick Wood 101. Alejandro A. Sch¨affer 115. Gelin Zhou 102. Robert Sedgewick
Books and Book chapters
[1] Barbay, J., Munro, J.I.: Succinct encoding of permutations: Applications to text indexing. In: Kao, M.Y. (ed.) Encyclopedia of Algorithms, pp. 915–919. Springer (2008) [2] Borodin, A., Munro, J.I.: The computational complexity of algebraic and numeric problems. American Elsevier, New York (1975) [3] Munro, J.I., Satti, S.R.: Succinct representation of data structures. In: Mehta, D.P., Sahni, S. (eds.) Handbook of Data Structures and Applica- tions. Chapman & Hall/Crc Computer and Information Science Series, ch. 37. Chapman & Hall/CRC (2004)
Edited Proceedings
[4] Blum, M., Galil, Z., Ibarra, O.H., Kozen, D., Miller, G.L., Munro, J.I., Ruzzo, W.L. (eds.): SFCS 1983: Proceedings of the 24th Annual Sympo- sium on Foundations of Computer Science, p. iii. IEEE Computer Society, Washington, DC (1983) [5] Chwa, K.-Y., Munro, J.I. (eds.): COCOON 2004. LNCS, vol. 3106. Springer, Heidelberg (2004) [6] L´opez-Ortiz, A., Munro, J.I. (eds.): ACM Transactions on Algorithms 2(4), 491 (2006) [7] Munro, J.I. (ed.): Proceedings of the Fifteenth Annual ACM-SIAM Sympo- sium on Discrete Algorithms, SODA 2004, New Orleans, Louisiana, USA, January 11-14. SIAM (2004) XII Curriculum Vitae J. Ian Munro
Journal and Conference Papers
[8] Allen, B., Munro, J.I.: Self-organizing binary search trees. J. ACM 25(4), 526–535 (1978); A preliminary version appeared in SFCS 1976: Proceed- ings of the 17th Annual Symposium on Foundations of Computer Science, pp. 166–172. IEEE Computer Society, Washington, DC (1976) [9] Alt, H., Mehlhorn, K., Munro, J.I.: Partial match retrieval in implicit data structures. Inf. Process. Lett. 19(2), 61–65 (1984); A preliminary version appeared in Gruska, J., Chytil, M.P. (eds.): MFCS 1981. LNCS, vol. 118, pp. 156–161. Springer, Heidelberg (1981) [10] Arge, L., Bender, M.A., Demaine, E.D., Holland-Minkley, B., Ian Munro, J.I.: An optimal cache-oblivious priority queue and its application to graph algorithms. SIAM J. Comput. 36(6), 1672–1695 (2007) [11] Arge, L., Bender, M.A., Demaine, E.D., Holland-Minkley, B., Munro, J.I.: Cache-oblivious priority queue and graph algorithm applications. In: STOC 2002: Proceedings of the Thiry-Fourth Annual ACM Symposium on Theory of Computing, pp. 268–276. ACM, New York (2002) [12]Arroyuelo,D.,Claude,F.,Dorrigiv,R.,Durocher,S.,He,M.,L´opez-Ortiz, A., Ian Munro, J.I., Nicholson, P.K., Salinger, A., Skala, M.: Untangled monotonic chains and adaptive range search. Theor. Comput. Sci. 412(32), 4200–4211 (2011); A Preliminary Version Appeared in Dong, Y., Du, D.- Z., Ibarra, O. (eds.): ISAAC 2009. LNCS, vol. 5878, pp. 203–212. Springer, Heidelberg (2009) [13] Barbay, J., Castelli Aleardi, L., He, M., Munro, J.I.: Succinct represen- tation of labeled graphs. Algorithmica 62(1-2), 224–257 (2012); A Pre- liminary Version Appeared in Tokuyama, T. (ed.): ISAAC 2007. LNCS, vol. 4835, pp. 316–328. Springer, Heidelberg (2007) [14] Barbay, J., Golynski, A., Munro, J.I., Satti, S.R.: Adaptive searching in succinctly encoded binary relations and tree-structured documents. Theor. Comput. Sci. 387(3), 284–297 (2007); A Preliminary Version Appeared in Lewenstein, M., Valiente, G. (eds.): CPM 2006. LNCS, vol. 4009, pp. 24– 35. Springer, Heidelberg (2006) [15] Barbay, J., He, M., Munro, J.I., Satti, S.R.: Succinct indexes for strings, binary relations and multilabeled trees. ACM Trans. Algorithms 7(4), 1– 27 (2011); A Preliminary Version Appeared in SODA 2007: Proceedings of the Eighteenth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 680–689. Society for Industrial and Applied Mathematics, Philadelphia (2007) [16] Benoit, D., Demaine, E.D., Munro, J.I., Raman, R., Raman, V., Satti, S.R.: Representing trees of higher degree. Algorithmica 43(4), 275–292 (2005); A Preliminary Version Appeared in Dehne, F., Gupta, A., Sack, J.-R., Tamassia, R. (eds.): WADS 1999. LNCS, vol. 1663, pp. 169–180. Springer, Heidelberg (1999) [17] Biedl, T., Chan, T., Demaine, E.D., Fleischer, R., Golin, M., King, J.A., Munro, J.I.: Fun-sort – or the chaos of unordered binary search. Discrete Appl. Math. 144(3), 231–236 (2004) Curriculum Vitae J. Ian Munro XIII
[18] Biedl, T., Golynski, A., Hamel, A.M., L´opez-Ortiz, A., Munro, J.I.: Sorting with networks of data structures. Discrete Appl. Math. 158(15), 1579–1586 (2010) [19] Borodin, A., Munro, J.I.: Evaluating polynomials at many points. Inf. Process. Lett. 1(2), 66–68 (1971) [20] Bose, P., Brodnik, A., Carlsson, S., Demaine, E.D., Fleischer, R., L´opez- Ortiz, A., Morin, P., Munro, J.I.: Online routing in convex subdivisions. Int. J. Comput. Geometry Appl. 12(4), 283–296 (2002); A Preliminary Version Appeared in Lee, D.T., Teng, S.-H. (eds.): ISAAC 2000. LNCS, vol. 1969, pp. 47–59. Springer, Heidelberg (2000) [21] Bose, P., Lubiw, A., Munro, J.I.: Efficient visibility queries in simple poly- gons. Comput. Geom. Theory Appl. 23(3), 313–335 (2002) [22] Brodal, G.S., Demaine, E.D., Fineman, J.T., Iacono, J., Langerman, S., Munro, J.I.: Cache-oblivious dynamic dictionaries with update/query tradeoffs. In: SODA 2010: Proceedings of the Twenty-First Annual ACM- SIAM Symposium on Discrete Algorithms, pp. 1448–1456. Society for In- dustrial and Applied Mathematics, Philadelphia (2010) [23] Brodal, G.S., Demaine, E.D., Munro, J.I.: Fast allocation and deallocation with an improved buddy system. Acta Inf. 41(4-5), 273–291 (2005) [24] Brodnik, A., Carlsson, S., Demaine, E.D., Munro, J.I., Sedgewick, R.D.: Resizable arrays in optimal time and space. In: Dehne, F., Gupta, A., Sack, J.-R., Tamassia, R. (eds.) WADS 1999. LNCS, vol. 1663, pp. 37–48. Springer, Heidelberg (1999) [25] Brodnik, A., Carlsson, S., Fredman, M.L., Karlsson, J., Munro, J.I.: Worst case constant time priority queue. J. Syst. Softw. 78(3), 249–256 (2005); A Preliminary Version Appeared in SODA 2001: Proceedings of the Twelfth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 523–528. So- ciety for Industrial and Applied Mathematics, Philadelphia (2001) [26] Brodnik, A., Karlsson, J., Munro, J.I., Nilsson, A.: An O(1) solution to the prefix sum problem on a specialized memory architecture. In: IFIP TCS, pp. 103–114 (2006) [27] Brodnik, A., Miltersen, P.B., Munro, J.I.: Trans-dichotomous algorithms without multiplication - some upper and lower bounds. In: Rau-Chaplin, A., Dehne, F., Sack, J.-R., Tamassia, R. (eds.) WADS 1997. LNCS, vol. 1272, pp. 426–439. Springer, Heidelberg (1997) [28] Brodnik, A., Munro, J.I.: Membership in constant time and almost- minimum space. SIAM J. Comput. 28(5), 1627–1640 (1999); A Preliminary Version Appeared in van Leeuwen, J. (ed.): ESA 1994. LNCS, vol. 855, pp. 72–81. Springer, Heidelberg (1994) [29] Brodnik, A., Munro, J.I.: Neighbours on a grid. In: Karlsson, R., Lingas, A. (eds.) SWAT 1996. LNCS, vol. 1097, pp. 309–320. Springer, Heidelberg (1996) XIV Curriculum Vitae J. Ian Munro
[30] Cardinal, J., Fiorini, S., Joret, G., Jungers, R.M., Munro, J.I.: An efficient algorithm for partial order production. CoRR abs/0811.2572 (2008); A Preliminary Version Appeared in STOC 2009: Proceedings of the 41st Annual ACM Symposium on Theory of Computing, pp. 93–100. ACM, New York (2009) [31] Cardinal, J., Fiorini, S., Joret, G., Jungers, R.M., Munro, J.I.: An efficient algorithm for partial order production. SIAM J. Comput. 39(7), 2927–2940 (2010) [32] Cardinal, J., Fiorini, S., Joret, G., Jungers, R.M., Munro, J.I.: Sorting un- der partial information (without the ellipsoid algorithm). In: STOC 2010: Proceedings of the 42nd ACM Symposium on Theory of Computing, pp. 359–368. ACM, New York (2010) [33] Carlsson, S., Munro, J.I., Poblete, P.V.: An implicit binomial queue with constant insertion time. In: Karlsson, R., Lingas, A. (eds.) SWAT 1988. LNCS, vol. 318, pp. 1–13. Springer, Heidelberg (1988) [34] Celis, P., Larson, P.A.,˚ Munro, J.I.: Robin hood hashing. In: SFCS 1985: Proceedings of the 26th Annual Symposium on Foundations of Computer Science, pp. 281–288. IEEE Computer Society, Washington, DC (1985) [35] Clark, D.R., Munro, J.I.: Efficient suffix trees on secondary storage. In: SODA 1996: Proceedings of the Seventh Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 383–391. Society for Industrial and Applied Mathematics, Philadelphia (1996) [36] Claude, F., Munro, J.I., Nicholson, P.K.: Range queries over untangled chains. In: Chavez, E., Lonardi, S. (eds.) SPIRE 2010. LNCS, vol. 6393, pp. 82–93. Springer, Heidelberg (2010) [37] Cormack, G., Munro, J.I., Vasiga, T., Kemkes, G.: Structure, scoring and purpose of computing competitions. Informatics in education 5(1), 15–36 (2006) [38] Culberson, J.C., Munro, J.I.: Explaining the behaviour of binary search trees under prolonged updates: a model and simulations. Comput. J. 32(1), 68–75 (1989) [39] Culberson, J.C., Munro, J.I.: Analysis of the standard deletion algorithms in exact fit domain binary search trees. Algorithmica 5(3), 295–311 (1990) [40] Cunto, W., Gonnet, G.H., Munro, J.I., Poblete, P.V.: Fringe analysis for extquick: an in situ distributive external sorting algorithm. Inf. Com- put. 92(2), 141–160 (1991) [41] Cunto, W., Munro, J.I.: Average case selection. J. ACM 36(2), 270–279 (1989); A Preliminary Version Appeared in STOC 1984: Proceedings of the Sixteenth Annual ACM Symposium on Theory of Computing, pp. 369–375. ACM, New York (1984) [42] Cunto, W., Munro, J.I., Poblete, P.V.: A case study in comparison based complexity: Finding the nearest value(s). In: Dehne, F., Sack, J.-R., San- toro, N. (eds.) WADS 1991. LNCS, vol. 519, pp. 1–12. Springer, Heidelberg (1991) [43] Cunto, W., Munro, J.I., Rey, M.: Selecting the median and two quartiles in a set of numbers. Softw. Pract. Exper. 22(6), 439–454 (1992) Curriculum Vitae J. Ian Munro XV
[44] Demaine, E.D., L´opez-Ortiz, A., Munro, J.I.: Adaptive set intersections, unions, and differences. In: SODA 2000: Proceedings of the Eleventh An- nual ACM-SIAM Symposium on Discrete Algorithms, pp. 743–752. Society for Industrial and Applied Mathematics, Philadelphia (2000) [45] Demaine, E.D., L´opez-Ortiz, A., Munro, J.I.: Experiments on adaptive set intersections for text retrieval systems. In: Buchsbaum, A.L., Snoeyink, J. (eds.) ALENEX 2001. LNCS, vol. 2153, pp. 91–104. Springer, Heidelberg (2001) [46] Demaine, E.D., L´opez-Ortiz, A., Munro, J.I.: Frequency estimation of internet packet streams with limited space. In: M¨ohring, R.H., Raman, R. (eds.) ESA 2002. LNCS, vol. 2461, pp. 348–360. Springer, Heidelberg (2002) [47] Demaine, E.D., L´opez-Ortiz, A., Munro, J.I.: Robot localization without depth perception. In: Penttonen, M., Schmidt, E.M. (eds.) SWAT 2002. LNCS, vol. 2368, pp. 249–259. Springer, Heidelberg (2002) [48] Demaine, E.D., L´opez-Ortiz, A., Munro, J.I.: Note: on universally easy classes for NP-complete problems. Theor. Comput. Sci. 304(1-3), 471–476 (2003); A Preliminary Version Appeared in SODA 2001: Proceedings of the Twelfth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 910–911. Society for Industrial and Applied Mathematics, Philadelphia (2001) [49] Demaine, E.D., Munro, J.I.: Fast allocation and deallocation with an im- proved buddy system. In: Pandu Rangan, C., Raman, V., Sarukkai, S. (eds.) FST TCS 1999. LNCS, vol. 1738, pp. 84–96. Springer, Heidelberg (1999) [50] Dobkin, D.P., Munro, J.I.: Time and space bounds for selection problems. In: Ausiello, G., B¨ohm, C. (eds.) ICALP 1978. LNCS, vol. 62, pp. 192–204. Springer, Heidelberg (1978) [51] Dobkin, D.P., Munro, J.I.: Determining the mode. Theor. Comput. Sci. 12, 255–263 (1980) [52] Dobkin, D.P., Munro, J.I.: Optimal time minimal space selection algo- rithms. J. ACM 28(3), 454–461 (1981) [53] Dobkin, D.P., Munro, J.I.: Efficient uses of the past. J. Algorithms 6(4), 455–465 (1985); A Preliminary Version Appeared in SFCS 1980: Proceed- ings of the 21st Annual Symposium on Foundations of Computer Science, pp. 200–206. IEEE Computer Society, Washington, DC (1980) [54] Dorrigiv, R., Durocher, S., Farzan, A., Fraser, R., L´opez-Ortiz, A., Munro, J.I., Salinger, A., Skala, M.: Finding a hausdorff core of a polygon: On con- vex polygon containment with bounded hausdorff distance. In: Dehne, F., Gavrilova, M., Sack, J.-R., T´oth, C.D. (eds.) WADS 2009. LNCS, vol. 5664, pp. 218–229. Springer, Heidelberg (2009) [55] Dorrigiv, R., L´opez-Ortiz, A., Munro, J.I.: List update algorithms for data compression. In: DCC 2008: Proceedings of the Data Compression Con- ference, p. 512. IEEE Computer Society, Washington, DC (2008) XVI Curriculum Vitae J. Ian Munro
[56] Dorrigiv, R., L´opez-Ortiz, A., Munro, J.I.: An application of self-organizing data structures to compression. In: Vahrenhold, J. (ed.) SEA 2009. LNCS, vol. 5526, pp. 137–148. Springer, Heidelberg (2009) [57] Dorrigiv, R., L´opez-Ortiz, A., Munro, J.I.: On the relative dominance of paging algorithms. Theor. Comput. Sci. 410(38-40), 3694–3701 (2009). A Preliminary Version Appeared in Tokuyama, T. (ed.): ISAAC 2007. LNCS, vol. 4835, pp. 488–499. Springer, Heidelberg (2007) [58] Durocher, S., He, M., Munro, J.I., Nicholson, P.K., Skala, M.: Range ma- jority in constant time and linear space. Inf. Comput. 222, 169–179 (2013); A preliminary version appeared in Aceto, L., Henzinger, M., Sgall, J. (eds.): ICALP 2011, Part I. LNCS, vol. 6755, pp. 244–255. Springer, Heidelberg (2011) [59] Elmasry, A., He, M., Munro, J.I., Nicholson, P.K.: Dynamic range majority data structures. In: Asano, T., Nakano, S.-i., Okamoto, Y., Watanabe, O. (eds.) ISAAC 2011. LNCS, vol. 7074, pp. 150–159. Springer, Heidelberg (2011) [60] Farzan, A., Ferragina, P., Franceschini, G., Munro, J.I.: Cache-oblivious comparison-based algorithms on multisets. In: Brodal, G.S., Leonardi, S. (eds.) ESA 2005. LNCS, vol. 3669, pp. 305–316. Springer, Heidelberg (2005) [61] Farzan, A., Munro, J.I.: Succinct representation of finite abelian groups. In: ISSAC 2006: Proceedings of the 2006 International Symposium on Sym- bolic and Algebraic Computation, pp. 87–92. ACM, New York (2006) [62] Farzan, A., Munro, J.I.: Succinct representations of arbitrary graphs. In: Halperin, D., Mehlhorn, K. (eds.) ESA 2008. LNCS, vol. 5193, pp. 393–404. Springer, Heidelberg (2008) [63] Farzan, A., Munro, J.I.: A uniform approach towards succinct representa- tion of trees. In: Gudmundsson, J. (ed.) SWAT 2008. LNCS, vol. 5124, pp. 173–184. Springer, Heidelberg (2008) [64] Farzan, A., Munro, J.I.: Succinct representation of dynamic trees. Theor. Comput. Sci. 412(24), 2668–2678 (2011) [65] Farzan, A., Munro, J.I.: Dynamic succinct ordered trees. In: Albers, S., Marchetti-Spaccamela, A., Matias, Y., Nikoletseas, S., Thomas, W. (eds.) ICALP 2009, Part I. LNCS, vol. 5555, pp. 439–450. Springer, Heidelberg (2009) [66] Farzan, A., Munro, J.I.: A uniform paradigm to succinctly encode var- ious families of trees. Algorithmica, 1–25 (2012), http://dx.doi.org/ 10.1007/s00453-012-9664-0 [67] Farzan, A., Munro, J.I., Raman, R.: Succinct indices for range queries with applications to orthogonal range maxima. In: Czumaj, A., Mehlhorn, K., Pitts, A., Wattenhofer, R. (eds.) ICALP 2012, Part I. LNCS, vol. 7391, pp. 327–338. Springer, Heidelberg (2012) [68] Fiat, A., Munro, J.I., Naor, M., Sch¨affer, A.A., Schmidt, J.P., Siegel, A.: An implicit data structure for searching a multikey table in logarithmic time. J. Comput. Syst. Sci. 43(3), 406–424 (1991) Curriculum Vitae J. Ian Munro XVII
[69] Fich, F.E., Munro, J.I., Poblete, P.V.: Permuting in place. SIAM J. Com- put. 24(2), 266–278 (1995); A Preliminary Version Appeared in SFCS 1990: Proceedings of the 31st Annual Symposium on Foundations of Com- puter Science, vol.1, pp. 372–379, IEEE Computer Society, Washington, DC (1990) [70] Franceschini, G., Grossi, R., Munro, J.I., Pagli, L.: Implicit B-trees: a new data structure for the dictionary problem. J. Comput. Syst. Sci. 68(4), 788– 807 (2004); A Preliminary Version Appeared in FOCS 2002: Proceedings of the 43rd Symposium on Foundations of Computer Science, pp. 145–154. IEEE Computer Society, Washington, DC (2002) [71] Franceschini, G., Munro, J.I.: Implicit dictionaries with O(1) modifications per update and fast search. In: SODA 2006: Proceedings of the Seven- teenth Annual ACM-SIAM Symposium on Discrete Algorithm, pp. 404– 413. ACM, New York (2006) [72] Gagie, T., He, M., Munro, J.I., Nicholson, P.K.: Finding frequent elements in compressed 2D arrays and strings. In: Grossi, R., Sebastiani, F., Sil- vestri, F. (eds.) SPIRE 2011. LNCS, vol. 7024, pp. 295–300. Springer, Heidelberg (2011) [73] Gentleman, W.M., Munro, J.I.: Designing overlay structures. Softw. Pract. Exper. 7(4), 493–500 (1977) [74] Ghodsnia, P., Tirdad, K., Munro, J.I., L´oez-Ortiz, A.: A novel approach for leveraging co-occurrence to improve the false positive error in signature files. J. of Discrete Algorithms 18, 63–74 (2013) [75] Golab, L., DeHaan, D., Demaine, E.D., L´opez-Ortiz, A., Munro, J.I.: Iden- tifying frequent items in sliding windows over on-line packet streams. In: IMC 2003: Proceedings of the 3rd ACM SIGCOMM Conference on Inter- net Measurement, pp. 173–178. ACM, New York (2003) [76] Golynski, A., Munro, J.I., Satti, S.R.: Rank/select operations on large alphabets: a tool for text indexing. In: SODA 2006: Proceedings of the Seventeenth Annual ACM-SIAM Symposium on Discrete Algorithm, pp. 368–373. ACM, New York (2006) [77] Gonnet, G.H., Larson, P.A.,˚ Munro, J.I., Rotem, D., Taylor, D.J., Tompa, F.W.: Database storage structures research at the University of Waterloo. IEEE Database Eng. Bull. 5(1), 49–52 (1982) [78] Gonnet, G.H., Munro, J.I.: Efficient ordering of hash tables. SIAM J. Com- put. 8(3), 463–478 (1979) [79] Gonnet, G.H., Munro, J.I.: A linear probing sort and its analysis. In: STOC 1981: Proceedings of the Thirteenth Annual ACM Symposium on Theory of Computing, pp. 90–95. ACM, New York (1981) [80] Gonnet, G.H., Munro, J.I.: The analysis of an improved hashing technique. In: STOC 1977: Proceedings of the Ninth Annual ACM Symposium on Theory of Computing, pp. 113–121. ACM, New York (1977) [81] Gonnet, G.H., Munro, J.I.: The analysis of linear probing sort by the use of a new mathematical transform. J. Algorithms 5(4), 451–470 (1984) XVIII Curriculum Vitae J. Ian Munro
[82] Gonnet, G.H., Munro, J.I.: Heaps on heaps. SIAM J. Comput. 15(4), 964– 971 (1986); A Preliminary Version Appeared in Nielsen, M., Schmidt, E.M. (eds.): ICALP 1982. LNCS, vol. 140, pp. 282–291. Springer, Heidelberg (1982) [83] Gonnet, G.H., Munro, J.I., Suwanda, H.: Toward self-organizing linear search. In: SFCS 1979: Proceedings of the 20th Annual Symposium on Foundations of Computer Science, pp. 169–174. IEEE Computer Society, Washington, DC (1979) [84] Gonnet, G.H., Munro, J.I., Suwanda, H.: Exegesis of self-organizing linear search. SIAM J. Comput. 10(3), 613–637 (1981) [85] Gonnet, G.H., Munro, J.I., Wood, D.: Direct dynamic structures for some line segment problems. Computer Vision, Graphics, and Image Process- ing 23(2), 178–186 (1983) [86] Hagerup, T., Mehlhorn, K., Munro, J.I.: Maintaining discrete probability distributions optimally. In: Lingas, A., Carlsson, S., Karlsson, R. (eds.) ICALP 1993. LNCS, vol. 700, pp. 253–264. Springer, Heidelberg (1993) [87] Harvey, N.J.A., Munro, J.I.: Deterministic skipnet. Inf. Process. Lett. 90(4), 205–208 (2004); A Preliminary Version Appeared in PODC 2003: Proceedings of the Twenty-Second Annual Symposium on Princi- ples of Distributed Computing, pp. 152–152. ACM, New York(2003) [88] He, M., Munro, J.I.: Succinct representations of dynamic strings. In: Chavez, E., Lonardi, S. (eds.) SPIRE 2010. LNCS, vol. 6393, pp. 334–346. Springer, Heidelberg (2010) [89] He, M., Munro, J.I.: Space efficient data structures for dynamic orthogonal range counting. In: Dehne, F., Iacono, J., Sack, J.-R. (eds.) WADS 2011. LNCS, vol. 6844, pp. 500–511. Springer, Heidelberg (2011) [90] He, M., Munro, J.I., Nicholson, P.K.: Dynamic range selection in linear space. In: Asano, T., Nakano, S.-i., Okamoto, Y., Watanabe, O. (eds.) ISAAC 2011. LNCS, vol. 7074, pp. 160–169. Springer, Heidelberg (2011) [91] He, M., Munro, J.I., Satti, S.R.: A categorization theorem on suffix ar- rays with applications to space efficient text indexes. In: SODA 2005: Proceedings of the Sixteenth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 23–32. Society for Industrial and Applied Mathematics, Philadelphia (2005) [92] He, M., Munro, J.I., Satti, S.R.: Succinct ordinal trees based on tree cover- ing. ACM Trans. Algorithms 8(4), 1–32 (2012); A Preliminary Version Ap- peared in Arge, L., Cachin, C., Jurdzi´nski, T., Tarlecki, A. (eds.): ICALP 2007. LNCS, vol. 4596, pp. 509–520. Springer, Heidelberg (2007) [93] He, M., Munro, J.I., Zhou, G.: Path queries in weighted trees. In: Asano, T., Nakano, S.-i., Okamoto, Y., Watanabe, O. (eds.) ISAAC 2011. LNCS, vol. 7074, pp. 140–149. Springer, Heidelberg (2011) [94] He, M., Munro, J.I., Zhou, G.: A framework for succinct labeled ordinal trees over large alphabets. In: Chao, K.-M., Hsu, T.-s., Lee, D.-T. (eds.) ISAAC 2012. LNCS, vol. 7676, pp. 537–547. Springer, Heidelberg (2012) [95] He, M., Munro, J.I., Zhou, G.: Succinct data structures for path queries. In: Epstein, L., Ferragina, P. (eds.) ESA 2012. LNCS, vol. 7501, pp. 575–586. Springer, Heidelberg (2012) Curriculum Vitae J. Ian Munro XIX
[96] Kaligosi, K., Mehlhorn, K., Munro, J.I., Sanders, P.: Towards optimal mul- tiple selection. In: Caires, L., Italiano, G.F., Monteiro, L., Palamidessi, C., Yung, M. (eds.) ICALP 2005. LNCS, vol. 3580, pp. 103–114. Springer, Heidelberg (2005) [97] Kameda, T., Munro, J.I.: A O(|V |∗|E|) algorithm for maximum matching of graphs. Computing 12(1), 91–98 (1974) [98] Karlsson, R.G., Munro, J.I.: Proximity of a grid. In: Mehlhorn, K. (ed.) STACS 1985. LNCS, vol. 182, pp. 187–196. Springer, Heidelberg (1984) [99] Karlsson, R.G., Munro, J.I., Robertson, E.L.: The nearest neighbor prob- lem on bounded domains. In: Brauer, W. (ed.) ICALP 1985. LNCS, vol. 194, pp. 318–327. Springer, Heidelberg (1985) [100] Kearney, P.E., Munro, J.I., Phillips, D.: Efficient generation of uniform samples from phylogenetic trees. In: Benson, G., Page, R.D.M. (eds.) WABI 2003. LNCS (LNBI), vol. 2812, pp. 177–189. Springer, Heidelberg (2003) [101] Munro, J.I.: Efficient determination of the transitive closure of a directed graph. Inf. Process. Lett. 1(2), 56–58 (1971) [102] Munro, J.I.: Some results concerning efficient and optimal algorithms. In: STOC 1971: Proceedings of the Third Annual ACM Symposium on Theory of Computing, pp. 40–44. ACM Press, New York (1971) [103] Munro, J.I.: Efficient polynomial evaluation. In: Proc. Sixth Annual Princeton Conference on Information Sciences and Systems (1972) [104] Munro, J.I.: In search of the fastest algorithm. In: AFIPS 1973: Proceed- ings of the National Computer Conference and Exposition, June 4-8, pp. 453–453. ACM, New York (1973) [105] Munro, J.I.: The parallel complexity of arithmetic computation. In: Karpinski, M. (ed.) FCT 1977. LNCS, vol. 56, pp. 466–475. Springer, Hei- delberg (1977) [106] Munro, J.I.: Review of “The Complexity of Computing” (Savage, J.E. in 1977). IEEE Transactions on Information Theory 24(3), 401–401 (1978) [107] Munro, J.I.: A multikey search problem. In: Proceedings of the 17th Aller- ton Conference on Communication, Control and Computing, pp. 241–244 (1979) [108] Munro, J.I.: An implicit data structure supporting insertion, deletion, and search in O(log2 n) time. J. Comput. Syst. Sci. 33(1), 66–74 (1986); A Pre- liminary Version An Implicit Data Structure for the Dictionary Problem that Runs in Polylog Time Appeared in SFCS 1984: Proceedings of the 25th Annual Symposium onFoundations of Computer Science, pp. 369– 374. IEEE Computer Society, Washington, DC (1984) [109] Munro, J.I.: Developing implicit data structures. In: Wiedermann, J., Gruska, J., Rovan, B. (eds.) MFCS 1986. LNCS, vol. 233, pp. 168–176. Springer, Heidelberg (1986) [110] Munro, J.I.: Searching a two key table under a single key. In: STOC 1987: Proceedings of the Nineteenth Annual ACM Symposium on Theory of Computing, pp. 383–387. ACM, New (1987) XX Curriculum Vitae J. Ian Munro
[111] Munro, J.I.: Data manipulations based on orderings. In: Algorithms and Order, pp. 283–306. Springer, Netherlands (1988) [112] Munro, J.I.: Tables. In: Chandru, V., Vinay, V. (eds.) FSTTCS 1996. LNCS, vol. 1180, pp. 37–42. Springer, Heidelberg (1996) [113] Munro, J.I.: On the competitiveness of linear search. In: Paterson, M. (ed.) ESA 2000. LNCS, vol. 1879, pp. 338–345. Springer, Heidelberg (2000) [114] Munro, J.I.: Space efficient suffix trees. J. Algorithms 39(2), 205–222 (2001) [115] Munro, J.I.: Succinct data structures. Electr. Notes Theor. Comput. Sci. 91, 3 (2004) [116] Munro, J.I.: Lower bounds for succinct data structures. In: Ferragina, P., Landau, G.M. (eds.) CPM 2008. LNCS, vol. 5029, p. 3. Springer, Heidel- berg (2008) [117] Munro, J.I.: Reflections on optimal and nearly optimal binary search trees. Efficient Algorithms: Essays DedicatedtoKurtMehlhornontheOccasion of His 60th Birthday, pp. 115–120 (2009) [118] Munro, J.I.: The complexity of partial orders. In: Bader, D.A., Mutzel, P. (eds.) ALENEX, p. 64. SIAM/Omnipress (2012) [119] Munro, J.I., Borodin, A.: Efficient evaluation of polynomial forms. J. Com- put. Syst. Sci. 6(6), 625–638 (1972) [120] Munro, J.I., Celis, P.: Techniques for collision resolution in hash tables with open addressing. In: ACM 1986: Proceedings of 1986 ACM Fall Joint Computer Conference, pp. 601–610. IEEE Computer Society Press, Los Alamitos (1986) [121] Munro, J.I., Ji, X.R.: On the pivot strategy of quicksort. In: Canadian Conference on Electrical and Computer Engineering, vol. 1, pp. 302–305. IEEE (1996) [122] Munro, J.I., Nicholson, P.K.: Succinct posets. In: Epstein, L., Ferragina, P. (eds.) ESA 2012. LNCS, vol. 7501, pp. 743–754. Springer, Heidelberg (2012) [123] Munro, J.I., Overmars, M.H., Wood, D.: Variations on visibility. In: SCG 1987: Proceedings of the Third Annual Symposium on Computational Ge- ometry, pp. 291–299. ACM, New York (1987) [124] Munro, J.I., Papadakis, T., Sedgewick, R.: Deterministic skip lists. In: SODA 1992: Proceedings of the Third Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 367–375. Society for Industrial and Applied Mathematics, Philadelphia (1992) [125] Munro, J.I., Paterson, M.S.: Optimal algorithms for parallel polynomial evaluation. J. Comput. Syst. Sci. 7(2), 189–198 (1973); A Preliminary Ver- sion Appeared in SWAT 1971: Proceedings of the 12th Annual Symposium on Switching and Automata Theory, pp. 132–139. IEEE Computer Society, Washington, DC (1971) [126] Munro, J.I., Paterson, M.S.: Selection and sorting with limited storage. Theor. Comput. Sci. 12, 315–323 (1980); A Preliminary Version Appeared in SFCS 1978: Proceedings of the 19th Annual Symposium on Foundations of Computer Science, pp. 253–258. IEEE Computer Society, Washington, DC (1978) Curriculum Vitae J. Ian Munro XXI
[127] Munro, J.I., Poblete, P.V.: Implicit structuring of data. In: Proceedings of the Twelfth Manitoba Conference on Numerical Mathematics and Com- puting: held at the University of Manitoba, September 30-October 2, vol. 37, p. 73. Utilitas Mathematica Publishing (1983) [128] Munro, J.I., Poblete, P.V.: A discipline for robustness or storage reduc- tion in binary search trees. In: PODS 1983: Proceedings of the 2nd ACM SIGACT-SIGMOD Symposium on Principles of Database Systems, pp. 70–75. ACM Press, New York (1983) [129] Munro, J.I., Poblete, P.V.: Probabilistic issues in data structures. In: Com- puter Science and Statistics: proceedings of the 14th Symposium on the Interface, p. 32. Springer, Heidelberg (1983) [130] Munro, J.I., Poblete, P.V.: Fault tolerance and storage reduction in binary search trees. Information and Control 62(2/3), 210–218 (1984) [131] Munro, J.I., Poblete, P.V.: Searchability in merging and implicit data structures. BIT 27(3), 324–329 (1987); A preliminary version appeared in D´ıaz, J. (ed.): ICALP 1983. LNCS, vol. 154, pp. 527–535. Springer, Heidelberg (1983) [132] Munro, J.I., Raman, R., Raman, V., Satti, S.R.: Succinct representations of permutations and functions. Theor. Comput. Sci. 438, 74–88 (2012); A Preliminary Version Appeared in Baeten, J.C.M., Lenstra, J.K., Parrow, J., Woeginger, G.J. (eds.): ICALP 2003. LNCS, vol. 2719, pp. 345–356. Springer, Heidelberg (2003) [133] Munro, J.I., Raman, V.: Fast sorting in-place sorting with O(n) data. In: Biswas, S., Nori, K.V. (eds.) FSTTCS 1991. LNCS, vol. 560, pp. 266–277. Springer, Heidelberg (1991) [134] Munro, J.I., Raman, V.: Sorting multisets and vectors in-place. In: Dehne, F., Sack, J.-R., Santoro, N. (eds.) WADS 1991. LNCS, vol. 519, pp. 473– 480. Springer, Heidelberg (1991) [135] Munro, J.I., Raman, V.: Sorting with minimum data movement. J. Algo- rithms 13(3), 374–393 (1992); A Preliminary Version Appeared in Dehne, F., Santoro, N., Sack, J.-R. (eds.): WADS 1989. LNCS, vol. 382, pp. 552– 562. Springer, Heidelberg (1989) [136] Munro, J.I., Raman, V.: Fast stable in-place sorting with O(n)datamoves. Algorithmica 16(2), 151–160 (1996) [137] Munro, J.I., Raman, V.: Selection from read-only memory and sorting with minimum data movement. Theor. Comput. Sci. 165(2), 311–323 (1996); A preliminary version appeared in Shyamasundar, R.K. (ed.): FSTTCS 1992. LNCS, vol. 652, pp. 380–391. Springer, Heidelberg (1992) [138] Munro, J.I., Raman, V.: Succinct representation of balanced parentheses and static trees. SIAM J. Comput. 31(3), 762–776 (2001); A Preliminary Version Succinct Representation of Balanced Parentheses, Static Trees and Planar Graphs Appeared in FOCS 1997: Proceedings of the 38th Annual Symposium on Foundations of Computer Science, p. 118. IEEE Computer Society, Washington, DC (1997) [139] Munro, J.I., Raman, V., Salowe, J.S.: Stable in situ sorting and minimum data movement. BIT 30(2), 220–234 (1990) XXII Curriculum Vitae J. Ian Munro
[140] Munro, J.I., Raman, V., Rao, S.S.: Space efficient suffix trees. In: Arvind, V., Sarukkai, S. (eds.) FST TCS 1998. LNCS, vol. 1530, pp. 186–197. Springer, Heidelberg (1998) [141] Munro, J.I., Raman, V., Storm, A.J.: Representing dynamic binary trees succinctly. In: SODA 2001: Proceedings of the Twelfth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 529–536. Society for Industrial and Applied Mathematics, Philadelphia (2001) [142] Munro, J.I., Ramirez, R.J.: Technical note - reducing space requirements for shortest path problems. Operations Research 30(5), 1009–1013 (1982) [143] Munro, J.I., Robertson, E.L.: Parallel algorithms and serial data struc- tures. In: Proceedings of the 17th Allerton Conference on Communication, Control and Computing, pp. 21–26 (1979) [144] Munro, J.I., Robertson, E.L.: Continual pattern replication. Information and Control 48(3), 211–220 (1981) [145] Munro, J.I., Rao, S.S.: Succinct representations of functions. In: D´ıaz, J., Karhum¨aki, J., Lepist¨o, A., Sannella, D. (eds.) ICALP 2004. LNCS, vol. 3142, pp. 1006–1015. Springer, Heidelberg (2004) [146] Munro, J.I., Spira, P.M.: Sorting and searching in multisets. SIAM J. Com- put. 5(1), 1–8 (1976) [147] Munro, J.I., Suwanda, H.: Implicit data structures for fast search and up- date. J. Comput. Syst. Sci. 21(2), 236–250 (1980); A Preliminary Version Appeared in STOC 1979: Proceedings of the Eleventh Annual ACM Sym- posium on Theory of Computing, pp. 108–117. ACM, New York(1979) [148] Oommen, B.J., Hansen, E.R., Munro, J.I.: Deterministic optimal and ex- pedient move-to-rear list organizing strategies. Theor. Comput. Sci. 74(2), 183–197 (1990); A Preliminary Version Deterministic move-to-rear list Or- ganizing Strategies with Optimal and Expedient Properties Appeared in Proceedings of the 25th Allerton Conference on Communication, Control and Computing (1987) [149] Papadakis, T., Munro, J.I., Poblete, P.V.: Analysis of the expected search cost in skip lists. In: Gilbert, J.R., Karlsson, R. (eds.) SWAT 1990. LNCS, vol. 447, pp. 160–172. Springer, Heidelberg (1990) [150] Papadakis, T., Munro, J.I., Poblete, P.V.: Average search and update costs in skip lists. BIT 32(2), 316–332 (1992) [151] Poblete, P.V., Munro, J.I.: The analysis of a fringe heuristic for binary search trees. J. Algorithms 6(3), 336–350 (1985) [152] Poblete, P.V., Munro, J.I.: Last-come-first-served hashing. J. Algo- rithms 10(2), 228–248 (1989) [153] Poblete, P.V., Munro, J.I., Papadakis, T.: The binomial transform and the analysis of skip lists. Theor. Comput. Sci. 352(1), 136–158 (2006); A Preliminary Version The Binomial Transform and its Application to the Analysis of Skip lists appeared in Spirakis, P.G. (ed.): ESA 1995. LNCS, vol. 979, pp. 554–569. Springer, Heidelberg (1995) [154] Poblete, P.V., Viola, A., Munro, J.I.: Analyzing the LCFS linear probing hashing algorithm with the help of Maple. MAPLETECH 4(1), 8–13 (1997) Curriculum Vitae J. Ian Munro XXIII
[155] Poblete, P.V., Viola, A., Munro, J.I.: The diagonal Poisson transform and its application to the analysis of a hashing scheme. Random Struct. Algo- rithms 10(1-2), 221–255 (1997); A Preliminary Version The Analysis of a Hashing Schema by the Diagonal Poisson Transform (extended abstract) appeared in van Leeuwen, J. (ed.): ESA 1994. LNCS, vol. 855, pp. 94–405. Springer, Heidelberg (1994) [156] Rahman, M.Z., Munro, J.I.: Integer representation and counting in the bit probe model. Algorithmica 56(1), 105–127 (2010); A Preliminary Version Appeared in Tokuyama, T. (ed.): ISAAC 2007. LNCS, vol. 4835, pp. 5–16. Springer, Heidelberg (2007) [157] Ram´ırez, R.J., Tompa, F.W., Munro, J.I.: Optimum reorganization points for arbitrary database costs. Acta Inf. 18, 17–30 (1982) [158] Robertson, E.L., Munro, J.I.: Generalized instant insanity and polynomial completeness. In: Proceedings of the 1975 Conference on Information Sci- ences and Systems: Papers Presented, April 2-4, p. 263. The Johns Hopkins University, Dept. of Electrical Engineering (1975) [159] Robertson, E.L., Munro, J.I.: NP-completeness, puzzles and games. Utili- tas Math. 13, 99–116 (1978) [160] Schwenk, A.J., Munro, J.I.: How small can the mean shadow of a set be? The American Mathematical Monthly 90(5), 325–329 (1983) [161] Tirdad, K., Ghodsnia, P., Munro, J.I., L´opez-Ortiz, A.: COCA filters: Co- occurrence aware bloom filters. In: Grossi, R., Sebastiani, F., Silvestri, F. (eds.) SPIRE 2011. LNCS, vol. 7024, pp. 313–325. Springer, Heidelberg (2011)
Technical Reports
[162] Alstrup, S., Bender, M.A., Demaine, E.D., Farach-Colton, M., Munro, J.I., Rauhe, T., Thorup, M.: Efficient tree layout in a multilevel memory hier- archy. CoRR cs.DS/0211010 (2002) [163] Biedl, T., Demaine, E.D., Demaine, M.L., Fleischer, R., Jacobsen, L., Munro, J.I.: The complexity of clickomania. CoRR cs.CC/0107031 (2001) [164] Dobkin, D.P., Munro, J.I.: A minimal space selection algorithm that runs in linear time. Tech. Rep. 106, Department of Computer Science, Univer- sity of Waterloo (1977) [165] He, M., Munro, J.I., Nicholson, P.K.: Dynamic range majority data struc- tures. CoRR abs/1104.5517 (2011) [166] Karpinski, M., Munro, J.I., Nekrich, Y.: Range reporting for moving points on a grid. CoRR abs/1002.3511 (2010) [167] Munro, J.I.: On random walks in binary trees. Tech. Rep. CS-76-33, De- partment of Computer Science, University of Waterloo, Waterloo, Ontario, Canada (1976) [168] Munro, J.I., Poblete, P.V.: A lower bound for determining the median. Tech. Rep. CS-82-21, Faculty of Mathematics, University of Waterloo (1982) XXIV Curriculum Vitae J. Ian Munro
Others
[169] Blum, M., Galil, Z., Ibarra, O.H., Kozen, D., Miller, G.L., Munro, J.I., Ruzzo, W.L.: Foreword. In: SFCS 1983: Proceedings of the 24th Annual Symposium on Foundations of Computer Science, p. iii. IEEE Computer Society, Washington, DC (1983) [170] Chwa, K.Y., Munro, J.I.: Computing and combinatorics - Preface. Theor. Comput. Sci. 363(1), 1–1 (2006) [171] L´opez-Ortiz, A., Munro, J.I.: Foreword. ACM Transactions on Algo- rithms 2(4), 491 (2006) [172] Munro, J.I.: Some results in the study of algorithms. Ph.D. thesis, Univer- sity of Toronto (1971) [173] Munro, J.I., Brodnik, A., Carlsson, S.: Digital memory structure and de- vice, and methods for the management thereof, US Patent App. 09/863,313 (May 24, 2001) [174] Munro, J.I., Brodnik, A., Carlsson, S.: A digital memory structure and device, and methods for the management thereof, eP Patent 1,141,951 (October 10, 2001) [175] Munro, J.I., Wagner, D.: Preface. J. Exp. Algorithmics 14, 1:2.1–1:2.1 (2010), http://doi.acm.org/10.1145/1498698.1537596
Ph.D. Student Supervision
[1] Allen, B.: On Binary Search Trees (1977) [2] Osborn, S.L.: Normal Forms for Relational Data Bases (1978) [3] Suwanda, H.: Implicit Data Structures for the Dictionary Problem (1980) [4] Pucci, W.C.: Average Case Selection (1983) [5] Poblete, P.V.: Formal Techniques for Binary Search Trees (1983) [6] Karlsson, R.G.: Algorithms in a Restricted Universe (1985) [7] Celis, P.: Robin Hood Hashiong (1986) [8] Culberson, J.C.: The Effect of Asymmetric Deletions on Binary Search Trees (1986) [9] Raman, V.: Sorting In-Place with Minimum Data Movement (1991) [10] Papadakis, T.: Skip Lists and Probabilistic Analysis of Algorithms (1993) [11] Brodnik, A.: Searching in Constant Time and Minimum Space Minimae Res Magni Momenti Sunt (1995) [12] Viola, A.: Analysis of Hashing Algorithms and a New Mathematical Trans- form (1995) [13] Clark, D.: Compact PAT Trees (1997) [14] Zhang, W.: Improving the Performance of Concurrent Sorts in Datsbase Systems (1997) [15] Demaine, E.D.: Folding and Unfolding (2001) [16] Golynski, A.: Upper and Lower Bounds for Text Indexing Data Structures (2007) [17] He, M.: Succinct Indexes (2008) Curriculum Vitae J. Ian Munro XXV
[18] Skala, M.A.: Aspects of Metric Spaces in Computation (2008) [19] Farzan, A.: Succinct Representation of Trees and Graphs (2009) [20] Claude, F.: Space-Efficient Data Structures for Information Retrieval (2013) [21] Salinger, A.J.: Models for Parallel Computation in Multi-Core, Heteroge- neous, and Ultra Wide-Word Architectures
–*– [22] Nicholson, P.: Space efficient data structures in Word-RAM and Bitprobe Models (working title) (2013) (expected year of graduation) [23] G. Zhou.
Professional Service and Honors
Fellow of Royal Society of Canada ACM Fellow Table of Contents
The Query Complexity of Finding a Hidden Permutation ...... 1 Peyman Afshani, Manindra Agrawal, Benjamin Doerr, Carola Doerr, Kasper Green Larsen, and Kurt Mehlhorn Bounds for Scheduling Jobs on Grid Processors ...... 12 Joan Boyar and Faith Ellen Quake Heaps: A Simple Alternative to Fibonacci Heaps ...... 27 Timothy M. Chan Variations on Instant Insanity ...... 33 Erik D. Demaine, Martin L. Demaine, Sarah Eisenstat, Thomas D. Morgan, and Ryuhei Uehara A Simple Linear-Space Data Structure for Constant-Time Range Minimum Query ...... 48 Stephane Durocher
Closing a Long-Standing Complexity Gap for Selection: V3(42) = 50 .... 61 David Kirkpatrick Frugal Streaming for Estimating Quantiles ...... 77 Qiang Ma, S. Muthukrishnan, and Mark Sandler From Time to Space: Fast Algorithms That Yield Small and Fast Data Structures ...... 97 J´er´emy Barbay Computing (and life) Is all About Tradeoffs : A Small Sample of Some Computational Tradeoffs ...... 112 Allan Borodin A History of Distribution-Sensitive Data Structures ...... 133 Prosenjit Bose, John Howat, and Pat Morin A Survey on Priority Queues ...... 150 Gerth Stølting Brodal On Generalized Comparison-Based Sorting Problems ...... 164 Jean Cardinal and Samuel Fiorini A Survey of the Game “Lights Out!” ...... 176 Rudolf Fleischer and Jiajin Yu XXVIII Table of Contents
Random Access to High-Order Entropy Compressed Text ...... 199 Roberto Grossi
Succinct and Implicit Data Structures for Computational Geometry .... 216 Meng He
In Pursuit of the Dynamic Optimality Conjecture ...... 236 John Iacono
A Survey of Algorithms and Models for List Update ...... 251 Shahin Kamali and Alejandro L´opez-Ortiz
Orthogonal Range Searching for Text Indexing ...... 267 Moshe Lewenstein
A Survey of Data Structures in the Bitprobe Model ...... 303 Patrick K. Nicholson, Venkatesh Raman, and S. Srinivasa Rao
Succinct Representations of Ordinal Trees ...... 319 Rajeev Raman and S. Srinivasa Rao
Array Range Queries ...... 333 Matthew Skala
Indexes for Document Retrieval with Relevance ...... 351 Wing-Kai Hon, Manish Patil, Rahul Shah, Sharma V. Thankachan, and Jeffrey Scott Vitter
Author Index ...... 363 The Query Complexity of Finding a Hidden Permutation
Peyman Afshani1, Manindra Agrawal2,BenjaminDoerr3, Carola Doerr3,4, Kasper Green Larsen1, and Kurt Mehlhorn3
1 MADALGO, Department of Computer Science, Aarhus University, Denmark 2 Indian Institute of Technology Kanpur, India 3 Max Planck Institute for Informatics, Saarbr¨ucken, Germany 4 Universit´e Paris Diderot - Paris 7, LIAFA, Paris, France
Abstract. We study the query complexity of determining a hidden per- mutation. More specifically, we study the problem of learning a secret (z,π) consisting of a binary string z of length n and a permutation π of [n]. The secret must be unveiled by asking queries x ∈{0, 1}n,andfor each query asked, we are returned the score fz,π(x) defined as
fz,π(x):=max{i ∈ [0..n] |∀j ≤ i : zπ(j) = xπ(j)} ;
i.e., the length of the longest common prefix of x and z with respect to π. The goal is to minimize the number of queries asked. We prove matching upper and lower bounds for the deterministic and randomized query complexity of Θ(n log n)andΘ(n log log n), respectively.
1 Introduction
Query complexity, also referred to as decision tree complexity, is one of the most basic models of computation. We aim at learning an unknown object (a secret) by asking queries of a certain type. The cost of the computation is the number of queries made until the secret is unveiled. All other computation is free. Let Sn denote the set of permutations of [n]:={1,...,n};let[0..n]:= {0, 1,...,n}. Our problem is that of learning a hidden permutation π ∈ Sn together with a hidden bit-string z ∈{0, 1} through queries of the following type. A query is again a bit-string x ∈{0, 1}n. As answer we receive the length of the longest common prefix of x and z in the order of π, which we denote by
fz,π(x):=max{i ∈ [0..n] |∀j ≤ i : zπ(j) = xπ(j)} .
We call this problem the HiddenPermutation problem. It is a Mastermind- like problem; however, the secret is now a permutation and a string and not just a string. Figure 1 sketches a gameboard for the HiddenPermutation game. It is easy to see that O(n log n) queries suffice deterministically to unveil the secret. Doerr and Winzen [1] showed that randomization allows to do better.
The full paper is available at http://eccc.hpi-web.de/report/2012/087/
A. Brodnik et al. (Eds.): Munro Festschrift, LNCS 8066, pp. 1–11, 2013. c Springer-Verlag Berlin Heidelberg 2013 2 P. Afshani et al.
0 10 0 4 1 1 1 0 3 0 1 1 1 2 000 0 1 102
Fig. 1. A gameboard for the HiddenPermutation game for n = 4. The first player (codemaker) chooses z and π byplacingastringin{0, 1}4 into the 4 × 4gridonthe right side, one digit per row and column; here, z = 0100 and π(1) = 4, π(2) = 2, π(3) = 3, and π(4) = 1. The second player (codebreaker) places its queries into the columns on the left side of the board. The score is shown below each column. The computation of the score by the codemaker is simple. She goes through the codematrix column by column and advances as long as the query and the code agrees.
They gave a randomized algorithm with O(n log n/ log log n) expected complex- ity. The information-theoretic lower bound is only Θ(n) as the answer to each query is a number between zero and n and hence may reveal as many as log n bits. We show: the deterministic query complexity is Θ(n log n), cf. Section 3, and the randomized query complexity is Θ(n log log n), cf. Sections 4 and 5. Both upper bound strategies are efficient, i.e., can be implemented in polynomial time. The lower bound is established by a (standard) adversary argument in the de- terministic case and by a potential function argument in the randomized case. The randomized upper and lower bound require a non-trivial argument. The archetypal guessing game is Mastermind. The secret is a string z ∈ [k]n, and a query is also a string x ∈ [k]n. The answer to a query is the number eq(z,x) of positions in which x and z agree and the number w(z,x) of additional colors in x |{ ∈ | }| − that appear in z (formally, w(z,x):=maxπ∈Sn i [n] zi = xπ(i) eq(z,x)). Some applications were found recently [2,3]. Mastermind has been studied inten- sively since the sixties [4,5,6,7,8,9] and thus even before it was invented as a board game. In particular, [4,6] show that for all n and k ≤ n1−ε, the secret code can be found by asking Θ(n log k/ log n) random queries. This can be turned into a deterministic strategy having the same asymptotic complexity. The information- theoretic lower bound of Ω(n log k/ log n) shows that this is best possible, and also, that there is no difference between the randomized and deterministic case. Similar situations have been observed for a number of guessing, liar, and pusher- chooser games (see, e.g., [10,11]). Our results show that the situation is different for the HiddenPermutation game. The complexity of Mastermind with n po- sitions and k = n colors is open. The best upper bound is O(n log log n), cf. [12], and the best lower bound is the trivial linear one. The Query Complexity of Finding a Hidden Permutation 3
2 Preliminaries
For all positive integers k ∈ N we define [k]:={1,...,k} and [0..k]:=[k] ∪{0}. n By ek we denote the kth unit vector (0,...,0, 1, 0,...,0) of length n.Fora ⊆ n n ⊕ n ⊕ set I [n] we define eI := i∈I ei = i∈I ei ,where denotes the bitwise exclusive-or. We say that we create y from x by flipping I or that we create y ⊕ n from x by flipping the entries in position(s) I if y = x eI .BySn we denote the set of all permutations of [n]. For r ∈ R≥0,let r := min{n ∈ N0 | n ≥ r}.and r := max{n ∈ N0 | n ≤ r}. To increase readability, we sometimes omit the · signs; that is, whenever we write r where an integer is required, we implicitly mean r . n n Let n ∈ N.Forz ∈{0, 1} and π ∈ Sn, define fz,π : {0, 1} → [0..n]asin the introduction. We call z the target string and π the target permutation.The i i i 1 t score of a query x is s = fz,π(x ). We may stop after t queries x to x if there n i i is only a single pair (z,π) ∈{0, 1} × Sn with s = fz,π(x )for1≤ i ≤ t. A randomized strategy for the HiddenPermutation problem is a tree of outdegree n + 1 in which a probability distribution over {0, 1}n is associated with every node of the tree. The search starts as the root. In any node, the query is selected according to the probability distribution associated with the node, and the search proceeds to the child selected by the score. The complexity of a strategy on input (z,π) is the expected number of queries required to identify the secret, and the randomized query complexity of a strategy is the worst case over all secrets. Deterministic strategies are the special case in which a fixed query is associated with every node. The deterministic (randomized) query complexity of HiddenPermutation is the best possible (expected) complexity. − ⊕ n We remark that knowing z allows us to determine π with n 1queriesz ei , ≤ −1 ⊕ n 1 i ∈ N H i i t Theorem 1. Let t ,andlet =(x ,s )i=1 be a guessing history. Construct the candidate sets V1,...,Vn ⊆ [n] according to the following rules: ≤ h ≤ h ∈ (1) If there are h and with j s s and xi = xi ,theni Vj . h h ∈ (2) If there are h and with s = s = s and xi = xi ,theni Vs+1. h h ∈ (3) If there are h and with s (4) If i is not excluded by one of the rules above, then i ∈ Vj . Furthermore, let s∗ := max{s1,...,st} and let x∗ = xj for some j with sj = s∗. ∗ ∗ Then a pair (z,π) is consistent with H if and only if (a) fz,π(x )=s and (b) π(j) ∈ Vj for all j ∈ [n]. Proof. Let (z,π) satisfy conditions (a) and (b). We show that (z,π) is consistent h h with H. To this end, let h ∈ [t], let x = x , s = s ,andf := fz,π(x). We need to show f = s. ∗ Assume f We may construct the sets Vj incrementally. The following update rules are direct consequences of Theorem 1. In the beginning, let Vj := [n], 1 ≤ j ≤ n.Afterthe first query, record the first query as x∗ and its score as s∗. For all subsequent queries, do the following: Let I be the set of indices in which the current query x and the current best query x∗ agree. Let s be the objective value of x and let s∗ be the objective value of x∗. ∗ Rule A: If s It is immediate from the update rules that the Vj sformalaminar family; i.e., for i Theorem 2. It is decidable in polynomial time whether a guessing history is feasible. Furthermore, we can efficiently compute the number of pairs consistent with it. The Query Complexity of Finding a Hidden Permutation 5 3 Deterministic Complexity We show that the deterministic query complexity of HiddenPermutation is Θ(n log n). The upper bound is achieved by an algorithm that resembles binary search and it- eratively identifies π(1),...,π(n) and the corresponding bit values zπ(1),...,zπ(n): We start by querying the all-zeros string 0n and the all-ones string 1n.Thescores determine zπ(1). By flipping a set I containing half of the bit positions in the bet- ter (the one achieving largest score) of the two strings, we can determine whether π(1) ∈ I or not. This allows us to find π(1) via a binary search strategy in O(log n) queries. Once π(1) and zπ(1) are known, we iterate this strategy on the remaining bit positions to determine π(2) and zπ(2), and so on, yielding an O(n log n)query strategy for identifying the secret. We proceed to the lower bound. The adversary strategy proceeds in rounds. In every round, the adversary reveals the next two values of π and the corresponding bits of z and every algorithm uses Ω(log n) queries. We describe the first phase. ∗ ∗ Let x1 be the first query. The adversary gives it a score of 1, sets (x ,s )=(x1, 1) and Vi to [n]for1≤ i ≤ n. In the first phase, the adversary will only return scores 0 and 1; observe that according to the rules for the incremental update of the sets Vi,onlysetsV1 and V2 will be modified in the first phase, and all other Vis stay equal to the [n]. | |≥ { | ∗} Let x be the next query and assume V1 3. Let I = i xi = xi be the set ∗ of positions in which x and x agree. If |I ∩V1|≥|V1|/2, the adversary returns a score of 1 and replaces V1 by V1 ∩ I and V2 by V2 ∩ I. Otherwise, the adversary returns a score of 0 and replaces V1 by V1 \ I. In either case, the cardinality of V1 is at most halved and V1 stays a subset of V2. The adversary proceeds as long as |V1|≥3 before the query. Then |V1|≥2 after the answer by the adversary. If |V1| = 2 before the query, the adversary starts the next phase by giving x a score of 3. Let i1 ∈ V1 and i2 ∈ V2 be arbitrary. The adversary commits to ∗ − ∗ π(1) = i1, π(2) = i2, zi1 = xi ,andzi2 =1 xi , removes i1 and i2 from V3 to ∗ ∗ 1 2 Vn,andsets(x ,s )=(x, 3). Theorem 3. The deterministic query complexity of the HiddenPermutation problem with n positions is Θ(n log n). 4 The Randomized Strategy We show that the randomized query complexity is only O(n log log n). Our ran- domized strategy learns an expected number of Θ(log n/ log log n) bits per query, and we have already seen that deterministic strategies can only learn a constant number of bits per query in the worst case. In the language of the candidate sets Vi, we manage to reduce the sizes of many Vis in parallel, that is, we gain information on several π(i)s despite the seemingly sequential way fz,π offers in- formation. The key to this is using partial information given by the Vi (that is, information that does not determine πi, but only restricts it) to guess with good ∗ probability an x with fz,π(x) >s . 6 P. Afshani et al. Theorem 4. The randomized query complexity of the HiddenPermutation problem with n positions is O(n log log n). The strategy has two parts. In the main part, we identify the positions π(1),...,π(q) and the corresponding bit values zπ(1),...,zπ(q) for some q ∈ n − Θ(n/ log n) with O(n log log n) queries. In the second part, we find the remaining n−q ∈ Θ(n/ log n) positions and entries using the binary search algorithm with O(log n)queriesper position. Part 1 is outlined below; the details are given in the full paper. 4.1 The Main Strategy Here and in the following we denote by s∗ the current best score, and by x∗ ∗ ∗ we denote a corresponding query; i.e., fz,π(x )=s . For brevity, we write f for fz,π. There is a trade-off between learning more information about π by reducing ∗ the sets V1,...,Vs∗+1 and increasing the score s . Our main task is to find the right balance between the two. In our O(n log log n) strategy, we partition the sets V1,...,Vn into several levels, each of which has a certain capacity. Depending on the status (i.e., the fill rate) of these levels, either we try to increase s∗,or we aim at reducing the sizes of the candidate sets. In the beginning, all candidate sets V1,...,Vn belong to level 0. In the first step we aim at moving V1,...,Vlog n to the first level. This is done sequentially. We start by querying f(x)andf(y), where x is arbitrary and y = x ⊕ 1n is the bitwise complement of x. By swapping x and y if needed, we may assume f(x)=0 At some point the probability that π(i) ∈/ V1 ∪...∪Vi−1 drops below a certain threshold and we cannot ensure to make progress anymore by simply querying y ⊕ ([n]\(V1 ∪ ...∪ Vi−1)). This situation is reached when i =logn and hence we abandon the previously described strategy once s∗ =logn.Atthispoint,we move our focus from increasing the current best score s∗ to reducing the size of the candidate sets V1,...,Vs∗ , thus adding them to the second level. More precisely, we reduce their sizes to at most n/ log2d n. This reduction is carried out by subroutine2, which we describe in the full paper. It reduces the sizes of ≤ d d the up to x−1 candidate sets from some value n/x−1 to the target size n/x of level with an expected number of O(1)x−1d(log(x) − log(x−1))/ log(x−1) queries. 2d Once the sizes |V1|,...,|Vs∗ | have been reduced to at most n/ log n,wemove ∗ ∗ our focus back to increasing s . The probability that π(s +1) ∈ V1 ∪...∪Vs∗ will now be small enough , and we proceed as before by flipping [n] \ (V1 ∪ ...∪ Vs∗ ) d and reducing the size of Vs∗+1 to n/ log n. Again we iterate this process until the ∗ first level is filled; i.e., until we have s = 2 log n.AswedidwithV1,...,Vlog n, 2d we reduce the sizes of Vlog n+1,...,V2logn to n/ log n, thus adding them to the second level. We iterate this process of moving log n sets from level 0 to level 1 and then moving them to the second level until log2 n sets have been added to the second level. At this point the second level has reached its capacity and we 4d proceed by reducing the sizes of V1,...,Vlog2 n to at most n/ log n, thus adding them to the third level. In total we have t = O(log log n) levels. For 1 ≤ i ≤ t,theith level has a 2i−1 capacity of xi := log n sets, each of which is required to be of size at most d n/xi . Once level i has reached its capacity, we reduce the size of the sets on the d ith level to at most n/xi+1, thus moving them from level i to level i +1.When xt sets Vi,...,Vi+xt have been added to the last level, level t, we finally reduce their sizes to one. This corresponds to determining π(i + j)foreachj ∈ [xt]. This concludes the presentation of the main ideas of the first phase. 5 The Lower Bound In this section, we prove a tight lower bound for the randomized query com- plexity of the HiddenPermutation problem. The lower bound is stated in the following: Theorem 5. The randomized query complexity of the HiddenPermutation problem with n positions is Ω(n log log n). To prove a lower bound for randomized query schemes, we appeal to Yao’s prin- ciple. That is, we first define a hard distribution over the secrets and show that every deterministic query scheme for this hard distribution needs Ω(n log log n) queries in expectation. This part of the proof is done using a potential function argument. Hard Distribution. Let Π be a permutation drawn uniformly among all the permutations of [n] (in this section, we use capital letters to denote random 8 P. Afshani et al. variables). Given such a permutation, we let our target string Z be the one satisfying ZΠ(i) =(i mod 2) for i =1,...,n.SinceZ is uniquely determined by the permutation Π, we will mostly ignore the role of Z in the rest of this section. Finally, we use F (x) to denote the value of the random variable fZ,Π (x) for x ∈{0, 1}n. We will also use the notation a ≡ b to mean that a ≡ b mod 2. Deterministic Query Schemes. By fixing the random coins, a randomized solution with expected t queries implies the existence of a deterministic query scheme with expected t queries over our hard distribution. The rest of this section is devoted to lower bounding t for such a deterministic query scheme. A deterministic query scheme is a decision tree T in which each node v is n labeled with a string xv ∈{0, 1} . Each node has n + 1 children, numbered from 0ton,andtheith child is traversed if F (xv)=i. To guarantee correctness, no two inputs can end up in the same leaf. For a node v in the decision tree T , we define maxv as the largest value of F seen along the edges from the root to v. Note that maxv is not a random variable and in fact, at any node v and for any ancestor u of v, conditioned on the event that the search path reaches v, the value of F (xu) is equal to the index of the child of u that lies on the path to v. Finally, we define Sv as the subset of inputs (as outlined above) that reach node v. We use a potential function which measures how much “information” the queries asked have revealed about Π. Our goal is to show that the expected increase in the potential function after asking each query is small. Our poten- tial function depends crucially on the candidate sets. The update rules for the candidate sets are slightly more specific than the ones in Section 2 because we now have a fixed connection between the two parts of the secret. We denote the v r candidate set for π(i)atnodev with Vi . At the root node r,wehaveVi =[n] for all i.Letv be a node in the tree and let w0,...,wn be its children (wi is v v traversed when the score i is returned). Let P0 (resp. P1 )bethesetofposi- v { | } tions in xv that contain 0 (resp. 1). Thus, formally, P0 = i xv[i]=0 and P v = {i | x [i]=1}.1 The precise definition of candidate sets is as follows: 1 v ⎧ v ∩ v ≤ ⎨ Vi Pi mod 2 if i j, wj v ∩ v Vi = Vi Pj mod 2 if i = j +1, ⎩ v Vi if i>j+1. As with the upper bound case, the candidate sets have some very useful prop- erties. These properties are slightly different from the ones observed before, due to the fact that some extra information has been announced to the query algo- v rithm. We say that a candidate set Vi is active (at v) if the following conditions are met: (i) at some ancestor node u of v,wehaveF (xu)=i − 1, (ii) at every ancestor node w of u we have F (xw) 5.1 Potential Function v | v| We define the potential of an active candidate set Vi as log log (2n/ Vi ). This is inspired by the upper bound: a potential increase of 1 corresponds to a candidate v set advancing one level in the upper bound context (in the beginning, a set Vi has size n and thus its potential is 0 while at the end its potential is Θ(log log n). With each level, the quantity n divided by the size of Vi is squared). We define the potential at a node v as 2n 2n ϕ(v)=loglog + log log , |V v |−Con |V v| maxv +1 v j j∈Av in which Av is the set of indices of active candidate sets at v and Conv is the v number of candidate sets contained inside Vmaxv +1. Note that from Lemma 1, it follows that Conv = maxv /2 . The intuition for including the term Conv is the same as our requirement i Lemma 2. Let v be a node in T and let iv be the random variable giving the value of F (xv) when Π ∈ Sv and 0 otherwise. Also let w0,...,wn denote the E − children of v,wherewj is the child reached when F (xv)=j.Then, [ϕ(wiv ) ϕ(v) | Π ∈ Sv]=O(1). 5.2 Potential at the End Intuitively, if the maximum score value increases after a query, it increases, in expectation, only by an additive constant. In fact, in the full paper, we prove 10 P. Afshani et al. that the probability of increasing the maximum score value by α after one query is 2−Ω(α). Thus, it follows from the definition of the active candidate sets that when the score reaches n/3 we expect Ω(n) active candidate sets. However, by Lemma 1, the active candidate sets are disjoint. This means that a fraction of them (again at least Ω(n) of them), must be small, or equivalently, their total potential is Ω(n log log n). Lemma 3. Let be the random variable giving the leaf node of T that the de- terministic query scheme ends up in on input Π. We have ϕ()=Ω(n log log n) with probability at least 3/4. 5.3 Putting Things together Finally, we show how Lemma 2 and Lemma 3 combine to give our lower bound. Essentially this boils down to showing that if the query scheme is too efficient, then the query asked at some node of T increases the potential by ω(1) in expectation, contradicting Lemma 2. To show this explicitly, define t as the random variable giving the number of queries asked on input Π.WehaveE[t]= t,wheret was the expected number of queries needed for the deterministic query scheme. Also let 1,...,4t be the random variables giving the first 4t nodes of T traversed on input Π,where1 = r is the root node and i denotes the node traversed at the ith level of T .Ifonlym<4t nodes are traversed, define i = m for i>m; i.e., ϕ(i)=ϕ(m). From Lemma 3, Markov’s inequality and a union bound, we may now write 4t−1 4t−1 E[ϕ(4t)] = E ϕ(1)+ ϕ(i+1) − ϕ(i) =E[ϕ(r)] + E ϕ(i+1) − ϕ(i) i=1 i=1 4t−1 = E[ϕ(i+1) − ϕ(i)] = Ω(n log log n). i=1 Hence there exists a value i∗,where1≤ i∗ ≤ 4t − 1, such that E[ϕ(i∗+1) − ϕ(i∗ )] = Ω(n log log n/t). But E ∗ − ∗ ∈ E − | ∈ [ϕ(i +1) ϕ(i )] = Pr[Π Sv] [ϕ(wiv ) ϕ(v) Π Sv], v∈Ti∗ |v non-leaf ∗ where Ti∗ is the set of all nodes at depth i in T , w0,...,wn are the children of v and iv is the random variable giving the score of F (xv) on an input Π ∈ Sv and 0 otherwise. Since the events Π ∈ Sv and Π ∈ Su are disjoint for v = u,we conclude that there must exist a node v ∈ Ti∗ for which E − | ∈ [ϕ(wiv ) ϕ(v) Π Sv]=Ω(n log log n/t). Combined with Lemma 2 this shows that n log log n/t = O(1); i.e., t = Ω(n log log n). This concludes the proof of Theorem 5. The Query Complexity of Finding a Hidden Permutation 11 References 1. Doerr, B., Winzen, C.: Black-box complexity: Breaking the o(n logn) barrier of LeadingOnes. In: Hao, J.-K., Legrand, P., Collet, P., Monmarch´e, N., Lutton, E., Schoenauer, M. (eds.) EA 2011. LNCS, vol. 7401, pp. 205–216. Springer, Heidelberg (2012) 2. Goodrich, M.T.: The Mastermind attack on genomic data. In: Proceedings of the 2009 30th IEEE Symposium on Security and Privacy (SP 2009), pp. 204–218. IEEE (2009) 3. Focardi, R., Luccio, F.L.: Cracking bank PINs by playing Mastermind. In: Boldi, P. (ed.) FUN 2010. LNCS, vol. 6099, pp. 202–213. Springer, Heidelberg (2010) 4. Erd˝os, P., R´enyi, A.: On two problems of information theory. Magyar Tudom´anyos Akad´emia Matematikai Kutat´oInt´ezet K¨ozlem´enyei 8, 229–243 (1963) 5. Knuth, D.E.: The computer as master mind. Journal of Recreational Mathemat- ics 9, 1–5 (1977) 6. Chv´atal, V.: Mastermind. Combinatorica 3, 325–329 (1983) 7. Chen, Z., Cunha, C., Homer, S.: Finding a hidden code by asking questions. In: Cai, J.-Y., Wong, C.K. (eds.) COCOON 1996. LNCS, vol. 1090, pp. 50–55. Springer, Heidelberg (1996) 8. Goodrich, M.T.: On the algorithmic complexity of the Mastermind game with black-peg results. Information Processing Letters 109, 675–678 (2009) 9. Viglietta, G.: Hardness of Mastermind. In: Kranakis, E., Krizanc, D., Luccio, F. (eds.) FUN 2012. LNCS, vol. 7288, pp. 368–378. Springer, Heidelberg (2012) 10. Pelc, A.: Searching games with errors — fifty years of coping with liars. Theoretical Computer Science 270, 71–109 (2002) 11. Spencer, J.: Randomization, derandomization and antirandomization: Three games. Theoretical Computer Science 131, 415–429 (1994) 12. Doerr, B., Sp¨ohel, R., Thomas, H., Winzen, C.: Playing Mastermind with many colors. In: SODA 2013, pp. 695–704. SIAM (2013) 13. Yao, A.C.C.: Probabilistic computations: Toward a unified measure of complexity. In: FOCS 1977, pp. 222–227. IEEE (1977) Bounds for Scheduling Jobs on Grid Processors Joan Boyar1 and Faith Ellen2 1 University of Southern Denmark [email protected] 2 University of Toronto [email protected] Abstract. In the Grid Scheduling problem, there is a set of jobs each with a positive integral memory requirement. Processors arrive in an online manner and each is assigned a maximal subset of the remaining jobs such that the sum of the memory requirements of those jobs does not exceed the processor’s memory capacity. The goal is to assign all the jobs to processors so as to minimize the sum of the memory capacities of the processors that are assigned at least one job. Previously, a lower 5 bound of 4 on the competitive ratio of this problem was achieved using jobs of size S and 2S − 1. For this case, we obtain matching upper and lower bounds, which vary depending on the ratio of the number of small jobs to the number of large jobs. 1 Introduction The Grid is a computing environment comprised of various processors which arrive at various times and to which jobs can be assigned. We consider the problem of scheduling a set of jobs, each with a specific memory requirement. When a processor arrives, it announces its memory capacity. Jobs are assigned to the processor so that the sum of the requirements of its assigned jobs does not exceed its capacity. In this way, the processor can avoid the expensive costs of paging when it executes the jobs. The charge for a set of jobs is (proportional to) the memory capacities of the processors to which they are assigned. There is no charge for processors whose capacities are too small for any remaining jobs. The goal is to assign all the jobs to processors in a manner that minimizes the total charge. The Grid Scheduling problem was motivated by a problem in bioinformatics in which genomes are compared to a very large database of DNA sequences to identify regions of interest [2]. In this application, an extremely large problem is divided into a set of independent jobs with varying memory requirements. This research was supported in part by the Danish Council for Independent Research, Natural Sciences (FNU), the VELUX Foundation, and the Natural Science and Engineering Research Council of Canada (NSERC). Parts of this work were carried out while Joan Boyar was visiting University of Waterloo and University of Toronto and while Faith Ellen was visiting University of Southern Denmark. A. Brodnik et al. (Eds.): Munro Festschrift, LNCS 8066, pp. 12–26, 2013. c Springer-Verlag Berlin Heidelberg 2013 Bounds for Scheduling Jobs on Grid Processors 13 The Grid Scheduling problem can also be rephrased as a bin packing problem for a given set of items, using variable-sized bins, which arrive one by one, in an online manner. In contrast, usual bin packing problems assume the bins are given and the items arrive online. The Grid Scheduling problem was introduced by Boyar and Favrholdt in [1]. 13 They gave an algorithm to solve this problem with competitive ratio 7 .This solved an open question in [8], which considered a similar problem. They also proved that the competitive ratio of any algorithm for this problem is at least 5 4 . The lower bound proof uses s =2 items of size S and items of size L = 2S − 1, where S>1 is an integer and M =2L − 1 is the maximum bin size. If S =1,thenL =2S − 1 = 1, so all items have the same size, making the problem uninteresting. Likewise, if there is no bound on the maximum bin size, the problem is uninteresting, because the competitive ratio is unbounded: Once enough bins for an optimal packing have arrived, an adversary can send bins of arbitrarily large size, which the algorithm would be forced to use. In many applications of bin packing, there are only a small number of dif- ferent item sizes. A number of papers have considered the problem of packing a sequence of items of two different sizes in bins of size 1 in an online matter. In particular, there is a lower bound of 4/3 on the competitive ratio [6,4] and a matching upper bound [4]. When both item sizes are bounded above by 1/k, (k+1)2 the competitive ratio can be improved to k2+k+1 [3]. In this paper, we consider the Restricted Grid Scheduling problem, a version of the Grid Scheduling problem where the input contains exactly s items of size S and items of size L =2S − 1 and the maximum bin size is M =2L − 1, 5 which includes the scenario used in the 4 lower bound. Two natural questions arise for this problem: 5 1. Is there an algorithm matching the 4 lower bound on the competitive ratio or can this lower bound be improved? 2. What is the competitive ratio for the problem when there are initially s items of size S and items of size L, when the ratio of s to is arbitrary, rather than fixed to 2? We obtain matching upper and lower bounds on the competitive ratio of the Restricted Grid Scheduling problem. Theorem 1. For unbounded S, the competitive ratio of the Restricted Grid Scheduling problem is ⎧ 1 ≤ ⎨ 1+ 2+s/ if s/2, 1 ≤ 1+ 4 if s/2 < 5s/6, and ⎩ 2 1+ 3+6/s if 5s/6 <. We begin with some preliminaries, including a formal definition of the Grid Scheduling problem and some properties of optimal packings. In Section 3, we prove the lower bound on the competitive ratio of the Restricted Grid Scheduling problem. Then, in Section 4, we present properties of optimal packings for the 14 J. Boyar and F. Ellen Restricted Grid Scheduling problem. Some of these provide motivation for our design, while others are important for the analysis. We show why a few simple algorithms are not optimal in Section 5. Our algorithm, 2-Phase-Packer, appears in Section 6, together with part of the analysis. We conclude with some open questions. The omitted proofs and the rest of the analysis are in the full paper. 2 Preliminaries The competitive ratio [7,5] of an on-line algorithm is the worst-case ratio of the on-line performance to the optimal off-line performance, up to an additive constant. More precisely, for a set I of items (or, equivalently, a multi-set of item sizes), a sequence σ of bins, and an algorithm A for the Grid Scheduling problem, let A(I,σ) denote the total size of all the bins used by A when packing I in the sequence σ of bins. Then, the competitive ratio CRA of A is CRA =inf{c |∃b, ∀I,∀σ, A(I,σ) ≤ c · OPT(I,σ)+b} , where OPT denotes an optimal off-line algorithm. For specific choices of families A of sets I and sequences σ , the performance ratios, (In,σn) ,canbeusedto n n OPT(In,σn) prove a lower bound on the competitive ratio of A. Given a set of items and a sequence of bins, each with a size in {1,...,M},the goal of the Grid Scheduling problem is to pack the items in the bins so that the sum of the sizes of the items packed in each bin is at most the size of the bin and the sum of the sizes of bins used is minimized. The bins in the sequence arrive one at a time and each must be packed before the next bin arrives, without knowledge of the sizes of any future bins. If a bin is at least as large as the smallest unpacked item, it must be packed with at least one item. There is no charge for a bin that is smaller than this. It is assumed that enough sufficiently large bins arrive so that any algorithm eventually packs all items. For example, it suffices that every sequence ends with enough bins of size M to pack every item one per bin. Givenasetofitemsandasequenceofbins,apartial packing is an assignment of some of the items to bins such that the sum of the sizes of the items assigned to each bin is at most the size of the bin. A packing is a partial packing that assigns every item to a bin. If p is a packing of a set of items I into a sequence of bins σ and p is a packing of a disjoint set of items I into a sequence of bins σ,thenweusepp to denote the packing of I ∪ I into the sequence of bins σσ, where each item in I is assigned to the same bin as in p and each item in I is assigned to the same bin as in p. If every item has size at least S, there is no loss of generality in assuming that every bin has size at least S. This is because no packing can use a bin of size less than S. Apackingisvalid if every bin that can be used is used. In other words, in a valid packing, if a bin is empty, then all remaining items are larger than the bin. Bounds for Scheduling Jobs on Grid Processors 15 A bin in a packing p for σ is wasteful if its empty space is at least the size of the smallest remaining item. A packing is thrifty if it contains no wasteful bins. Since a packing is valid if and only if it has no wasteful empty bin, every thrifty packing is valid. Apackingisoptimal if it is valid and the sum of the sizes of the bins it uses is at least as small as any other valid packing. Lemma 1. For any sequence of bins and any optimal packing pp of these bins, there is an optimal packing pq that uses the same set of bins, in which q has no wasteful bins. Taking p to be empty in Lemma 1 yields the following result. Corollary 1. For any optimal packing of a sequence of bins, there is an optimal thrifty packing of that sequence using the same set of bins. 3 Lower Bounds Theorem 2. For unbounded S, any algorithm for the Restricted Grid Schedul- ing problem has competitive ratio at least ⎧ 1 ≤ ⎨ 1+ 2+s/ if s/2, 1 ≤ 1+ 4 if s/2 < 5s/6, and ⎩ 2 1+ 3+6/s if 5s/6 <. Proof. Consider an instance of the Grid Scheduling problem in which there are s items of size S, items of size L =2S − 1, and maximum bin size M =2L − 1. We start with the case when ≤ s/2 and then handle the case when >s/2. In both cases, we consider two subcases, depending on how the algorithm packs the first batch of bins. Case I: ≤ s/2. The adversary begins by giving bins of size 2S. In each of these bins, the algorithm must pack either two items of size S or one item of size L.Let0≤ k ≤ be the number of these bins in which the algorithm packs two items of size S. Then the algorithm has s − 2k items of size S and k items of size L left to pack. Case I.1: k ≤ /2. Next, the adversary gives s − 2 bins of size S, followed by 2 bins of size L. The algorithm must pack one item of size S in each bin of size S and must use one bin of size L for each of the remaining s − 2k − (s − 2)=2( − k) items of size S and k items of size L. The total cost incurred by the algorithm is · 2S +(s − 2) · S +(2 − k) · L = s · S +2 · L − k · L ≥ s · S +3 · L/2. For this sequence, OPT packs two items of size S in each of the bins of size 2S, one item of size S in each of the s − 2 bins of size S,andoneitemof 16 J. Boyar and F. Ellen size L in each of the next bins of size L, for total cost s · S + · L.Thus,the performance ratio of the algorithm is at least s · S +3 · L/2 · L =1+ =1+ s · S + · L 2 · L +2s · S 2 + s + s/L 1 1 =1+ → 1+ as S →∞. s s/ 2+s/ 2+ + 2S−1 Case I.2: k>/2. Next, the adversary gives s bins of size S, followed by bins of size M.The algorithm packs one item of size S in the first s − 2k ≥ 2 − 2k ≥ 0ofthese bins, using up all its items of size S. It discards the remaining 2k bins of size S, because it has no remaining elements that are small enough to fit in them. Then the algorithm packs its remaining k items of size L into k bins of size M =4S − 3. The total cost incurred by the algorithm is · 2S +(s − 2k) · S + k · (4S − 3) =(2 + s) · S + k · (2S − 3) > (2 + s) · S + · (S − 3/2). For this sequence, OPT packs one item of size L in each of the bins of size 2S and one item of size S in each of the next s bins. The total cost used by OPT is · 2S + s · S. Thus, the performance ratio of the algorithm is at least (3 + s) · S − 3/2 1 − 3/(2S) 1 =1+ → 1+ as S →∞. (2 + s) · S 2+s/ 2+s/ Case II: >s/2. The adversary begins by giving s/2 bins of size 2S.Ineach of these bins, the algorithm must pack either two items of size S or one item of size L.Let0≤ k ≤ s/2 be the number of these bins in which the algorithm packs two items of size S. Then the algorithm has s − 2k items of size S and − s/2 + k items of size L left to pack. Case II.1: k ≤ s/2 −s/8 − /4+1ork ≤ s/2 −s/3+1. Next, the adversary next gives s/2 − s/2 bins of size S (i.e. one bin of size S if s is odd and no bins of size S if s is even), s/2 −k+−1 bins of size L,and1bin of size M. Since (s−2k)+(− s/2 +k)=( s/2 − s/2 )+( s/2 −k+−1)+1, the algorithm packs one of its remaining items in each of these bins, so the total cost it incurs is s/2 ·2S +( s/2 − s/2 ) · S +( s/2 −k + − 1) · L + M = s · S + · L +( s/2 −k +1)· L − 1. If s ≥ 4, then s/2 −k ≥ min{s/8+/4,s/3}−1 >s/4 − 1 ≥ 0, so there are at least bins of size L. Because of the additive constant in the definition of the competitive ratio, the case s ≤ 3 can be ignored. For this sequence, OPT packs two items of size S in each of the s/2 bins of size 2S, one item of size S in the bin of size S,ifs is odd, and one item of size L in each of the next bins of size L. Its total cost is s · S + · L. Bounds for Scheduling Jobs on Grid Processors 17 If k ≤ s/2 −s/8 − /4+1,then( s/2 −k +1)· L ≥ (s/8+/4) · L = S · s/4 − s/8+L · /4, so the performance ratio of the algorithm is at least (s · S + · L) · 5/4 − s/8 − 1 5 s/8+1 5 = − → as S →∞. s · S + · L 4 s · S + · (2S − 1) 4 Similarly, if k ≤ s/2 −s/3+1,then( s/2 −k +1)· L ≥ (s/3) · L,sothe performance ratio of the algorithm is at least (s/3) · L 2 − 1/(s · S) 2 1+ =1+ → 1+ as S →∞. s · S + · L 3+6/s − 3/(s · S) 3+6/s Case II.2: k> s/2 −s/8 − /4+1andk> s/2 −s/3+1>s/6. Next, the adversary gives max{s − 2k, s − + s/2 } bins of size S, followed by min{2k, − s/2 } bins of size L + S,max{ − s/2 −2k, 0} bins of size L,and finally k bins of size M =4S−3. The algorithm packs its s−2k items of size S into bins of size S. Since min{2k, − s/2 }+max{− s/2 −2k, 0}+k = − s/2 +k, the algorithm packs one item of size L in each bin of size L + S, L,andM.The total cost incurred by the algorithm is s/2 ·2S +(s − 2k) · S +min{2k, − s/2 } · (L + S) +max{ − s/2 −2k, 0}·L + k · M =(2 s/2 + s) · S +( − s/2 ) · L + k · (2S − 3) + min{2k, − s/2 } · S. For this sequence, OPT fills every bin it uses except for the s/2 bins of size 2S, in which it puts items of size L =2S − 1. Therefore, the total cost used by OPT is s · S + · L + s/2 . If 2k ≥ − s/2 , the performance ratio of the algorithm is at least (2 s/2 + s) · S +( − s/2 ) · L + k · (2S − 3) + ( − s/2 ) · S s · S + · L + s/2 ( + s + s/2 ) · S +( − s/2 ) · L +( s/2 −s/8 − /4+1)· (2S − 3) > s · S + · L + s/2 5 ( s/2 −s/2+2)· S + +3s/8 − 13 s/2 /4 − 3 = + 4 (s +2) · S − + s/2 5 +3s/8 − 13 s/2 /4 − 3 5 > + → as S →∞. 4 (s +2) · S − + s/2 4 If 2k ≤ − s/2 , the performance ratio of the algorithm is at least (2 s/2 + s) · S +( − s/2 ) · L + k · (4S − 3) s · S + · L + s/2 k · (4S − 3) =1+ (s +2) · S − + s/2 (s/6) · (4S − 3) > 1+ (s +2) · S + s/2 − 2 − 3/2S 2 =1+ → 1+ as S →∞. 3+6/s +3( s/2 −)/sS 3+6/s 18 J. Boyar and F. Ellen 5 ≤ 2 ≤ 5 Note that 4 1+ 3+6/s if and only if 5s/6. Thus, 4 is a lower bound on ≤ 2 the competitive ratio when s/2 < 5s/6and1+3+6/s is a lower bound on the competitive ratio when >5s/6. 4 Properties of Optimal Packings for Restricted Grid Scheduling We say that a bin used in a packing is bad if it contains an item of size S,it has empty space at least L − S, and it occurs while items of size L remain. Note that a bin containing an item of size L andanitemofsizeS has empty space at most M − L − S = L − S − 1, so it is not bad. Lemma 2. For any set of items and any sequence of bins, there exists an opti- mal thrifty packing that contains no bad bin. Proof. Fix a set of items and a sequence of bins and suppose every optimal thrifty packing contains a bad bin. Consider an optimal thrifty packing p which has the longest prefix without bad bins. Let b be the last bin to which p assigns an item of size L. Then the first bad bin b occurs before b.Sincep is thrifty, the empty space in b is less than L. Note that p has no empty bins (of size at least S) between b and b.Otherwise, let b be the first empty bin following b.Sincep is valid, size(b) – one item of size L,ifsize(b)=L, – two items of size S or one item of size L,ifsize(b) ∈ [L +1,L+ S − 1], – one item of size S and one item of size L,ifsize(b)=L + S,and – three items of size S or one item of size S and one item of size L,ifsize(b) ∈ [L + S +1, 2L − 1]. Note that a reasonable partial packing contains no wasteful, bad, or empty bins. For any packing, consider the first bin after which there are no items of size L remaining or at most 2 items of size S remaining. This bin is called the key bin of the packing. The partial packing that assigns the same items into each bin up to and including its key bin and assigns no items to any subsequent bin is called the front of the packing. We say that a packing is reasonable if it is thrifty and its front is reasonable. Corollary 2. For any set of items and any sequence of bins, there exists an optimal packing that is reasonable. From now on, we will restrict attention to reasonable packings. Given a set of items and a sequence of bins, two reasonable partial packings can differ as to whether they use one item of size L or two items of size S in certain bins. Therefore, the numbers of items of size S and items of size L they do not assign may differ. However, if both have at least one item of size S and at least one item of size L unassigned, the set of bins they have used is the same and there is a simple invariant relating the numbers of unassigned items of size S and unassigned items of size L they have. Lemma 3. Consider two reasonable partial packings of a set of items into a sequence of bins. Suppose that before bin b, each packing has at least one unas- signed item of size S and at least one unassigned item of size L or at least three unassigned items of size S. Then immediately after bin b has been packed, the number of items of size S available plus twice the number of items of size L available is the same for both packings. Once a packing runs out of items of size S, it may be impossible for it to com- pletely use some bins, so this relationship does not necessarily hold. For any sequence of bins σ and any nonnegative integers s and ,letOPT(σ, s, ) denote the cost of an optimal packing of s items of size S and items of size L =2S − 1usingσ. This must be at least the sum of the sizes of all the items. Proposition 1. OPT(σ, s, ) ≥ sS + L. Given any optimal packing for a set of items, a packing for a subset of these items can be obtained by removing the additional items from bins, starting from the end. Proposition 2. OPT(σ, s,) ≤ OPT(σ, s, ) for all s ≤ s and ≤ . For any sequence of bins σ and any nonnegative integers s and ,letR(σ, s, ) denote the maximum cost of any reasonable packing of s items of size S and items of size L =2S − 1usingσ. 20 J. Boyar and F. Ellen When all items have the same size, all thrifty algorithms, including OPT, behave exactly the same. Proposition 3. For all integers s, > 0, R(σ, s, 0) = OPT(σ, s, 0) and R(σ, 0,) = OPT(σ, 0,). Thus, if R and OPT both run out of items of size L at the same time or they both run out of items of size S at the same time, then they will use the same set of bins and, hence, have the same cost. The following four lemmas describe the relationship between the costs incurred by R and OPT when one of them has run out of one size of items. Lemma 4. For any sequence of bins σ and any integers s, ≥ 0, R(σ, s, ) ≤ OPT(σ, s +2, 0) + (2S − 3). Lemma 5. For any sequence of bins σ and any integers s, ≥ 0,if2k = s +2, then R(σ, s, ) ≤ OPT(σ, 0,k)+(s + − k − 1)L + M. Lemma 6. For any sequence of bins σ and any integers s, ≥ 0, R(σ, s +2, 0) ≤ OPT(σ, s, )+( − 1)L + M. Lemma 7. For any sequence of bins σ and any integers s, ≥ 0,if2k = s +2, then R(σ, 0,k) ≤ OPT(σ, min{s, },)+(k − )M. 5 Simple Non-optimal Algorithms It is helpful to understand why simple reasonable algorithms are not optimal for the Restricted Grid Scheduling problem. The following examples show why a number of natural candidates don’t work well enough. Example 1. Consider the reasonable algorithm that always uses items of size S, when there is a choice. Let s =2 and let σ consist of bins of size 2S, followed by s bins of size S,andthen bins of size M. For this instance, the algorithm has ·2S+·M 3 − 3 a performance ratio of ·2S+s·S = 2 4S , which is greater than 5/4 for large S. Example 2. Consider the reasonable algorithm that always uses items of size L, when there is a choice. Let s =2 and let σ consist of bins of size 2S, followed by s − 1 bins of size L and then 1 bin of size M. For this instance, the ·2S+(s−1)·L+M 3 1 − 1/+1/2 algorithm has a performance ratio of ·2S+·L = 2 + 2S−1 ,which is also greater than 5/4 for large S. For the two instances considered above, the reasonable algorithm which al- ternates between using two items of size S and one item of size L,whenithasa choice, would do well, achieving a performance ratio of 5/4. However, it doesn’t do as well on other instances. Bounds for Scheduling Jobs on Grid Processors 21 Example 3. Let 2s =3 and let σ consist of bins of size 2S, followed by s bins of size S and /2 bins of size M. For this instance, the algorithm which alternates between using two items of size S and one item of size L, when it has a choice, · − · · ·(M−2S) 2S+(s ) S+(/2) M 2 2 − 3 has a performance ratio of ·2S+s·S =1+ (2+s)·S =1+7 7S , which is larger than 5/4forS sufficiently large. As the above examples partially illustrate, once either the online algorithm or OPT has run out of one type of item (items of size S or items of size L), the adversary can give bins which make the online algorithm waste a lot of space. The algorithm we present in the next section aims to postpone this situation long enough to get a good ratio. The following example indicates the need for a second phase in order to obtain the optimal competitive ratios, which are less than 5/4 in some cases. Example 4. Consider the reasonable algorithm which uses one item of size L twice as often as two items of size S, when it has a choice. Let 3s =2 and let σ consist of bins of size 2S, followed by s bins of size S and /3 bins of size M. For this instance, the algorithm packs /3=s/2 bins of size 2S with two · · s · − 2S+(/3) M 2 M sS items of size S,soithasaperformanceratioof ·2S+s·S =1+(2+s)·S = S−3/2 5 − 3 2 7 1+ 4·S = 4 8S , which exceeds the lower bound of 1 + 3+6/s = 6 for S sufficiently large. 6 A Matching Upper Bound In this section, we present a reasonable algorithm, 2-Phase-Packer, for the Re- stricted Grid Scheduling problem. It is asymptotically optimal: the competitive ratio matches the lower bound in Section 3 for all three ranges of the ratio s/ of the initial numbers of items of size S and items of size L. Not surprisingly, 2-Phase-Packer has two phases. In the first phase, it attempts to balance the number of items of size S and the number of items of size L it uses, aiming for the ratio indicated by the lower bound. When it receives bins where it has a choice of using one item of size L or two items of size S in part or all of that bin (i.e., bins with sizes in the ranges [2S, 3S − 2] and [3S, 4S − 3]), it uses one item of size L in a certain fraction of them (and increments the variable L-bins) and uses two items of size S in the remaining fraction (and increments S-bins). The fraction varies depending on the original ratio s/: at least 2, between 2 and 6/5, and less than 6/5. It is enforced by a macro called UseLs, which indicates that an item of size L should be used if and only if L-bins ≤ rS-bins, where r is the target ratio of L-bins to S-bins. For example, when equal numbers of each should be used, we have UseLs = (L-bins ≤ S-bins). Both L-bins and S-bins start at zero, so, in this case, 2-Phase-Packer starts by choosing to use one item of size L and then alternates. Note that S-bins and L-bins do not change after Phase 1 is completed. In the middle range for the ratio s/, there are two different fractions used. The first fraction is used until S-bins reaches a specific value. Afterwards, its 22 J. Boyar and F. Ellen choices alternate. To do so, for the rest of Phase 1, it records the number of times it chooses to pack two items of size S in a bin and the number of times it chooses to pack one item of size L in late-S-bins and late-L-bins, respectively. The variables late-S-bins and late-L-bins are also zero initially. 2-Phase-Packer uses countS and countL throughout the algorithm to keep track of the total numbers of items of size S and items of size L it has used, whether or not it had a choice. (Specifically, countS is incremented every time an item of size S is used and countL is incremented every time an item of size L is used.) It continues with Phase 1 until it has used a certain number of items of size S or items of size L (depending on the relationship between s and ). For each of the three ranges of s/, we define a different condition for ending Phase 1. In Phase 2, only items of size S or only items of size L are used where a reasonable algorithm has a choice, depending on whether one would expect an excess of items of size S or items of size L, given the ratio s/. The definitions of the end of Phase 1 for the various ranges of s/ imply these inequalities. Lemma 8. If s/2 <≤ 5s/6,thenS-bins≤ 3s/8 − /4+1. If s<6/5,thenS-bins≤ s/6+1. The following simple invariants can be proved inductively. Lemma 9. L-bins ≤ countL and 2S-bins ≤ countS. If ≤ s/2,thenS-bins≤ L-bins ≤ S-bins +1. If s/2 <≤ 5s/6, then late-S-bins ≤ late-L-bins ≤ late-S-bins +1 and − ≤ ≤ 10−3s ≤ c(S-bins 1) +1 L-bins c S-bins +1,where1 We analyse the performance of 2-Phase-Packer as compared to the cost of an optimal reasonable packing on an arbitrary sequence, σ, using the three different ranges for the relationship between s and in the lower bound. Both 2-Phase-Packer and OPT use exactly the same bins until one of them runs out of either items of size L or items of size S. Thus, there are four cases to consider. 1. OPT runs out of items of size L at or before the point where 2-Phase-Packer runs out of anything. 2. OPT runs out of items of size S at or before the point where 2-Phase-Packer runs out of anything. 3. 2-Phase-Packer runs out of items of size L before OPT runs out of anything. 4. 2-Phase-Packer runs out of items of size S before OPT runs out of anything. We only present the analysis for Case 1. The remaining cases are similar. Consider an arbitrary sequence of bins σ in which 2-Phase-Packer packs s items of size S and items of size L. Suppose that, in this instance, OPT packs its last item of size L in bin b, but prior to bin b, both OPT and 2-Phase-Packer have unpacked items of both sizes. Let countL and countS denote the number of items of size L and items of size S, respectively, that 2-Phase-Packer has used Bounds for Scheduling Jobs on Grid Processors 23 ⎧ ⎨ countL ≥/2 if ≤ s/2 ≥ − ≤ macro Phase1done = ⎩ countS 3s/4 /2 if s/2 < 5s/6 countS ≥s/3 if 5s/6 < ⎧ ⎪ ≤ ≤ ⎪ L-bins S-bins if s/2 ⎨⎪ if (S-bins < (s +2)/16) if s/2 <≤ 5s/6 ≤ − macro UseLs = ⎪ then L-bins (10 3s)S-bins/(s +2) ⎪ ≤ ⎩⎪ else late-L-bins late-S-bins L-bins ≤ 2S-bins if 5s/6 < countS % counts the number of items of size S used; initially 0 countL % counts the number of items of size L used; initially 0 S-bins ← L-bins ← late-S-bins ← late-L-bins ← 0 for each arriving bin b if only one type of item still remains then use as many items as fit in b else if size(b) ∈ [S, 2S − 2] then use 1 item of size S else if size(b)=2S − 1 then use 1 item of size L else if size(b)=3S − 1 then use 1 item of size L and 1 item of size S else if only one item of size S still remains then use 1 item of size L if remaining space in b is at least S then use 1 item of size S else if only two items of size S still remain and size(b) ∈ [3S, 4S − 3] then use 1 item of size L and 1 item of size S else if (not Phase1done) then % Use range determined ratio if 6/5 ≤ s<2 and S-bins ≥(s +2)/16 then if UseLs then late-L-bins ++ else late-S-bins ++ if size(b) ∈ [2S, 3S − 2] then if UseLs then use 1 item of size L;L-bins++; else use 2 items of size S;S-bins++; if size(b) ∈ [3S, 4S − 3] then if UseLs then use 1 item of size L and 1 item of size S;L-bins++; else use 3 items of size S;S-bins++; else %InPhase2 if ≤ s/2 then use as many items of size S as fit in bin b else use 1 item of size L if remaining space in b is at least S then use 1 item of size S end for Fig. 1. The algorithm 2-Phase-Packer up to and including bin b. Let S-bins denote the number of bins at or before b where 2-Phase-Packer had a choice and used two items of size S instead of one of size L and let L-bins denote the number where it used one item of size L and couldhaveusedtwoofsizeS instead. Let σ denote the portion of σ after b. 24 J. Boyar and F. Ellen Both algorithms use all bins up to and including bin b, since all bins have size at least S.IfX is the total cost of these bins, then X ≥ (countS)S +(countL)L and 2-Phase-Packer (σ, s, )=X+ 2-Phase-Packer (σ,s− countS,− countL). In this case, Lemma 3 implies that, after bin b,OPThas(s − countS)+2( − countL)itemsofsizeS remaining, so OPT(σ, s, )=X+OPT(σ, (s−countS)+ 2( − countL ), 0). Since 2-Phase-Packer is reasonable, Lemma 4 implies that 2-Phase-Packer(σ, s − countS, − countL) ≤ R(σ,s − countS, − countL) ≤ OPT(σ, (s − countS)+2( − countL), 0)+ ( − countL)(2S − 3), so 2-Phase-Packer(σ, s, ) ≤ OPT(σ, s, )+(−countL)(2S −3). By Proposition 1, OPT(σ, s, ) ≥ sS +L ≥ sL/2+L =(s +2)L/2. When computing the competitive ratio, we will choose the additive constant to be at least L, so we subtract L from 2-Phase-Packer’s cost in the ratio. Thus, − − − − 2-Phase-Packer(σ, s, ) L ≤ OPT(σ, s, )+( countL )(2S 3) L OPT(σ, s, ) OPT(σ, s, ) ( − countL − 1)(L − 2) ≤ 1+ (s +2)L/2 2( − countL − 1) ≤ 1+ . s +2 It remains to bound − countL − 1 in each of the three ranges for the ratio s/. We use the fact that, immediately after bin b, OPT has run out of items of size L,soatleast bins of size at least L are in σ up to and including bin b. First, consider the case when ≤ s/2. If countL < /2 , then Phase 1 was not completed when bin b arrived. Therefore, each time a bin of size at least L arrives up to and including bin b, 2-Phase-Packer either packs an item of size L in it and, hence, increments countL, or it increments S-bins. Hence, countL + S-bins ≥ . By Lemma 9, L-bins ≥ S-bins . Since countL ≥ L-bins , by Lemma 9, it follows that countL ≥ /2 ≥ /2 . This is a contradiction. Thus, countL ≥ /2 and 2-Phase-Packer(σ, s, ) − L 2( − countL − 1) ≤ 1+ OPT(σ, s, ) s +2 1 ≤ 1+ =1+ . s +2 2+s/ So, suppose that s/2 <. During Phase 1, each time a bin of size at least L arrives, 2-Phase-Packer either packs an item of size L in it and, hence, incre- ments countL, or it increments S-bins. During Phase 2, 2-Phase-Packer packs an item of size L in each such bin until it runs out of items of size L. Therefore, countL + S-bins ≥ . Bounds for Scheduling Jobs on Grid Processors 25 If ≤ 5s/6, then Lemma 8 implies that − countL ≤ S-bins ≤ 3s/8 − /4+1 and 2-Phase-Packer(σ, s, ) − L 2( − countL − 1) 2(3s/8 − /4) ≤ 1+ ≤ 1+ OPT(σ, s, ) s +2 s +2 s/4+/2+s/2 − s/4+/2 5 =1+ < 1+ = . s +2 s +2 4 Similarly, if s<6/5, then − countL ≤ S-bins ≤ s/6 + 1, by Lemma 8, and 2-Phase-Packer(σ, s, ) − L 2( − countL − 1) ≤ 1+ OPT(σ, s, ) s +2 s/3 2 ≤ 1+ < 1+ . s +2 3+6/s 7 Conclusions and Open Problems We have shown that varying the proportion of items of size S to items of size L does not lead to a larger competitive ratio if the maximum bin size is at most 4S − 3. This may also be the case for an arbitrary maximum bin size, but there are complications. First, in bins of size 2kS,wherek ≥ 2S − 1, it is possible to pack more than k items of size L. In addition, it may be an advantage to have mixed bins which contain more than one item of size S and more than one item of size L. So, when bins can be large, one needs to consider how to maintain agoodratioofitemsofsizeL to items of size S, as they are used. We conjecture that maintaining the ratios specified in 2-Phase-Packer is sufficient. One could also consider the the Grid Scheduling problem for two bin sizes, S and L =2 S − 1. For example, when L is a multiple of S, then the algorithm of Example 2, which always uses as many items of size L as possible, is optimal and, hence, has competitive ratio 1. It would be interesting to see if changing the ratio of S to L could improve the lower bound. We conjecture that it does not. For the general problem, where there could be more than two sizes of items, we would like to close the gap between our lower bound and the upper bound of 13 3 7 in [1]. Using many item sizes, it is not hard to prove a lower bound of 2 on the strict competitive ratio (the competitive ratio where the additive constant in the definition is zero). However, the strict competitive ratio is not very interesting for this problem, since the ratio can be made larger simply by increasing the size of M and giving a last bin of size M. Finally, it would be interesting to consider the competitive ratio of random- ized algorithms for the Grid Scheduling problem or Restricted Grid Scheduling problem against an oblivious adversary. 26 J. Boyar and F. Ellen References 1. Boyar, J., Favrholdt, L.M.: Scheduling jobs on Grid processors. Algorithmica 57(4), 819–847 (2010) 2. Boyar, J., Favrholdt, L.M.: A new variable-sized bin packing problem. Journal of Scheduling 15, 273–287 (2012) 3. Epstein, L., Levin, A.: More online bin packing with two item sizes. Discrete Opti- mization 5(4), 705–713 (2008) 4. Gutin, G., Jensen, T.R., Yeo, A.: On-line bin packing with two item sizes. Algorith- mic Operations Research 1(2) (2006) 5. Karlin, A.R., Manasse, M.S., Rudolph, L., Sleator, D.D.: Competitive snoopy caching. Algorithmica 3(1), 79–119 (1988) 6. Liang, F.M.: A lower bound for on-line bin packing. Inform. Process. Lett. 10, 76–79 (1980) 7. Sleator, D.D., Tarjan, R.E.: Amortized efficiency of list update and paging rules. Comm. of the ACM 28(2), 202–208 (1985) 8. Zhang, G.: A new version of on-line variable-sized bin packing. Discrete Applied Mathematics 72, 193–197 (1997) Quake Heaps: A Simple Alternative to Fibonacci Heaps Timothy M. Chan Cheriton School of Computer Science, University of Waterloo, Waterloo, Ontario N2L 3G1, Canada [email protected] Abstract. This note describes a data structure that has the same the- oretical performance as Fibonacci heaps, supporting decrease-key op- erations in O(1) amortized time and delete-min operations in O(log n) amortized time. The data structure is simple to explain and analyze, and may be of pedagogical value. 1 Introduction In their seminal paper [5], Fredman and Tarjan investigated the problem of maintaining a set S of n elements under the operations – insert(x): insert an element x to S; – delete-min(): remove the minimum element x from S, returning x; – decrease-key(x, k): change the value of an element x to a smaller value k. They presented the first data structure, called Fibonacci heaps, that can support insert() and decrease-key() in O(1) amortized time, and delete-min() in O(log n) amortized time. Since Fredman and Tarjan’s paper, a number of alternatives have been pro- posed in the literature, including Driscoll et al.’s relaxed heaps and run-relaxed heaps [1], Peterson’s Vheaps [9], which is based on AVL trees (and is an instance of Høyer’s family of ranked priority queues [7]), Takaoka’s 2-3 heaps [11], Ka- plan and Tarjan’s thin heaps and fat heaps [8], Elmasry’s violation heaps [2], and most recently, Haeupler, Sen, and Tarjan’s rank-pairing heaps [6]. The classical pairing heaps [4,10,3] are another popular variant that performs well in practice, although they do not guarantee O(1) decrease-key cost. Among all the data structures that guarantee constant decrease-key and log- arithmic delete-min cost, Fibonacci heaps have remained the most popular to teach. The decrease-key operation uses a simple “cascading cut” strategy, which requires an extra bit per node for marking. For the analysis, the potential func- tion itself is not complicated, but one needs to first establish bounds on the maximum degree of the trees (Fibonacci numbers come into play here), and this requires understanding some subtle structural properties of the trees formed (a node may lose at most one child when it is not a root, but may lose multiple chil- dren when it is a root). In contrast, Vheaps are more straightforward to analyze, A. Brodnik et al. (Eds.): Munro Festschrift, LNCS 8066, pp. 27–32, 2013. c Springer-Verlag Berlin Heidelberg 2013 28 T.M. Chan for those already acquainted with AVL trees, but the decrease-key() algorithm requires division into multiple cases, like the update algorithms of most balanced search trees. The recent rank-pairing heaps interestingly avoid cascading cuts by performing cascading rank changes, which may lead to a simpler implementation, but from the teaching perspective, the analysis appears even more complicated than for Fibonacci heaps (and there are also divisions into multiple cases). In this note, we describe a data structure that is arguably the easiest to understand among all the existing methods. There is no case analysis involved, and no “cascading” during decrease-key(). We use a very simple, and rather standard, idea to ensure balance: be lazy during updates, and just rebuild when the structure gets “bad”. Previous methods differ based on what local structural invariants are imposed. Our method is perhaps the most relaxed, completely forgoing local constraints, only requiring the tracking of some global counters. (Violation heaps [2] are of a similar vein but require multiple local counters; our method is simpler.) In Section 2, we give a self-contained presentation of our method,1 which should be helpful for classroom use; it only assumes basic knowledge of amortized analysis. We find a description based on tournament trees the most intuitive, although the data structure can also be expressed more traditionally in terms of heap-ordered trees or half-ordered trees, as noted in Section 3. 2QuakeHeaps The Approach. We will work with a collection of tournament trees,where each element in S is stored in exactly one leaf, and the element of each internal node is defined as the minimum of the elements at the children. We require that at each node x, all paths from x to a leaf have the same length; this length is referred to as the height of x. We also require that each internal node has degree 2or1.SeeFigure1. 1 1 3 4 1 3 5 12 4 1 20 3 14 10 5 12 13 4 6 1 9 20 3 16 15 14 10 13 5 8 21 Fig. 1. An example Two basic operations are easy to do in constant time under these requirements: First, given two trees of the same height, we can link them into one, simply 1 Tradition demands a name to be given. The one in the title will hopefully make some sense after reading Section 2. Quake Heaps: A Simple Alternative to Fibonacci Heaps 29 by creating a new root pointing to the two roots, storing the smaller element among the two roots. Secondly, given a node x whose element is different from x’s parent’s, we can cut out the subtree rooted at x.Notethatx’s former parent’s degree is reduced to 1, but our setup explicitly allows for degree-1 nodes. Inserting an element can be trivially done by creating a new tree of size 1. The number of trees in the collection increases by 1, but can be reduced by linking at a convenient time later. For a delete-min operation, we can just remove the path of nodes that store the minimum element. The number of trees in the collection grows, and this is the time to do repeated linking operations to reduce the number of trees. Namely, whenever there are two trees of the same height, we link them. For a decrease-key operation on an element, let x be the highest node that stores the element. It would be too costly to update the elements at all the ancestors of x. Instead we can perform a cut at x. Then we can decrease the value of x at will in the separate new tree. We need to address one key issue: after many decrease-key operations, the trees may become too off-balanced. Let ni denote the number of nodes at height i. (In particular, n0 = n = |S|.) Our approach is simple—we maintain the following invariant for some fixed constant α ∈ (1/2, 1): ni+1 ≤ αni. (To be concrete, we can set α =3/4, for example.) The invariant clearly implies that the maximum height is at most log1/α n. When the invariant is violated for some i, a “seismic” event occurs and we remove everything from height i+1 and up, to allow rebuilding later. Since ni+1 = ni+2 = ··· = 0 now, the invariant is restored. Intuitively, events of large “magnitude” (i.e., events at low heights i) should occur infrequently. Pseudocode. We give pseudocode for all three operations below: insert(x): 1. create a new tree containing {x} decrease-key(x, k): 1. cut the subtree rooted at the highest node storing x [yields 1 new tree] 2. change x’s value to k delete-min(): 1. x ← minimum of all the roots 2. remove the path of nodes storing x [yields multiple new trees] 3. while there are 2 trees of the same height: 4. link the 2 trees [reduces the number of trees by 1] 5. if ni+1 >αni for some i then: 6. let i be the smallest such index 7. remove all nodes at heights >i [increases the number of trees] 8. return x 30 T.M. Chan We can explicitly maintain a pointer to the highest node storing x for each element x; it is easy to update these pointers as linkings are performed. It is also easy to update the ni’s as nodes are created and removed. Lines 3–4 in delete-min() can be done in time proportional to the current number of trees, by using an auxiliary array of pointers to trees indexed by their heights. Analysis. In the current data structure, let N be the number of nodes, T be the number of trees, and B be the number of degree-1 nodes (the “bad” nodes). 1 Define the potential to be N + T + 2α−1 B. The amortized cost of an operation is the actual cost plus the change in potential. For insert(), the actual cost is O(1), and N and T increase by 1. So, the amortized cost is O(1). For decrease-key(), the actual cost is O(1), and T and B increase by 1. So, the amortized cost is O(1). For delete-min(), we analyze lines 1–4 first. Let T (0) be the value of T just before the operation. Recall that the maximum height, and thus the length of the path in line 2, is O(log n). We can bound the actual cost by T (0) + O(log n). Since after lines 3–4 there can remain at most one tree per height, T is decreased to O(log n). So, the change in T is O(log n) − T (0). Since linking does not create degree-1 nodes, the change in B is nonpositive. Thus, the amortized cost is O(log n). For lines 5–7 of delete-min(), let n(0) be the value of n just before these j j lines. We can bound the actual cost of lines 5–7 by n(0). The change in j>i j − (0) (0) (0) N is at most j>i nj . The change in T is at most +ni .Letbi be the (0) ≥ number of degree-1 nodes at height i just before lines 5–7. Observe that ni (0) − (0) (0) ≥ (0) − (0) ≥ − (0) 2ni+1 bi .Thus,bi 2ni+1 ni (2α 1)ni . Hence, the change in B − − (0) 1 is at most (2α 1)ni . Thus, the net change in T + 2α−1 B is nonpositive. We conclude that the amortized cost of lines 5–7 is nonpositive. Therefore, the overall amortized cost for delete-min() is O(log n). 3 Comments Like Fibonacci heaps, our method can easily support the meld (i.e., merge) operation in O(1) amortized time, by just concatenating the lists of trees. Many variations of the method are possible. Linking of equal-height trees can be done at other places, for example, immediately after an insertion or after lines 5–7 of delete-min(), without affecting the amortized cost. Alternatively, we can perform less linking in lines 3–4 of delete-min(), as long as the number of trees is reduced by a fraction if it exceeds Θ(log n). We can further relax the invariant to ni+c ≤ αni for any integer constant 1 c. In the analysis, the potential can be readjusted to N + T + c(2α−1) B.Itis straightforward to check that the amortized number of comparisons per decrease- 1 key()isatmost1+c(2α−1) , which can be made arbitrarily close to 1 at the Quake Heaps: A Simple Alternative to Fibonacci Heaps 31 expense of increasing the constant factor in delete-min(). (A similar tradeoff of constant factors is possible with Fibonacci heaps as well, by relaxing the “lose at most one child per node” property to “at most c children” [5].) In the tournament trees, it is convenient to assume that the smaller child of each node is always the left child (and if the node has degree 1, its only child is the left child). 1 1 1 1 3 9320 4 3 1 4 3 6 12 16 14 4 1 20 4 12 3 14 13 15 20 12 14 114159 20 4 6 12 13 3 16 9 6 1316 15 Fig. 2. Transforming a tournament tree into a heap-ordered tree or a half-ordered tree The tournament trees require a linear number of extra nodes, but more space- efficient representations are possible where each element is stored in only one node. One option is to transform each tournament tree T into a heap-ordered, O(log n)-degree tree T : the children of x in T are the right children of all the nodes storing x in T . See Figure 2 (middle). Binomial heaps and Fibonacci heaps are usually described for trees of this form. Another option is to transform T into a binary tree T as follows: after short- cutting degree-1 nodes in T , the right child of x in T is the right child of the highest node storing x in T ; the left child of x in T is the right child of the sibling of the highest node storing x in T . See Figure 2 (right). The resulting tree T is a half-ordered binary tree: the value of every node x is smaller than the value of any node in the right subtree of x. Høyer [7] advocated the use of such trees in implementation. It is straightforward to redescribe our method in terms of half-ordered binary trees. For example, see [7] on the analogous linking and cutting operations. While our method is simple to understand conceptually, we do not claim that it would lead to the shortest code, nor the fastest implementation in practice, compared to existing methods. Philosophically, Peterson’s and Høyer’s work demonstrated that a heap data structure supporting decrease-key() in constant amortized time can be obtained from techniques for balanced search trees supporting deletions in constant amor- tized time. The moral of this note is that the heap problem is in fact simpler than balanced search trees—a very simple lazy update algorithm suffices to en- sure balance for heaps. References 1. Driscoll, J., Gabow, H., Shrairman, R., Tarjan, R.: Relaxed heaps: an alternative to Fibonacci heaps with applications to parallel computation. Commun. ACM 31, 1343–1354 (1988) 32 T.M. Chan 2. Elmasry, A.: The violation heap: a relaxed Fibonacci-like heap. Discrete Math., Alg. and Appl. 2, 493–504 (2010) 3. Elmasry, A.: Pairing heaps with O(log log n) decrease cost. In: Proc. 20th ACM– SIAM Sympos. Discrete Algorithms, pp. 471–476 (2009) 4. Fredman, M., Sedgewick, R., Sleator, D., Tarjan, R.: The pairing heap: a new form of self-adjusting heap. Algorithmica 1, 111–129 (1986) 5. Fredman, M., Tarjan, R.: Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM 34, 596–615 (1987) 6. Haeupler, B., Sen, S., Tarjan, R.E.: Rank-pairing heaps. SIAM J. Comput. 40, 1463–1485 (2011) 7. Høyer, P.: A general technique for implementation of efficient priority queues. In: Proc. 3rd Israel Sympos. Theory of Comput. Sys., pp. 57–66 (1995) 8. Kaplan, H., Tarjan, R.: Thin heaps, thick heaps. ACM Trans. Algorithms 4(1), 3 (2008) 9. Peterson, G.: A balanced tree scheme for meldable heaps with updates. Tech. Report GIT-ICS-87-23, Georgia Institute of Technology (1987) 10. Pettie, S.: Towards a final analysis of pairing heaps. In: Proc. 46th IEEE Sympos. Found. Comput. Sci., pp. 174–183 (2005) 11. Takaoka, T.: Theory of 2-3 heaps. Discrete Applied Math. 126, 115–128 (2003) Variations on Instant Insanity Erik D. Demaine1,MartinL.Demaine1, Sarah Eisenstat1, Thomas D. Morgan2, and Ryuhei Uehara3 1 MIT Computer Science and Artificial Intelligence Laboratory, 32 Vassar St., Cambridge, MA 02139, USA {edemaine,mdemaine,seisenst}@mit.edu 2 Harvard University School of Engineering and Applied Sciences, 33 Oxford St., Cambridge, MA 02138, USA [email protected] 3 School of Information Science, Japan Advanced Institute of Science and Technology (JAIST), Asahidai 1-1, Nomi, Ishikawa 923-1292, Japan [email protected] Abstract. In one of the first papers about the complexity of puzzles, Robertson and Munro [14] proved that a generalized form of the then- popular Instant Insanity puzzle is NP-complete. Here we study several variations of this puzzle, exploring how the complexity depends on the piece shapes and the allowable orientations of those shapes. Prepared in honor of Ian Munro’s 66th birthday. 1 Introduction In the late 1960s, the company Parker Brothers popularized a puzzle known as Instant Insanity1. Instant Insanity is composed of four cubes, where each face of each cube is colored red, green, white, or blue. The goal is to arrange the cubes in a tower with dimensions 1 × 1 × 4 so that on each of the four long sides of the tower, every color appears (exactly once per side). This puzzle has a rich history — the name Instant Insanity dates back to 1967 [13], but there were many earlier variants, released under such names as Katzenjammer, Groceries, and The Great Tantalizer [12]. The mathematics behind the Instant Insanity puzzle have been studied ex- tensively, and the puzzle is used as a sample application of graph theory in some textbooks [1,4,16]. In 1978, Robertson and Munro [14] showed that, by generalizing the number of colors and cubes from 4 to n, the puzzle becomes NP-complete to solve; they also proved a two-player variant PSPACE-complete. Their paper was one of the first to study the computational complexity of puz- zles and games [5,8,11]. More recently, there have been two studies of variants 1 The name “Instant Insanity” was originally trademarked by Parker Brothers in 1967. The trademark is currently owned by Winning Moves, Inc. A. Brodnik et al. (Eds.): Munro Festschrift, LNCS 8066, pp. 33–47, 2013. c Springer-Verlag Berlin Heidelberg 2013 34 E.D. Demaine et al. Fig. 1. A modern instance of Instant Insanity (left, distributed by Winning Moves, Inc., 2010), and a much older The Great Tantalizer (right, indicated only as British Made, consisting of wooden blocks). of Instant Insanity. In 2002, Jebasingh and Simoson [10] studied variants of the problem with Platonic solid pieces. In 2008, Berkove et al. [3] studied a problem in which the goal is to combine cubes to form a larger box with consistent colors on each side. Our Results. Inspired by Robertson and Munro [14], our goal is to explore how the complexity of the puzzle changes with the shape of the pieces and the set of allowable motions. In particular, we consider puzzles in which all of the pieces are shaped like identical right prisms, and the goal is to stack the pieces to form a taller prism with the same base. In Section 2, we establish a combinatorial definition for the pieces of a puzzle, and give a formal definition of the Instant Insanity problem. In Section 3.2, we examine the case of pieces where the base of the prism is a regular polygon. When the base is an equilateral triangle, we show that the problem is easy to solve. When the base is a square (but the piece is not a cube), we prove that the problem is NP-complete, even though the number of allowable configurations for each piece is only a third as large as the number of configurations for the original Instant Insanity problem. In Section 3.3, we consider the case of regular polygon prisms where the mo- tion is restricted, and show that even in the case of equilateral triangle pieces with three possible configurations per piece, the problem remains NP-complete. Finally, in Section 4, we prove results about some irregular prism pieces, using a technique for solving any puzzle in which each piece has two possible configu- rations. 2 Definitions 2.1 Instant Insanity Let C be a finite set of colors. Given a polyhedral piece shape,letk1 be the number of potentially visible sides, and let k2 be the number of sides that are Variations on Instant Insanity 35 Fig. 2. A rendering of the original Instant Fig. 3. A generalized version of the puzzle Insanity puzzle. Although the back of the with octagonal prism pieces. The top and tower is not shown, each color occurs ex- bottom of each prism can never lie on any actly once on each of the four long sides of the eight sides of the tower. The other of the tower of blocks. eight faces are visible at all times. visible in any given configuration. In this paper, we restrict ourselves to pieces in the shape of a right prism, which often implies that k1 = k2. For each (poten- tially visible) side of the piece shape, we assign a unique number from the set k1 {1,...,k1}. Hence, a single piece can be represented by a tuple in C assigning a color to each of the k1 sides. When defining a piece, we sometimes use the special symbol ∗, which represents a unique color used once in the entire puzzle. The set of possible configurations of a single piece is given by the piece con- k figurations P ⊆{1,...,k1} 2 . Each piece configuration indicates how the colors in the original piece should be assigned to the visible sides. Specifically, a piece configuration is a mapping from each of the k2 visible sides to the index of one of the sides of the piece shape. A single side of a single piece cannot appear on multiple sides of the puzzle, so each piece configuration has the additional restriction that no element of the tuple is repeated. k For each visible side 1 ≤ i ≤ k2, we define the function Fi : C 1 × P → C to return the color of side i, given a piece and its configuration. Formally, we say: Fi( a1,...,ak1 , q1,...,qk2 )=aqi . As an example, we consider the original Instant Insanity puzzle. Each cube has k1 = 6 sides with colors on them; only k2 = 4 of those sides are visible when the cubes are stacked vertically. Suppose that we number the sides as depicted in Fig. 4. Then there are 24 possible piece configurations: 6 ways to choose the side that faces down, and 4 possible ways to rotate the visible faces. These 24 piece configurations are listed in Fig. 5. Many piece shapes, including the cube, have a number of symmetries. In particular, many have the following property: Definition 1. The set of piece configurations P is rotationally symmetric if P is closed under cyclic shifts. Using this combinatorial definition of piece configurations, we can formally define two variants of the Instant Insanity problem: 36 E.D. Demaine et al. 6 { 1, 2, 3, 4 , 2, 3, 4, 1 , 3, 4, 1, 2 , 4, 1, 2, 3 , 1, 4, 3, 2 , 2, 1, 4, 3 , 3, 2, 1, 4 , 4, 3, 2, 1 , 1 4 1, 5, 3, 6 , 5, 3, 6, 1 , 3, 6, 1, 5 , 6, 1, 5, 3 , 2 3 1, 6, 3, 5 , 5, 1, 6, 3 , 3, 5, 1, 6 , 6, 3, 5, 1 , 5 2, 5, 4, 6 , 5, 4, 6, 2 , 4, 6, 2, 5 , 6, 2, 5, 4 , 2, 6, 4, 5 , 5, 2, 6, 4 , 4, 5, 2, 6 , 6, 4, 5, 2 } Fig. 4. Labels for each of the Fig. 5. The 24 different piece configurations for the faces on a cube cube piece depicted in Fig. 4 Definition 2. The Complete-Insanity(P ) problem is defined as follows: Input: AsetofcolorsC and a sequence of pieces A1,...,An,wheren = |C|. Output: Yes if and only if there is a sequence of configurations p1,...,pn ∈ P such that for each side 1 ≤ i ≤ k2,thesetofvisiblecolors{Fi(Aj ,pj ) | 1 ≤ j ≤ n} = C. Definition 3. The Partial-Insanity(P ) problem is defined as follows: Input: AsetofcolorsC and a sequence of pieces A1,...,An,wheren ≤|C|. Output: Yes if and only if there is a sequence of configurations p1,...,pn ∈ P such that for each side 1 ≤ i ≤ k2, all of the visible colors Fi(Aj ,pj) on side i are distinct. Note that both problems require all visible colors on a single side to be distinct; however, the Partial-Insanity(P ) problem only requires a subset of all of the colors to be visible on a single side, while the Complete-Insanity(P )problem requires all colors to be visible. Clearly, the Partial-Insanity(P )problemisat least as hard as the Complete-Insanity(P ) problem, and both are contained in the complexity class NP. 2.2 Positive Not-All-Equal Satisfiability In this paper, we prove that several variants of the Instant Insanity puzzle are NP-complete to solve by reducing from a known NP-complete problem. The problem we use for these reductions is a variant of the 3-Sat problem known as Positive-Not-All-Equal-Sat,orPositive-NAE-Sat. Definition 4. The Positive-NAE-Sat problem is defined as follows: Input: Asetofn variables x1,...,xn and m clauses C1,...,Cm.Eachclause Ci is composed of three positive literals ci,1,ci,2,ci,3 ∈{x1,...,xn}. Output: Yes if there exists some mapping φ : {x1,...,xn}→{T,F} such that each clause Ci has at least one literal ci,j1 such that φ(ci,j1 )=T ,and at least one literal ci,j2 such that φ(ci,j2 )=F . This problem was one of many Boolean satisfiability problems shown to be NP- complete by Schaefer [15]. Variations on Instant Insanity 37 3 Regular Prism Pieces 3.1 Partial versus Complete Insanity In this section, we show that for many types of regular pieces, if the Partial- Insanity(P ) problem is NP-complete, then the Complete-Insanity(P )prob- lem is NP-complete. We do this by way of a third problem in which the use of each color is restricted. Specifically, we restrict the number of occurrences of c ∈ C: the sum over all pieces Ai of the number of sides of Ai with the color c. Definition 5. The One-or-All-Insanity(P ) problem is defined as follows: Input: AsetofcolorsC and a sequence of pieces A1,...,An,wheren ≤|C|. Furthermore, the number of occurrences of each color c ∈ C is either 1 or k2. Output: Yes if and only if there is a sequence of configurations p1,...,pn ∈ P such that for each side 1 ≤ i ≤ k2, all of the visible colors Fi(Aj ,pj) on side i are distinct. Lemma 1. Suppose that k1 = k2 and the set of piece configurations P is ro- tationally symmetric. Then there exists a polynomial-time reduction from the problem Partial-Insanity(P ) to the problem One-or-All-Insanity(P ). Proof. Suppose that we are given an instance of the Partial-Insanity(P )prob- lem consisting of colors C and pieces A1,...,An. Using these pieces, we construct an instance of the One-or-All-Insanity(P ) problem as follows: 1. The first n pieces are identical to the pieces A1,...,An. 2. For each color c ∈ C,let#(c) be the number of occurrences of c in the set of pieces A1,...,An.If#(c)=1or#(c)=k2, then we do not need to do anything. If #(c) >k2, then the puzzle must be impossible to solve. Otherwise, we generate k2 − #(c) new pieces, each defined as follows: ∗ ∗ ∗ c, , ,..., . k2 − 1times (Recall that each ∗ symbol represents a unique color used exactly once.) Let D be the set of colors generated by this process, and let B1,...,Bm be the pieces. Our construction ensures that the pieces B1,...,Bm form a valid instance of the One-or-All-Insanity(P ) problem. We must additionally show that the puzzle formed by A1,...,An canbesolvedifandonlyifB1,...,Bm can be solved. Suppose that we have a solution p1,...,pn to the problem A1,...,An.Ifwe use p1,...,pn to configure B1,...,Bn, then we are guaranteed that for the first n pieces, no color is used twice on the same side. So our goal is to find a way to configure the remaining m − n pieces. All of the new colors generated in step 2 of the reduction occur exactly once, so they can be used on any side of the puzzle. Because the set of piece configurations P is rotationally symmetric, the 38 E.D. Demaine et al. first color in each piece Bi for n +1≤ i ≤ m can be placed on any side of the puzzle. Each color occurs at most k2 times, so it is straightforward to arrange the pieces Bn+1,...,Bm to ensure that no color occurs twice on any side. Furthermore, if there exists a solution q1,...,qm to the problem B1,...,Bm, then we can find a solution to A1,...,An using the piece configurations q1,...,qn. This means that our polynomial-time reduction is correct. Lemma 2. Suppose that k1 = k2 and the set of piece configurations P is ro- tationally symmetric. Then there exists a polynomial-time reduction from One- or-All-Insanity(P ) to Complete-Insanity(P ). Proof. Suppose that we are given an instance of the One-or-All-Insanity(P ) problem consisting of colors C and pieces A1,...,An.LetC1 be the set of colors that are used once, and let C2 be the set of colors that are used k2 times. For each color c ∈ C2,letg(c) be a unique index in {1,...,|C2|}. For each 1 ≤ i ≤ k2,weconstructn pieces Bi,1,...,Bi,n and |C2| distinct { } colors Di = di,1,...,di,|C2| . If the piece Aj consists of the sequence of colors aj,1,...,aj,k2 , then we define the colors bi,j,1,...,bi,j,k2 for the piece Bi,j as follows: ∈ di,g(aj,k ), if aj,k C2; bi,j,k = aj,k, otherwise. ∈ ∪ ∪···∪ This ensures that each color c (C1 D1 Dk2 )isusedexactlyk2 times in the set of pieces B1,1,...,Bk2,n. Hence the number of colors is k2n,which is the same as the number of pieces, making this an instance of Complete- Insanity(P ). NowwewishtoshowthatA1,...,An is solvable if and only if B1,1,...,Bk2,n is solvable. First, suppose that B1,1,...,Bk2,n is solvable. This means that there is a way to configure B1,1,...,B1,n such that no color is used twice on a single side. The pieces B1,1,...,B1,n are almost identical to the pieces A1,...,An, with the exception that each color c ∈ C2 is replaced with the color d1,g(c). Hence, a configuration of B1,1,...,B1,n that does not reuse colors on any side must also be a configuration of A1,...,An that does not reuse colors on any side. Complete-Insanity So if B1,1,...,Bk2,n is a solvable instance of (P ), then A1,...,An is a solvable instance of One-or-All-Insanity(P ). Next, suppose that A1,...,An is solvable. This means that there is a se- quence of configurations p1,...,pn such that if we apply p1,...,pn to the pieces A1,...,An, then no color is used twice on a single side. Let σi be the circular shift of k2 elements by i so that σi( a1,...,ak2 )= ai+1 mod k2 ,...,ai+k2 mod k2 . Because P is rotationally symmetric, for any 1 ≤ i ≤ k2 and any 1 ≤ j ≤ n, σi(pj ) ∈ P . Suppose that we use the configuration σi(pj ) for the piece Bi,j . Suppose, for the sake of contradiction, that there is some pair of distinct pieces Bi1,j1 and Bi2,j2 that assigns the same color c to the same side of the puzzle. Note that the ∪ colors of Bi1,j1 must be a subset of C1 Di1 , while the colors of Bi2,j2 must be ∪ a subset of C1 Di2 . We consider three cases: Variations on Instant Insanity 39 7 8 6 1 5 4 2 3 Fig. 6. Labels for each of the faces on an 8-sided regular prism Case 1: i1 = i2. Then it must be that c ∈ C1. Because A1,...,An is an instance One-or-All-Insanity of (P ), there is exactly one piece Aj3 that uses the color c. By construction of the pieces Bi1,j1 and Bi2,j2 ,itmustbethat j1 = j2 = j3, and the index of c is the same in both pieces. The configuration of Bi1,j1 is σi1 (pj1 ), while the configuration of Bi2,j2 is σi2 (pj2 )=σi2 (pj1 ). Hence the configurations would map the color c to different sides of the puzzle, contradicting our assumption that c occurs twice on the same side. Case 2: i1 = i2 and c ∈ C1. Because c ∈ C1, it is used exactly once in the original set of pieces A1,...,An. Therefore, it is also used exactly once in the set of pieces Bi1,1,...,Bi1,n, and so if it occurs both in Bi1,j1 and Bi2,j2 = Bi1,j2 , then we must have j1 = j2. Again, this means that c is not used twice. Case 3: i1 = i2 and c/∈ C1.Leti = i1 = i2.Byourassumption,weknow that there exists some such that F(Bi,j1 ,σi(pj1 )) = F(Bi,j2 ,σi(pj2 )) = c. Because σi is a cyclic shift, this means that there is some such that F (Bi,j1 ,pj1 )=F (Bi,j2 ,pj2 )=c. By construction of Bi,j1 and Bi,j2 ,this means that F (Aj1 ,pj1 )=F (Aj2 ,pj2 ), which is a contradiction. The combination of Lemmas 1 and 2 yields the following theorem: Theorem 1. Suppose that k1 = k2 and the set of piece configurations P is rotationally symmetric. Then there exists a polynomial-time reduction from the Partial-Insanity(P ) problem to the Complete-Insanity(P ) problem. 3.2 Regular Prism Pieces Definition 6. The k-sided regular prism is a right prism whose base is a regular k-sided polygon. We leave the bases of the prism unlabeled, because they cannot become visible. The other k faces we label in order, as depicted in Fig. 6. We define Rk to be the set of piece configurations of a k-sided regular prism: in particular, Rk is the union of all cyclic shifts of 1,...,k and its reverse. Note that in the case of k = 4, we assume that the height of the prism and the side length of the square base are distinct, so that the pieces do not have the full range of motion of the original Instant Insanity puzzle. Our first result concerns right prism pieces with an equilateral triangle base: 40 E.D. Demaine et al. Theorem 2. The Partial-Insanity(R3) problem can be solved in polynomial time. Proof. Let Pk be the set of all permutations of {1,...,k}. By definition, R3 = P3.Furthermore,foranyk, the set of piece configurations Pk is rotationally sym- metric, so by Theorem 1, if the Complete-Insanity(Pk) problem is solvable in polynomial time, then the Partial-Insanity(Pk) problem is also solvable in polynomial time. Hence we may examine the Complete-Insanity(Pk)instead. In particular, our goal is to show that Complete-Insanity(Pk)canbesolved if and only if every color c ∈ C occurs exactly k times in the pieces A1,...,An. It is easy to see that if a particular series of pieces A1,...,An can be solved, then the number of occurrences of each color must be k. We may show the converse by induction on k. First, consider the base case Complete-Insanity(P1). If all colors occur exactly once, then the only possible configuration of the puzzle is in fact a solved state. By induction, we assume that Complete-Insanity(Pk−1)canbe solved if each color is used exactly k −1 times. Suppose that we have an instance A1,...,An of the Complete-Insanity(Pk) puzzle in which each color is used exactly k times. We construct a multigraph G as follows: 1. For each index 1 ≤ i ≤ n,constructanodeui. 2. For each color c ∈ C,constructanodevc. 3. For each piece Ai =(a1,...,ak) and each side 1 ≤ j ≤ k, construct an edge from ui to vaj . (Note that this may result in the creation of parallel edges.) Because each piece has k colors, and each color is used exactly k times, G is a k-regular bipartite multigraph. By applying Hall’s theorem√ [7], we know that G has a perfect matching, which can be computed in O(kn n) time with the Hopcroft-Karp algorithm [9]. For each edge (ui,vc) in the matching, we wish to configure piece Ai so that the color on the first visible side is c.Byusing the matching to determine the colors on side 1, we ensure that no color will occur twice. Furthermore, because the set of piece configurations Pk consists of all permutations, we know that for each piece Ai, the remaining k − 1sides can be arbitrarily assigned to the remaining k − 1 visible sides of the puzzle. In particular, we are left with an instance of the Complete-Insanity(Pk−1) problem in which each color occurs k − 1 times. Hence, by induction, the puzzle Partial-Insanity R is solvable.√ In particular, the ( 3) problem can be solved in O(n n)time. Note that the structure of this proof reveals some interesting properties about the problem Complete-Insanity(R3). In particular, we don’t need to know anything about the assignment of colors to pieces to determine whether a given Complete-Insanity(R3) puzzle can be solved — we need only check whether the number of occurrences of each color is 3. Furthermore, careful analysis reveals that the reduction of Theorem 1 will produce an Complete-Insanity(R3) puz- zle with 3 copies of each color if and only if the original Partial-Insanity(R3) puzzle has at most 3 copies of each color. Hence, to determine whether a given Variations on Instant Insanity 41 instance of Partial-Insanity(R3) can be solved, it is sufficient to check that every color occurs ≤ 3 times. The Partial-Insanity(R4) problem is not as easy to solve: Theorem 3. The Partial-Insanity(R4) problem is NP-complete. Proof. We show that Partial-Insanity(R4) is NP-complete by a reduction from the Positive-NAE-Sat problem. Suppose that we are given a Positive- NAE-Sat instance θ with n clauses, each containing three literals. Let m be the number of variables. Then we can represent which literals are associated with which variables by a function γ : {0,...,3n − 1}→{0,...,m− 1} mapping the index of each literal to the index of the corresponding variable. Let L(i)={x | γ(x)=i}, and let (i, k)bethekth literal index in L(i). Then our reduction proceeds as follows. For each literal index 0 ≤ x ≤ 3n − 1, add three colors: ax, bx,andcx.For each variable 0 ≤ i ≤ m − 1 and each index 0 ≤ h ≤|L(i)|−1, let x = (i, h) and y = (i, (h +1)mod|L(i)|). Use these values to construct two pieces: Ax,0 = ax,bx,cx,bx Ax,1 = ax,cx,by,cx Intuitively, the placement of the color ax will determine whether or not the corresponding literal is true — in particular, the structure of the pieces Ax,0 and Ax,1 ensures that the two copies of the color ax must occur on opposite sides of the puzzle. Hence the color ax can either be placed on sides 1 and 3, or on sides 2 and 4. These two possibilities represent the two possible assignments to literal x. The use of the color by in Ax,1 ensures that the assignment to literal x is the same as the assignment to literal y, so that the assignment is consistent. We must also add pieces to ensure that the assignment is satisfying. For each clause 0 ≤ j ≤ n−1, add a new color dj and construct the following three pieces: B3j+0 = dj ,a3j+0, ∗, ∗ B3j+1 = dj ,a3j+1, ∗, ∗ B3j+2 = dj ,a3j+2, ∗, ∗ We wish to show that, when taken together, these pieces form a puzzle that can be solved if and only if the original Positive-NAE-Sat problem can be solved. Suppose that we have a consistent solution to the original Positive-NAE- Sat instance θ. We can represent this solution as a function φ : {1,...,3n}→ {T,F} assigning a value of true or false to each of the literals. This assign- ment has the property that for any pair of indices j1,j2,ifγ(j1)=γ(j2), then φ(j1)=φ(j2). Using this assignment, we wish to construct configurations p0,0,p0,1,...,p3n−1,0,p3n−1,1 for the pieces A0,0,A0,1,...,A3n−1,0,A3n−1,1 and configurations q0,...,q3n−1 for the pieces B0,...,B3n−1.Wedefinethesecon- figurations as follows: – For each literal 0 ≤ x ≤ 3n−1, if φ(x)=T ,thenwesetpx,0 = 1, 2, 3, 4 and px,1 = 3, 4, 1, 2. Otherwise, we set px,0 = 2, 3, 4, 1 and px,1 = 4, 1, 2, 3. 42 E.D. Demaine et al. – For each clause 0 ≤ j ≤ n − 1, we assign q3j+0, q3j+1,andq3j+2 according to the following table: φ(3j +0)φ(3j +1)φ(3j +2) q3j+0 q3j+1 q3j+2 T T F 1, 2, 3, 4 3, 4, 1, 2 2, 3, 4, 1 T F T 1, 2, 3, 4 2, 3, 4, 1 3, 4, 1, 2 T F F 1, 2, 3, 4 2, 3, 4, 1 4, 1, 2, 3 F T T 4, 1, 2, 3 3, 4, 1, 2 1, 2, 3, 4 F T F 4, 1, 2, 3 3, 4, 1, 2 2, 3, 4, 1 F F T 4, 1, 2, 3 2, 3, 4, 1 1, 2, 3, 4 It may be verified that by configuring the pieces in this way, we ensure that no color appears twice on the same side of the puzzle. Hence we have shown that the existence of a solution to the Positive-NAE-Sat instance implies the existence of a solution to the constructed Partial-Insanity(R4) puzzle. Suppose now that the Partial-Insanity(R4) problem can be solved. Let p0,0,...,p3n−1,1 be the sequence of configurations for the pieces A0,0,...,A3n−1,1, and let q0,...,q3n−1 be the sequence of configurations for B0,...,B3n−1.Then we construct an assignment function φ : {1,...,3n}→{T,F} as follows: for each literal 0 ≤ x ≤ 3n − 1, if the configuration px,0 =(s1,s2,s3,s4), then we define φ(x)=T if and only if s1 ≡ 1 (mod 2). To see that this is a valid assignment, we must show that this assignment is both consistent and satisfying. Suppose, for the sake of contradiction, that the assignment is not consistent. This means that there exists some variable i such that {φ(j) | γ(j)=i} = {T,F}. Then there must be some index h such that φ((i, h)) = φ((i, (h+1) mod |L(i)|)). Let x = (i, h) and let y = (i, (h +1)mod|L(i)|). Without loss of generality, we may assume that φ(x)=F and φ(y)=T . Hence F2(Ay,0,py,0)= F4(Ay,0,py,0)=by. No color is used twice on the same side, so we know that either F1(Ax,1,px,1)=by or F3(Ax,1,px,1)=by. In either case, all possible configurations px,1 have the property that F2(Ax,1,px,1)=F4(Ax,1,px,1)=cx. By assumption, φ(x) = φ(y), so either F2(Ax,0,px,0)=cx or F4(Ax,0,px,0)=cx. In either case, we have a contradiction — colors cannot be repeated on the same side of the puzzle. Hence, the assignment of values to literals must be consistent. Now suppose that there is some clause j such that φ(3j +0)=φ(3j +1)= φ(3j+2). Without loss of generality, we may assume that all three of these values are T . For each literal index x ∈{3j +0, 3j +1, 3j +2}, pieces Ax,0 and Ax,1 must be configured so that they do not place the color cx on the same side of the puzzle. Furthermore, because φ(x)=T , we know that the configuration of Ax,0 must place the color ax on side 1 or side 3. Together, these constraints ensure that the configuration of Ax,1 must also place the color ax on side 1 or side 3. Hence between the pieces Ax,0 and Ax,1, the color ax must be placed both on side 1 and on side 3. Then Bx must place ax on either side 2 or side 4, and must therefore place dj on side 1 or 3. This holds for all x ∈{3j+0, 3j+1, 3j+2}.Asa result, dj must show up at least twice on either side 1 or side 3. This contradicts our assumption that the puzzle was solved. Variations on Instant Insanity 43 3.3 Regular Prism Pieces with Restricted Motion In this section, we consider what happens when the motion of the pieces is limited. In particular, we consider what happens when the pieces of the puzzle are mounted on a central dowel, so that the set of allowable motions is restricted to rotations around the dowel. Definition 7. We define Uk to be the unflippable piece configurations of the k-sided regular prism: in particular, Uk is the set of all cyclic shifts of 1,...,k. Theorem 4. The Partial-Insanity(Uk) problem is NP-complete for all k ≥ 3. Proof. Suppose that we are given a Positive-NAE-Sat instance θ with n clauses, each containing three literals. Let m be the number of variables. Again, we represent the relationship between variables and the corresponding literal indices with a function γ : {0,...,3n − 1}→{0,...,m− 1} mapping the index of each literal to the index of the corresponding variable. Let L(i)={x | γ(x)=i}, and let (i, j)bethejth literal index in L(i). Then our reduction proceeds as follows. For each literal index 0 ≤ x ≤ 3n − 1, construct six colors: ax, bx,1, bx,2, cx,1, cx,2,anddx. We then use these colors to define three pieces for each literal index x: Ax = a x,...,a x ,bx,1,bx,2 k − 2times ∗ ∗ Bx = ,..., ,ax,cx,1,cx,2 k − 3times ∗ ∗ ∗ Cx = ,..., ,ax,dx, k − 3times To ensure that all of the pieces A0,...,A3n−1 have the same configuration, we use a series of gadgets, each of which consists of k−1 identical pieces. Specifically, for every x ∈{0,...,3n − 2},wecreatek − 1 copies of the following piece: ∗ ∗ Gx = ,..., ,bx,1,bx+1,2 k − 2times These k − 1 copies of Gx, combined with the piece Ax, all have the color bx,1 on side k − 1. Hence, each piece must have a different configuration. There are k possible configurations, and k pieces, so each configuration is used exactly once. The configurations are rotationally symmetric, so we may suppose without loss of generality that the configuration of Ax is 1,...,k. Every other possible cyclic shift is used to configure one of the pieces Gx. Hence, the color bx+1,2 occurs on sides {1, 2, 3,...,k − 1} — everything except side k. So the only possible configuration for piece Ax+1 is 1,...,k. By induction, for any pair x1,x2,the configuration of Ax1 must be the same as the configuration of Ax2 . We also wish to ensure that for any x1,x2 such that γ(x1)=γ(x2), the configuration of Bx1 is the same as the configuration of Bx2 . We accomplish 44 E.D. Demaine et al. this with a nearly identical construction. For each variable i, and each index h ∈{0,...,|L(i)|−2},letx = (i, h) and let y = (i, h + 1). Then we create k − 1 copies of the following piece: ∗ ∗ Hx = ,..., ,cx,1,cy,2 k − 2times By a similar argument, this enforces the desired constraint. Finally, for each clause j ∈{0,...,n− 1}, we add one more piece: Dj = d 3j+0,...,d 3j+0 ,d3j+0,d3j+1,d3j+2 . k − 3times This completes the construction. Next, we must show that this construction is in fact a reduction: that there is a solution to this instance of the Partial- Insanity(Uk) problem if and only if there is a solution to the original Positive- NAE-Sat problem. Suppose that we are given an assignment φ : {0,...,3n − 1}→{T,F} map- ping each literal to true or false. Then we can construct a solution to the Partial-Insanity(Uk) puzzle as follows. For each Ax, use the configuration 1,...,k.Ifφ(x)=T , then the configuration of Bx is k, 1,...,k− 1 and the configuration of Cx is k − 1,k,1,...,k− 2. Otherwise, the configuration of Bx is k − 1,k,1,...,k − 2 and the configuration of Cx is k, 1,...,k − 1.The configuration of Dj is determined according to the following table: φ(3j +0)φ(3j +1)φ(3j +2) configuration of Dj T T F k, 1,...,k− 2,k− 1 T F T k − 1,k,1,...,k− 2 T F F k − 1,k,1,...,k− 2 F T T 1,...,k− 2,k− 1,k F T F k, 1,...,k− 2,k− 1 F F T 1,...,k− 2,k− 1,k It can be verified that by configuring the pieces in this way, we ensure that each color occurs at most once per side. ∈ Because the configurations of Ax1 and Ax2 are the same for any x1,x2 {0,...,3n − 1}, there is a way to configure the gadgets Gx so that the colors bx,1 and bx,2 occur exactly once on each visible side of the puzzle. Similarly, because ∈{ − } the configurations of Bx1 and Bx2 are the same for any x1,x2 0,...,3n 1 with γ(x1)=γ(x2), there is a way to configure the gadgets Hx. We have shown that if there exists a satisfying assignment for the original Positive-NAE-Sat problem, then there is a solution to the corresponding Partial-Insanity(Uk) puzzle. Now we wish to show the converse. To that end, suppose that we have a solution to the puzzle. For each literal x ∈{0,...,3n−1}, let px be the configuration of Ax,letqx be the configuration of Bx, and let rx be the configuration of Cx. Furthermore, for each clause j ∈{0,...,n−1},letsj be the configuration of Dj . Without loss of generality, suppose that p0 = 1,...,k. Variations on Instant Insanity 45 Then, as we have argued previously, the k − 1 copies of the pieces G0,...,G3n−2 ensure that px = 1,...,k for all literal indices x. We define our assignment function φ : {0,...,3n − 1}→{T,F} as follows: φ(x)=T if and only if qx = k, 1,...,k−1. To see that this assignment function is consistent, we recall that the k − 1 copies of the pieces H0,...,H3n−2 ensure ∈{ − } that qx1 = qx2 for all x1,x2 0,...,3n 1 with γ(x1)=γ(x2). Hence, if γ(x1)=γ(x2), then φ(x1)=φ(x2). It remains to show that our assignment function is satisfying: for all clauses j ∈{0,...,n−1}, {φ(3j+0),φ(3j+1),φ(3j+2)} = {T,F}. Suppose, for the sake of contradiction, that there is some clause with φ(3j +0) = φ(3j +1) = φ(3j +2). We know that px = 1,...,k for all x ∈{3j +0, 3j +1, 3j +2}, so the color ax already shows up on sides {1,...,k− 2}. Hence the configurations qx and rx must be in the set {k, 1,...,k− 1, k − 1,k,1,...,k− 2}. We also know that qx = rx for all x ∈{3j +0, 3j +1, 3j +2}. If φ(3j +0)= φ(3j +1)= φ(3j +2)= T ,thenq3j+0 = q3j+1 = q3j+2 = k, 1,...,k− 1,andr3j+0 = r3j+1 = r3j+2 = k − 1,k,1,...,k− 2. This means that the three pieces C3j+0, C3j+1,andC3j+2 map the three colors d3j+0, d3j+1, and d3j+2 to side 1. Hence, there is no way to configure Dj to avoid duplicating one of the colors on one of the sides. A similar argument shows that setting φ(3j +0)=φ(3j +1)=φ(3j +2)=F also leads to contradiction. Hence, the assignment is satisfying as well as consistent. 4 Irregular Prism Pieces In this section, we consider less regular pieces. Because the symmetries of the shape determine the number of possible configurations, puzzles with highly asym- metric shapes are easy to solve. For instance, if all edge lengths are distinct (as inthecaseofagenerick-gon), then there is exactly one possible configuration for each piece, making the puzzle trivial to solve. Nonetheless, there are a few shapes with interesting symmetries, some of which we discuss here. The results in this section derive from the following theorem: Theorem 5. For any set of piece configurations P ,if|P | =2,thenPartial- Insanity(P ) can be solved in polynomial time. Proof. We may show this by a reduction to 2-Sat.Letp1,p2 be the two piece configurations in P . Suppose that we are given a set of pieces A1,...,An.Then we construct two variables for each piece Ai:avariablexi,1 that is true if and only if Ai is in configuration p1, and a variable xi,2 that is true if and only if Ai is in configuration p2. We additionally construct two clauses for each Ai: (xi,1 ∨ xi,2)and(¬xi,1 ∨¬xi,2). This ensures that Ai must be placed in exactly one of the two configurations. Next, we construct constraints to ensure that no color is used twice. For each pair of piece indices 1 ≤ i1 = i2 ≤ n and for each pair of (not necessarily distinct) configurations j1,j2 ∈{1, 2},weexaminethek2 visible sides. If there ∈{ } exists some 1,...,k2 such that F(Ai1 ,pj1 )=F(Ai2 ,pj2 ), then we know 46 E.D. Demaine et al. 1 4 1 3 2 2 3 Fig. 7. Labels for the faces on a right Fig. 8. Labels for each of the potentially prism with an isoceles triangle base visible faces on a box that the pair of assigned configurations is invalid, and so we add a constraint ¬ ∨¬ ( xi1 ,j1 xi2 ,j2 ) to prevent the reuse of colors on a single side. Because these constraints completely encapsulate the requirements of the Partial-Insanity(P ) problem, we may use a standard 2-Sat algorithm to find a satisfying assignment [2,6], then use the satisfying assignment to deter- mine how we configure the pieces. For example, we can make use of Theorem 5 to help analyze the complexity of solving a puzzle with the following shape: Definition 8. Suppose that the piece shape is a right prism with an isoceles triangle base. If we number the sides of the prism in order around the base, as depicted in Fig. 7, then the set of configurations is T = {1, 2, 3, 1, 3, 2}. Because |T | = 2, we can show the following: Theorem 6. The problem Partial-Insanity(T ) can be solved in polynomial time. We can also use Theorem 5 to help us analyze more complex shapes: Definition 9. Suppose that the piece shape is a box with dimensions w × h × d, where the goal is to stack pieces into a tower with base w × h.Ifwenumberthe sides of the prism in order around the base, as depicted in Fig. 8, then the set of configurations is B = {1, 2, 3, 4, 3, 4, 1, 2, 1, 4, 3, 2, 3, 2, 1, 4}. Theorem 7. The problem Partial-Insanity(B) can be solved in polynomial time. Proof. The set of configurations B is generated by allowing side 1 to swap freely with side 3, and allowing side 2 to swap freely with side 4. Hence, we can de- compose the Partial-Insanity(B) problem into two instances of the Partial- Insanity(P2) problem: one for sides 1 and 3, and one for sides 2 and 4. If we solve both halves of the problem with the technique of Theorem 5, it is straight- forward to combine the solutions to compute the configuration of each piece. 5Conclusion In this paper, we have examined several variants of Instant Insanity, exploring how the complexity changes as the geometry of the pieces changes. We have also Variations on Instant Insanity 47 explored how restricting the motion of the pieces can change the complexity. In particular, we have analyzed several types of triangular prism puzzles and rect- angular prism puzzles, discovering which variants are NP-complete and which canbesolvedinpolynomialtime. Our results leave open a few problems. In particular, the complexity of Partial-Insanity(Rk)fork ≥ 5 is still unknown. Because the Partial- Insanity(R4) problem is NP-complete, it is likely (but not yet proven) that the Partial-Insanity(Rk) problem is NP-complete for k ≥ 5 as well. References 1. Arlinghaus, W.C.: The tantalizing four cubes. In: Michaels, J.G., Rosen, K.H. (eds.) Applications of Discrete Mathematics, ch. 16. McGraw-Hill Higher Educa- tion (1991) 2. Aspvall, B., Plass, M.F., Tarjan, R.E.: A linear-time algorithm for testing the truth of certain quantified boolean formulas. Information Processing Letters 8(3), 121– 123 (1979) 3. Berkove, E., Van Sickle, J., Hummon, B., Kogut, J.: An analysis of the (colored cubes)3 puzzle. Discrete Mathematics 308(7), 1033–1045 (2008) 4. Chartrand, G.: Introductory Graph Theory, pp. 125–132. Courier Dover Publica- tions (1985); Originally published in 1977 as Graphs as Mathematical Models 5. Eppstein, D.: Computational complexity of games and puzzles (April 2013), http://www.ics.uci.edu/~eppstein/cgt/hard.html 6. Even, S., Itai, A., Shamir, A.: On the complexity of timetable and multicommodity flow problems. SIAM Journal on Computing 5(4), 691–703 (1976) 7. Hall, P.: On representatives of subsets. Journal of the London Mathematical Soci- ety s1-10(1), 26–30 (1935) 8. Hearn, R.A., Demaine, E.D.: Games, Puzzles, and Computation. A. K. Peters (July 2009) 9. Hopcroft, J.E., Karp, R.M.: An n5/2 algorithm for maximum matchings in bipartite graphs. SIAM Journal on Computing 2(4), 225–231 (1973) 10. Jebasingh, A., Simoson, A.: Platonic solid insanity. In: Congressus Numerantium, vol. 154, pp. 101–112 (2002) 11. Kendall, G., Parkes, A., Spoerer, K.: A survey of NP-complete puzzles. ICGA Journal 31(1), 13–34 (2008) 12. O’Beirne, T.H.: Puzzles and paradoxes. New Scientist 247, 358–359 (1961) 13. United States Patent and Trademark Office. Trademark Electronic Search System (TESS) (April 2013), http://tmsearch.uspto.gov/ 14. Robertson, E., Munro, I.: NP-completeness, puzzles and games. Utilitas Mathe- matica 13, 99–116 (1978) 15. Schaefer, T.J.: The complexity of satisfiability problems. In: Proceedings of the Tenth Annual ACM Symposium on Theory of Computing, vol. 14, pp. 216–226 (1978) 16. van Lint, J.H., Wilson, R.M.: A Course in Combinatorics. Cambridge University Press (2001) A Simple Linear-Space Data Structure for Constant-Time Range Minimum Query Stephane Durocher University of Manitoba, Winnipeg, Canada [email protected] Abstract. We revisit the range minimum query problem and present anewO(n)-space data structure that supports queries in O(1) time. Although previous data structures exist whose asymptotic bounds match ours, our goal is to introduce a new solution that is simple, intuitive, and practical without increasing asymptotic costs for query time or space. 1 Introduction 1.1 Motivation Along with the mean, median, and mode of a multiset, the minimum (equiv- alently, the maximum) is a fundamental statistic of data analysis for which efficient computation is necessary. Given a list A[0 : n − 1] of n items drawn from a totally ordered set, a range minimum query (RMQ) consists of an input pair of indices (i, j) for which the minimum element of A[i : j] must be returned. The objective is to preprocess A to construct a data structure that supports efficient response to one or more subsequent range minimum queries, where the corresponding input parameters (i, j) are provided at query time. Although the complete set of possible queries can be precomputed and stored using Θ(n2) space, practical data structures require less storage while still en- abling efficient response time. For all i,ifi = j, then a range query must report A[i]. Consequently, any range query data structure for a list of n items requires Ω(n) storage space in the worst case [7]. This leads to a natural question: how quickly can an O(n)-space data structure answer a range minimum query? Previous O(n)-space data structures exist that provide O(1)-time RMQ (e.g., [4–6, 14, 18], see Section 2). These solutions typically require a transformation or invoke a property that enables the volume of stored precomputed data to be reduced while allowing constant-time access and RMQ computation. Each such solution is a conceptual organization of the data into a compact table for efficient reference; essentially, the algorithm reduces to a clever table lookup. In this paper our objective is not to minimize the total number of bits occupied by the data structure (our solution is not succinct) but rather to present a sim- ple and more intuitive method for organizing the precomputed data to support Work supported in part by the Natural Sciences and Engineering Research Council of Canada (NSERC). A. Brodnik et al. (Eds.): Munro Festschrift, LNCS 8066, pp. 48–60, 2013. c Springer-Verlag Berlin Heidelberg 2013 A Simple Linear-Space Data Structure for Constant-Time RMQ 49 RMQ efficiently. Our solution combines new ideas with techniques from various previous data structures: van Emde Boas trees [16], resizable arrays [10], range mode query [11, 12, 23], one-sided√ RMQ [4], and a linear-space data structure that supports RMQ in O( n) time. The resulting RMQ data structure stores efficient representations of the data to permit direct lookup without requiring the indirect techniques employed by previous solutions (e.g., [1, 4–6, 18, 22, 27]) such as transformation to a lowest common ancestor query, Cartesian trees, Eu- lerian tours, or the Four Russians speedup. The data structure’s RMQ algorithm is astonishingly simple: it can be implemented as a single if statement with four branches, each of which returns the minimum of at most three values retrieved from precomputed tables (see the pseudocode for Algorithm 2 in Section 3.3). The RMQ problem is sometimes defined such that a query returns only the index of the minimum element instead of the minimum element itself. In partic- ular, this is the case for succinct data structures that support O(1)-time RMQ using only O(n) bits of space [14, 19, 20, 26] (see Section 2). In order to return the actual minimum element, say A[i], in addition to its index i,anysuchdata structure must also store the values from the input array A, corresponding to a lower bound of Ω(n log u) bits of space in the worst case when element are drawn from a universe of size u or, equivalently, Ω(n) words of space (this lower bound also applies to other array range query problems [7]). Therefore, a range query data structure that uses o(n) words of space requires storing the input array A separately, resulting in total space usage of Θ(n) words of space in the worst case. In this paper we require that a RMQ return the minimum element. Our RMQ data structure stores all values of A internally and matches the optimal asymptotic bounds of O(n) words of space and O(1) query time. 1.2 Definitions and Model of Computation We assume the RAM word model of computation with word size Θ(log u), where elements are drawn from a universe U = {−u,...,u− 1} for some fixed positive integer u>n. Unless specified otherwise, memory requirements are expressed in word-sized units. We assume the usual set of O(1)-time primitive operations: ba- sic integer arithmetic (addition, subtraction, multiplication, division, and mod- ulo), bitwise logic, and bit shifts. We do not assume O(1)-time exponentiation nor, consequently, radicals. When the base operand is a power of two and the re- sult is an integer, however, these operations can be computed using a bitwise left or right shifts. All arithmetic computations are on integers in U, and integer di- vision is assumed to return the floor of the quotient. Finally, our data structure only requires finding the binary logarithm of integers in the range {0,...,n}. Consequently, the complete set of values can be precomputed and stored in a table of size O(n)toprovideO(1)-time reference for the log (and log log) opera- tions at query time, regardless of whether logarithm computation is included in the RAM model’s set of primitive operations. A common technique used in array range searching data structures (e.g., [4, 11,23]) is to partition the input array A[0 : n−1] into a sequence of n/b blocks, each of size b (except possibly for the last block whose size is [(n−1) mod b]+1). 50 S. Durocher A query range A[i : j] spans between 0 and n/b complete blocks. We refer to the sequence of complete blocks contained within A[i : j]asthespan,tothe elements of A[i : j] that precede the span as the prefix, and to the elements of A[i : j] that succeed the span as the suffix. See Figure 1. One or more of the prefix, span, and suffix may be empty. When the span is empty, the prefix and suffix can lie either in adjacent blocks, or in the same block; in the latter case the prefix and suffix are equal. We summarize the asymptotic resource requirements of a given RMQ data structure by the ordered pair f(n),g(n),wheref(n) denotes the storage space it requires measured in words and g(n) denotes its worst-case RMQ time for an array of size n. Our discussion focuses primarily on these two measures of effi- ciency; other measures of interest include the preprocessing time and the update time. Note that similar notation is sometimes used to pair precomputation time and query time (e.g., [4, 18]). 2 Related Work Multiple ω(n),O(1) solutions are known, including precomputing RMQs for all query ranges in O(n2),O(1), and precomputing RMQs for all ranges of length 2k for some k ∈ Z+ in O(n log n),O(1) (Sparse Table Algorithm) [4,18]. In the latter case, a query is decomposed into two (possibly overlapping) precomputed√ queries. Similarly, O(n),ω(1) solutions exist, including the O(n),O( n) data structure described in Section 3.1, and a tournament tree which provides an O(n),O(log n) solution. This latter data structure (known in RMQ folklore, e.g., [25]) consists of a binary tree that recursively partitions the array A such that successive array elements are stored in order as leaf nodes, and each internal node stores the minimum element in the subarray of A stored in leaves below it. Given an arbitrary pair of array indices (i, j), a RMQ is processed by traversing the path from i to j in the tree and returning the minimum value stored at children of nodes on the path corresponding to subarrays contained in A[i : j]. Several O(n),O(1) RMQ data structures exist, many of which depend on the equivalence between the RMQ and lowest common ancestor (LCA) problems. Harel and Tarjan [22] gave the first O(n),O(1) solution to LCA. Their solution was simplified by Schieber and Vishkin [27]. Berkman and Vishkin [6] showed how to solve the LCA problem in O(n),O(1) by transformation to RMQ using an Euler tour. This method was simplified by Bender and Farach-Colton [4] to give an ingenious solution which we briefly describe below. Comprehensive overviews of previous solutions are given by Davoodi [13] and Fischer [17]. The array A[0 : n − 1] can be transformed into a Cartesian tree C(A)onn nodes such that a RMQ on A[i : j] corresponds to the LCA of the respective nodes associated with i and j in C(A). When each node in C(A) is labelled by its depth, an Eulerian tour on C(A) (i.e., the depth-first traversal sequence on C(A)) gives an array B[0 : 2n − 2] for which any two adjacent values differ by ±1. Thus, a LCA query on C(A) corresponds to a ±1-RMQ on B. Array B is partitioned into blocks of size (log n)/2. Separate data structures are constructed A Simple Linear-Space Data Structure for Constant-Time RMQ 51 to answer queries that are contained within a single block of B and those that span multiple blocks, respectively. In the former√ case,√ the ±1 property implies that the number of unique blocks in B is O( n); all O( n log2 n) possible RMQs on blocks of B are precomputed (the Four Russians technique [3]). In the latter case, a query can be decomposed into a prefix, span, and suffix (see Section 1.2). RMQs on the prefix and suffix are contained within respective single blocks, each of which can be answered in O(1) time as in the former case. The span covers zero or more blocks. The minimum of each block of B is precomputed andstoredinA[0 : 2n/ log n − 1]. A RMQ on A (the minimum value in the span) can be found in O(n),O(1) using the O(n log n),O(1) data structure mentioned above due to the shorter length of A (i.e., n =2n/ log n). Fischer and Heun [18] use similar ideas to give a O(n),O(1) solution to RMQ that applies the Four Russians technique to any array (i.e., it does not require the ±1 property) on blocks of length Θ(log n). Yuan and Atallah [29] examine RMQ on multidimensional arrays and give a new one-dimensional O(n),O(1) solution that uses a hierarchical binary decomposition of A[0 : n − 1] into Θ(n) canonical intervals, each of length 2k for some k ∈ Z+, and precomputed queries within blocks of length Θ(log n) (similar to the Four Russians technique). When only the minimum’s index is required, Sadakane [26] gives a succinct data structure requiring 4n + o(n) bits that supports O(1)-time RMQ. Fischer and Heun [19, 20] and Davoodi et al. [14] reduce the space requirements to 2n + o(n) bits. Finally, the RMQ problem has been examined in the dynamic setting [8,13], in two and higher dimensions [2,9,15,21,26,29], and on trees and directed acyclic graphs [5, 8, 15]. Various array range query problems have been examined in addition to range minimum query. See the survey by Skala [28]. 3ANew O(n),O(1) RMQ Data Structure √ The new data structure is described in steps, starting with a previous O(n),O( n) data structure, extending it to O(n log log n),O(log log n) by applying the tech- nique recursively, eliminating recursion to obtain O(n log log n),O(1), and finally reducing the space to O(n),O(1). To simplify the presentation, suppose initially k that the input array A has size n =22 ,forsomek ∈ Z+; as described in Section 3.5, removing this constraint and generalizing to an arbitrary n is easily achieved with- out any asymptotic increase in time or space. √ 3.1 O(n),O( n) Data Structure √ The following O(n),O( n) data structure is known in RMQ folklore (e.g., [25]) and has similar high-level structure to the ±1-RMQ algorithm of Bender and Farach-Colton [4, Section 4]. While subobtimal and often overlooked in favour of more efficient solutions, this data structure forms the basis for our new O(n),O(1) data structure. 52 S. Durocher prefix span suffix ij 0123456789101112131415 A 3333607443177898 n 0123 B 3104 n √ √ Fig.√ 1. A O(n),O( n) data structure: the array A is partitioned into n blocks of size n. The range minimum of each block is precomputed and stored in array B.A range minimum query A[2 : 14] is processed by finding the minimum of the respective minima of the prefix A[2 : 3], the span A[4 : 11] (determined by examining B[1 : 2]), and the suffix A[12 : 14]. In this example this corresponds to min{3, 0, 4} =0. √ √ The input array A[0 : n − 1] is partitioned into n blocks of size √n.The range minimum of each block is precomputed and stored in√ a table B[0 : n−1]. See Figure 1. A query range spans between zero and n complete blocks. The minimum of the span is computed by iteratively scanning the corresponding values in B. Similarly, the respective minima of the prefix and suffix are com- puted by iteratively examining their elements. The range minimum corresponds to the minimum of√ these three values. Since the prefix, suffix, and√ array B each contain at most n elements, the worst-case query time is Θ( n). The√ total space required by the data structure is Θ(n) (or, more precisely, n + Θ( n)). Precomputation requires only a single pass√ over the input array in Θ(n)time. Updates (e.g., set A[i] ← x)requireΘ( n) time in the worst case; whenever an array element equal to its block’s minimum is increased, the block must be scanned to identify the new minimum. 3.2 O(n log log n),O(log log n) Data Structure One-sided range minimum queries (where one endpoint of the query range co- incides with one end of the array A) are trivially precomputed [4] and stored in arrays C and C, each of size n,whereforeachi, min{A[i],C[i − 1]} if i>0, C[i]= A[0] if i =0, min{A[i],C[i +1]} if i Any subsequent one-sided RMQ on A[0 : j]orA[j : n − 1] can be answered in O(1) time by referring√ to C[j]orC [j]. The O(n),O( n) solution discussed√ in Section 3.1 includes three range min- imum queries on subproblems of size n, of which at most one is two-sided. A Simple Linear-Space Data Structure for Constant-Time RMQ 53 In particular, if the span is non-empty, then the query on array B is two-sided, and the queries on the prefix and suffix are one-sided. Similarly, if the query range is contained in a single block, then there is a single two-sided query and no one-sided queries. Finally, if the query range intersects exactly two blocks, then there are two one-sided queries (one each for the prefix and suffix) and no two-sided queries. Thus, upon adding arrays C and C to the data structure, at most one of the three (or fewer) subproblems requires ω(1) time to identify its range minimum. This search technique can be applied recursively on two-sided queries. By lim- iting the number of recursive calls to at most one and by reducing the problem size by an exponential factor of 1/2 at each step of the recursion, the resulting query time is bounded by the following recurrence (similar to that achieved by van Emde Boas trees [16]): √ T ( n)+O(1) if n>2, T (n) ≤ O(1) if n ≤ 2 ∈ O(log log n). (2) √ Each step invokes at most one recursive RMQ on a subarray of size n.Each recursive call is one of two types: i) a recursive call on array B (a two-sided query to compute the range minimum of the span) or ii) a recursive call on the entire query range (contained within a single block). Recursion can be avoided entirely for determining√ the minimum√ of the span (a n+1 recursive call of the first type). Since there are n blocks, 2 Table 1. The xth level is a sequence of bx(n) blocks of size sx(n) x 01 2... i ... log log n − 2loglogn − 1loglogn √ −2i 3/4 bx(n) n/2 n/4 n/16 ... n2 ... n n 1 √ 2i 1/4 sx(n)2416... 2 ... n nn 1 Throughout this manuscript, log a denotes the binary logarithm log2 a. 2 Level log log n is included for completeness since we refer to the size of the parent of blocks on level x,foreachx ∈{0,...,log log n − 1}. The only query that refers to level log log n directly is the complete array: i =0andj = n−1. The global√ minimum for this singular case can be stored using O(1) space and updated in O( n)timeas described in Section 3.1. 54 S. Durocher ∈{ } Generalizing (1), for each x 0,...,log log n the new arrays Cx and Cx are defined by min{A[i],Cx[i − 1]} if i =0mod sx(n), Cx[i]= A[i]ifi =0mods (n), x { } min A[i],Cx[i +1] if (i +1)=0modsx(n), and Cx[i]= A[i]if(i +1)=0modsx(n). We refer to a sequence of blocks on level x that are contained in a common block on level x +1 assiblings andtothecommonblockastheirparent.Eachblock on level x+ 1 is a parent to sx+1(n)/sx(n)=sx(n) siblings on level x.Thus,any query range contained in some block at level x +1 coversatmostsx(n) siblings 2 at level x, resulting in Θ(sx(n) )=Θ(sx+1(n)) distinct possible spans within a block at level x +1andΘ(sx+1(n) · bx+1(n)) = Θ(n) total distinct possible spans at level x + 1, for any x ∈{0,...,log log n − 1}. These precomputed range minima are stored in table D, such that for every x ∈{0,...,log log n−1},every b ∈{0,...,bx+1(n) − 1}, and every {i, j}⊆{0,...,sx(n) − 1}, Dx[b][i][j]stores the minimum of the span A[b · sx+1(n)+i · sx(n):b · sx+1(n)+(j +1)sx(n) − 1]. This gives the following recursive algorithm whose worst-case time is bounded by (2): Algorithm 1 RMQ(i, j) 1 if i =0and j = n − 1 // query is entire array 2 return minA // precomputed array minimum 3 else 4 return RMQ(log log n − 1,i,j) // start recursion at top level RMQ(x, i, j) 1 if x>0 2 bi ← i/sx(n) // blocks containing i and j 3 bj ← j/sx(n) 4 if bi = bj // i and j in same block at level√x 5 return RMQ(x − 1,i,j) // two-sided recursive RMQ: T ( n) time 6 else if bj − bi ≥ 2//spanisnon-empty 7 b ← i mod sx+1(n) { − } 8 return min Cx[i],Cx[j],Dx[b][bi +1][bj 1] // 2 one-sided RMQs + precomputed span: O(1) time 9 else { } 10 return min Cx[i],Cx[j] // 2 one-sided RMQs: O(1) time 11 else 12 return min{A[i],A[j]} // base case (block size ≤ 2): O(1) time The space required by array Dx for each level x Since arrays Cx and Cx also require O(n) space at each level, the total space required is O(n) per level, resulting in O(n log log n) total space for the complete data structure. For each level x 3.3 O(n log log n),O(1) Data Structure Each step of Algorithm 1 described in Section 3.2 invokes at most one recursive call on a subarray whose size decreases exponentially at each step. Specifically, the only case requiring ω(1) time occurs when the query range is contained within a single block of the current level. In this case, no actual computation or table lookup occurs locally; instead, the result of the recursive call is returned directly (see Line 5 of Algorithm 1). As such, the recursion can be eliminated by jumping directly to the level of the data structure at which the recursion terminates, that is, the highest level for which the query range is not contained in a single block. Any such query can be answered in O(1) time using a combination of at most three references to arrays C and D (see Lines 8 and 10 of Algorithm 1). We refer to the corresponding level of the data structure as the query level, whose index we denote by . More precisely, Algorithm 1 makes a recursive call whenever bi = bj,where bi and bj denote the respective indices of the blocks containing i and j in the current level (see Line 5 of Algorithm 1). Thus, we seek to identify the highest level for which bi = bj. In fact, it suffices to identify the highest level ∈ {0,...,log log n−1} for which no query of size j −i+1 can be contained within a single block. While the query could span the boundary of (at most) two adjacent blocks at higher levels, it must span at least two blocks at all levels less than or equal to . In other words, the size of the query range is bounded by s(n) s ,thenVi ← Vi ∩ I for 1 ≤ i ≤ s and Vs∗ +1 ← Vs∗+1 \ I.We further replace s∗ ← s and x∗ ← x.