A language over an alphabet B = A ∪ A of opening (A) and closing (A ) brackets, is balanced if it is a subset of the Dyck language D B over B, and it is well-formed if all words are prefixes of words in D B . We show that well-formedness of a context-free language is decidable in polynomial time, and that the longest common reduced suffix can be computed in polynomial time. We also show that equivalence of linear tree transducers with well-formed output in B * is decidable in polynomial time. These two results enable us to decide in polynomial time for the class 2-TW of non-linear tree transducers with output alphabet B * whether or not the output language is balanced.
ACM Subject ClassificationTheory of computation → Transducers; Theory of computation → Grammars and context-free languages; Mathematics of computing → Combinatorics on words Keywords and phrases balancedness of tree-to-word transducer, equivalence over the free group, longest common suffix/prefix of a CFG