In this paper, the density of a language is the function that returns, for each n, the number of words in the language of length n. We consider the question of deciding whether the density of a given regular language L is exponential or polynomial. This question can be answered in linear time when L is given via a DFA. When L is given via an NFA, we show that L has exponential density if and only if the NFA has a strongly connected component (SCC) in which two equal length walks from the same state have different labels. This characterization leads to a simple quadratic time algorithm. However, a more elegant approach produces a linear time algorithm whose proof of correctness involves the theorem of Fine and Wilf and the greatest common divisor (gcd) of the lengths of all cycles in the SCC. We have implemented both the quadratic and linear time algorithms using the FAdo library for automata, and present results of a few test cases.
[1]
Nivat G. Päun,et al.
Handbook of Formal Languages
,
2013,
Springer Berlin Heidelberg.
[2]
M. Lothaire.
Combinatorics on words: Bibliography
,
1997
.
[3]
Kenneth H. Rosen.
Handbook of Discrete and Combinatorial Mathematics
,
1999
.
[4]
P. Gács,et al.
Algorithms
,
1992
.
[5]
Jeffrey Shallit,et al.
Characterizing Regular Languages with Polynomial Densities
,
1992,
MFCS.
[6]
D. R. Shier,et al.
Graph-Theoretic Analysis of Finite Markov Chains
,
2003
.
[7]
Esther M. Arkin,et al.
Modularity of cycles and paths in graphs
,
1991,
JACM.
[8]
Stavros Konstantinidis,et al.
DNA Coding Using the Subword Closure Operation
,
2007,
DNA.
[9]
Arseny M. Shur.
Factorial Languages of Low Combinatorial Complexity
,
2006,
Developments in Language Theory.