Recounting the Rationals: Twice!

  • Roland Backhouse
  • João F. Ferreira
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5133)


We derive an algorithm that enables the rationals to be efficiently enumerated in two different ways. One way is known and is credited to Moshe Newman; it corresponds to a deforestation of the so-called Calkin-Wilf tree of rationals. The second is new and corresponds to a deforestation of the Stern-Brocot tree of rationals. We show that both enumerations stem from the same simple algorithm. In this way, we construct a Stern-Brocot enumeration algorithm with the same time and space complexity as Newman’s algorithm.


Calkin-Wilf tree Stern-Brocot tree algorithm derivation enumeration algorithm rational numbers 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Aigner, M., Ziegler, G.: Proofs From The Book, 3rd edn. Springer, Heidelberg (2004)Google Scholar
  2. 2.
    Calkin, N., Wilf, H.S.: Recounting the rationals. The American Mathematical Monthly 107(4), 360–363 (2000)zbMATHCrossRefMathSciNetGoogle Scholar
  3. 3.
    Dijkstra, E.W.: Guarded commands, nondeterminacy and formal derivation of programs. Communications of the ACM 18(8), 453–457 (1975)zbMATHCrossRefMathSciNetGoogle Scholar
  4. 4.
    Gibbons, J., Lester, D., Bird, R.: Enumerating the rationals. Journal of Functional Programming 16(3), 281–291 (2006)zbMATHCrossRefGoogle Scholar
  5. 5.
    Graham, R.L., Knuth, D.E., Patashnik, O.: Concrete Mathematics: a Foundation for Computer Science, 2nd edn. Addison-Wesley Publishing Company, Reading (1994)zbMATHGoogle Scholar
  6. 6.
    Knuth, D.E., Rupert, C.P., Smith, A., Stong, R.: Recounting the rationals, continued. American Mathematical Monthly 110(7), 642–643 (2003)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2008

Authors and Affiliations

  • Roland Backhouse
    • 1
  • João F. Ferreira
    • 1
  1. 1.School of Computer ScienceUniversity of NottinghamNottinghamEngland

Personalised recommendations