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.
Similar content being viewed by others
References
Alonso, L., Schott, R.: Random Generation of Trees: Random Generators in Computer Science. Kluwer Academic, Norwell (1995)
Barcucci, E., Del Lungo, A., Pergola, E.: Random generation of trees and other combinatorial objects. Theor. Comp. Sci. 218, 219–232 (1999)
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)
Cormen, T.H., Leiserson, C.E., Rivest, R.L.: Introduction to Algorithms, 1st edn. MIT Press, Cambridge (1990)
Denise, A.: Génération aléatoire uniforme de mots de langages rationnels. Theor. Comp. Sci. 159(1), 43–63 (1996)
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)
Denise, A., Zimmermann, P.: Uniform random generation of decomposable structures using floating-point arithmetic. Theor. Comp. Sci. 218(2), 233–248 (1999)
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)
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)
Fusy, E.: Uniform random sampling of planar graphs in linear time. Random Struct. Algorithms 35(4), 464–522 (2009)
Goldwurm, M.: Random generation of words in an algebraic language in linear binary space. Inf. Process. Lett. 54(4), 229–233 (1995)
Hickey, T., Cohen, J.: Uniform random generation of strings in a context-free language. SIAM J. Comput. 12(4), 645–655 (1983)
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)
Knuth, D.: The Art of Computer Programming. Seminumerical Algorithms, vol. 2. Addison-Wesley, Reading (1969)
Mairson, H.G.: Generating words in a context free language uniformly at random. Inf. Process. Lett. 49(2), 95–99 (1994)
Matsumoto, M., Nishimura, T.: Mersenne twister: a 623-dimensionally equidistributed uniform pseudorandom number generator. ACM Trans. Model. Comput. Simul. 8(1), 3–30 (1998)
Nijenhuis, A., Wilf, H.S.: Combinatorial Algorithms. Academic Press, San Diego (1978)
Author information
Authors and Affiliations
Corresponding author
Rights 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
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00453-010-9446-5