Skip to main content
Log in

A Linear Algorithm for the Random Sampling from Regular Languages

  • Published:
Algorithmica Aims and scope Submit manuscript

Abstract

We present the first linear algorithm for the random sampling from regular languages. More precisely, for generating a uniformly random word of length n in a given regular language, our algorithm has worst-case space bit-complexity O(n) and mean time bit-complexity O(n). The previously best algorithm, due to Denise and Zimmermann (Theor. Comp. Sci. 218(2):233–248, 1999), has worst-case space bit-complexity O(n 2) and mean time bit-complexity O(nlog (n)). The Denise et al. algorithm was obtained by performing a floating-point optimization on the general recursive method formalized by Nijenhuis and Wilf (and further developed by Flajolet, Zimmermann and Van Cutsem). Our algorithm combines the floating-point optimization with a new divide-and-conquer scheme.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Alonso, L., Schott, R.: Random Generation of Trees: Random Generators in Computer Science. Kluwer Academic, Norwell (1995)

    Google Scholar 

  2. Barcucci, E., Del Lungo, A., Pergola, E.: Random generation of trees and other combinatorial objects. Theor. Comp. Sci. 218, 219–232 (1999)

    Article  MATH  Google Scholar 

  3. Barcucci, E., Del Lungo, A., Pergola, E., Pinzani, R.: ECO: a general methodology for the enumeration of combinatorial objects. J. Differ. Equ. Appl. 5, 435–490 (1999)

    Article  MATH  Google Scholar 

  4. Cormen, T.H., Leiserson, C.E., Rivest, R.L.: Introduction to Algorithms, 1st edn. MIT Press, Cambridge (1990)

    MATH  Google Scholar 

  5. Denise, A.: Génération aléatoire uniforme de mots de langages rationnels. Theor. Comp. Sci. 159(1), 43–63 (1996)

    Article  MATH  MathSciNet  Google Scholar 

  6. Denise, A., Rocques, O., Termier, M.: Random generation of words of context-free languages according to the frequencies of letters. In: Colloquium on Mathematics and Computer Science, pp. 113–125 (2000)

  7. Denise, A., Zimmermann, P.: Uniform random generation of decomposable structures using floating-point arithmetic. Theor. Comp. Sci. 218(2), 233–248 (1999)

    Article  MATH  MathSciNet  Google Scholar 

  8. Duchon, P., Flajolet, P., Louchard, G., Schaeffer, G.: Boltzmann samplers for the random generation of combinatorial structures. Comb. Probab. Comput. 3(4–5), 577–625 (2004)

    Article  MathSciNet  Google Scholar 

  9. Flajolet, P., Zimmermann, P., Van Cutsem, B.: A calculus for the random generation of labelled combinatorial structures. Theor. Comp. Sci. 132(1), 1–35 (1994)

    Article  MATH  Google Scholar 

  10. Fusy, E.: Uniform random sampling of planar graphs in linear time. Random Struct. Algorithms 35(4), 464–522 (2009)

    Article  MATH  MathSciNet  Google Scholar 

  11. Goldwurm, M.: Random generation of words in an algebraic language in linear binary space. Inf. Process. Lett. 54(4), 229–233 (1995)

    Article  MATH  MathSciNet  Google Scholar 

  12. Hickey, T., Cohen, J.: Uniform random generation of strings in a context-free language. SIAM J. Comput. 12(4), 645–655 (1983)

    Article  MATH  MathSciNet  Google Scholar 

  13. Kannan, S., Sweedyk, Z., Mahaney, S.: Counting and random generation of strings in regular languages. In: Proceedings of the Sixth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 551–557 (1995)

  14. Knuth, D.: The Art of Computer Programming. Seminumerical Algorithms, vol. 2. Addison-Wesley, Reading (1969)

    MATH  Google Scholar 

  15. Mairson, H.G.: Generating words in a context free language uniformly at random. Inf. Process. Lett. 49(2), 95–99 (1994)

    Article  MATH  MathSciNet  Google Scholar 

  16. Matsumoto, M., Nishimura, T.: Mersenne twister: a 623-dimensionally equidistributed uniform pseudorandom number generator. ACM Trans. Model. Comput. Simul. 8(1), 3–30 (1998)

    Article  MATH  Google Scholar 

  17. Nijenhuis, A., Wilf, H.S.: Combinatorial Algorithms. Academic Press, San Diego (1978)

    MATH  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Omer Giménez.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Bernardi, O., Giménez, O. A Linear Algorithm for the Random Sampling from Regular Languages. Algorithmica 62, 130–145 (2012). https://doi.org/10.1007/s00453-010-9446-5

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s00453-010-9446-5

Keywords

Navigation