Space-Optimal Quasi-Gray Codes with Logarithmic Read Complexity

Authors Diptarka Chakraborty, Debarati Das, Michal Koucký, Nitin Saurabh

Thumbnail PDF


  • Filesize: 474 kB
  • 15 pages

Document Identifiers

Author Details

Diptarka Chakraborty
  • Computer Science Institute of Charles University, Prague, Czech Republic
Debarati Das
  • Computer Science Institute of Charles University, Prague, Czech Republic
Michal Koucký
  • Computer Science Institute of Charles University, Prague, Czech Republic
Nitin Saurabh
  • Max-Planck-Institut für Informatik, Saarbrücken, Germany

Cite AsGet BibTex

Diptarka Chakraborty, Debarati Das, Michal Koucký, and Nitin Saurabh. Space-Optimal Quasi-Gray Codes with Logarithmic Read Complexity. In 26th Annual European Symposium on Algorithms (ESA 2018). Leibniz International Proceedings in Informatics (LIPIcs), Volume 112, pp. 12:1-12:15, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2018)


A quasi-Gray code of dimension n and length l over an alphabet Sigma is a sequence of distinct words w_1,w_2,...,w_l from Sigma^n such that any two consecutive words differ in at most c coordinates, for some fixed constant c>0. In this paper we are interested in the read and write complexity of quasi-Gray codes in the bit-probe model, where we measure the number of symbols read and written in order to transform any word w_i into its successor w_{i+1}. We present construction of quasi-Gray codes of dimension n and length 3^n over the ternary alphabet {0,1,2} with worst-case read complexity O(log n) and write complexity 2. This generalizes to arbitrary odd-size alphabets. For the binary alphabet, we present quasi-Gray codes of dimension n and length at least 2^n - 20n with worst-case read complexity 6+log n and write complexity 2. This complements a recent result by Raskin [Raskin '17] who shows that any quasi-Gray code over binary alphabet of length 2^n has read complexity Omega(n). Our results significantly improve on previously known constructions and for the odd-size alphabets we break the Omega(n) worst-case barrier for space-optimal (non-redundant) quasi-Gray codes with constant number of writes. We obtain our results via a novel application of algebraic tools together with the principles of catalytic computation [Buhrman et al. '14, Ben-Or and Cleve '92, Barrington '89, Coppersmith and Grossman '75].

Subject Classification

ACM Subject Classification
  • Theory of computation → Cell probe models and lower bounds
  • Gray code
  • Space-optimal counter
  • Decision assignment tree
  • Cell probe model


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. D. J. Amalraj, N. Sundararajan, and Goutam Dhar. Data structure based on Gray code encoding for graphics and image processing. In Proceedings of the SPIE: International Society for Optical Engineering, pages 65-76, 1990. Google Scholar
  2. David A. Mix Barrington. Bounded-width polynomial-size branching programs recognize exactly those languages in NC¹. Journal of Computer and System Sciences, 38:150-164, 1989. Google Scholar
  3. Michael Ben-Or and Richard Cleve. Computing algebraic formulas using a constant number of registers. SIAM J. Comput., 21(1):54-58, 1992. URL:
  4. James R. Bitner, Gideon Ehrlich, and Edward M. Reingold. Efficient generation of the binary reflected Gray code and its applications. Commun. ACM, 19(9):517-521, 1976. Google Scholar
  5. Prosenjit Bose, Paz Carmi, Dana Jansens, Anil Maheshwari, Pat Morin, and Michiel H. M. Smid. Improved methods for generating quasi-Gray codes. In Algorithm Theory - SWAT 2010, 12th Scandinavian Symposium and Workshops on Algorithm Theory, Bergen, Norway, June 21-23, 2010. Proceedings, pages 224-235, 2010. URL:
  6. Gerth Stølting Brodal, Mark Greve, Vineet Pandey, and Srinivasa Rao Satti. Integer representations towards efficient counting in the bit probe model. J. Discrete Algorithms, 26:34-44, 2014. URL:
  7. Harry Buhrman, Richard Cleve, Michal Koucký, Bruno Loff, and Florian Speelman. Computing with a full memory: catalytic space. In Symposium on Theory of Computing, STOC 2014, New York, NY, USA, May 31 - June 03, 2014, pages 857-866, 2014. URL:
  8. Diptarka Chakraborty, Debarati Das, Michal Koucký, and Nitin Saurabh. Optimal quasi-Gray codes: Does the alphabet matter? CoRR, 2017. URL:
  9. C. C. Chang, H. Y. Chen, and C. Y. Chen. Symbolic Gray code as a data allocation scheme for two-disc systems. The Computer Journal, 35(3):299-305, 1992. URL:
  10. M. S. Chen and K. G. Shin. Subcube allocation and task migration in hypercube multiprocessors. IEEE Transactions on Computers, 39(9):1146-1155, 1990. URL:
  11. Richard Cleve. Methodologies for Designing Block Ciphers and Cryptographic Protocols. PhD thesis, University of Toronto, April 1989. Google Scholar
  12. Martin Cohn. Affine m-ary Gray codes. Information and Control, 6(1):70-78, 1963. Google Scholar
  13. Don Coppersmith and Edna Grossman. Generators for certain alternating groups with applications to cryptography. SIAM J. Appl. Math., 29(4):624-627, 1975. Google Scholar
  14. C. Ding, D. Pei, and A. Salomaa. Chinese Remainder Theorem: Applications in Computing, Coding, Cryptography. World Scientific Publishing Co., Inc., River Edge, NJ, USA, 1996. Google Scholar
  15. David S. Dummit and Richard M. Foote. Abstract Algebra. John Wiley &Sons, 2004. Google Scholar
  16. Tomáš Dvořák, Petr Gregor, and Václav Koubek. Generalized Gray codes with prescribed ends. Theor. Comput. Sci., 668:70-94, 2017. URL:
  17. Gideon Ehrlich. Loopless algorithms for generating permutations, combinations, and other combinatorial configurations. J. ACM, 20(3):500-513, 1973. URL:
  18. Ivan Flores. Reflected number systems. IRE Transactions on Electronic Computers, EC-5(2):79-82, 1956. Google Scholar
  19. Gudmund Skovbjerg Frandsen, Peter Bro Miltersen, and Sven Skyum. Dynamic word problems. J. ACM, 44(2):257-271, 1997. URL:
  20. Michael L. Fredman. Observations on the complexity of generating quasi-Gray codes. SIAM J. Comput., 7(2):134-146, 1978. URL:
  21. Zachary Frenette. Towards the efficient generation of Gray codes in the bitprobe model. Master’s thesis, University of Waterloo, Waterloo, Ontario, Canada, 2016. Google Scholar
  22. E. Gad, M. Langberg, M. Schwartz, and J. Bruck. Constant-weight Gray codes for local rank modulation. IEEE Transactions on Information Theory, 57(11):7431-7442, 2011. URL:
  23. F. Gray. Pulse code communication, 1953. US Patent 2,632,058. URL:
  24. Petr Gregor and Torsten Mütze. Trimming and gluing Gray codes. In 34th Symposium on Theoretical Aspects of Computer Science, STACS 2017, March 8-11, 2017, Hannover, Germany, pages 40:1-40:14, 2017. URL:
  25. Felix Herter and Günter Rote. Loopless Gray code enumeration and the tower of bucharest. In 8th International Conference on Fun with Algorithms, FUN 2016, June 8-10, 2016, La Maddalena, Italy, pages 19:1-19:19, 2016. Google Scholar
  26. A. Jiang, R. Mateescu, M. Schwartz, and J. Bruck. Rank modulation for flash memories. IEEE Transactions on Information Theory, 55(6):2659-2673, 2009. URL:
  27. James T. Joichi, Dennis E. White, and S. G. Williamson. Combinatorial Gray codes. SIAM J. Comput., 9(1):130-141, 1980. URL:
  28. Donald E. Knuth. The Art of Computer Programming. Volume 4A: Combinatorial Algorithms, Part 1. Addison-Wesley Professional, 2011. Google Scholar
  29. Serge Lang. Linear Algebra. Undergraduate Texts in Mathematics. Springer New York, 1987. Google Scholar
  30. Rudolf Lidl and Harald Niederreiter. Finite Fields. Encyclopedia of Mathematics and its Applications. Cambridge University Press, 2 edition, 1996. URL:
  31. H. M. Lucal. Arithmetic operations for digital computers using a modified reflected binary code. IRE Transactions on Electronic Computers, EC-8(4):449-458, 1959. Google Scholar
  32. J. Ludman. Gray code generation for mpsk signals. IEEE Transactions on Communications, 29(10):1519-1522, 1981. URL:
  33. Torsten Mütze. Proof of the middle levels conjecture. Proceedings of the London Mathematical Society, 112(4):677-713, 2016. Google Scholar
  34. Torsten Mütze and Jerri Nummenpalo. Efficient computation of middle levels Gray codes. In Algorithms - ESA 2015 - 23rd Annual European Symposium, Patras, Greece, September 14-16, 2015, Proceedings, pages 915-927, 2015. Google Scholar
  35. Torsten Mütze and Jerri Nummenpalo. A constant-time algorithm for middle levels Gray codes. In Proceedings of the Twenty-Eighth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2017, Barcelona, Spain, Hotel Porta Fira, January 16-19, pages 2238-2253, 2017. Google Scholar
  36. Patrick K. Nicholson, Venkatesh Raman, and S. Srinivasa Rao. A survey of data structures in the bitprobe model. In Space-Efficient Data Structures, Streams, and Algorithms - Papers in Honor of J. Ian Munro on the Occasion of His 66th Birthday, pages 303-318, 2013. URL:
  37. Albert Nijenhuis and Herbert S. Wilf. Combinatorial Algorithms. Academic Press, 1978. Google Scholar
  38. M. Ziaur Rahman and J. Ian Munro. Integer representation and counting in the bit probe model. Algorithmica, 56(1):105-127, 2010. URL:
  39. Mikhail Raskin. A linear lower bound for incrementing a space-optimal integer representation in the bit-probe model. In 44th International Colloquium on Automata, Languages, and Programming, ICALP 2017, July 10-14, 2017, Warsaw, Poland, pages 88:1-88:12, 2017. Google Scholar
  40. Dana Richards. Data compression and Gray-code sorting. Information Processing Letters, 22(4):201-205, 1986. URL:
  41. J. P. Robinson and M. Cohn. Counting sequences. IEEE Transactions on Computers, C-30(1):17-23, 1981. URL:
  42. Carla Savage. A survey of combinatorial Gray codes. SIAM review, 39(4):605-629, 1997. Google Scholar
  43. Andrew Chi-Chih Yao. Should tables be sorted? J. ACM, 28(3):615-628, 1981. URL:
  44. Y. Yehezkeally and M. Schwartz. Snake-in-the-box codes for rank modulation. IEEE Transactions on Information Theory, 58(8):5471-5483, 2012. URL: