It is well-known that every first-order property on words is expressibleusing at most three variables. The subclass of properties expressible withonly two variables is also quite interesting and well-studied. We proveprecise structure theorems that characterize the exact expressive power offirst-order logic with two variables on words. Our results apply toFO^2[<] and FO^2[<,Suc], the latter of which includes the binarysuccessor relation in addition to the linear ordering on string positions.

For both languages, our structure theorems show exactly what isexpressible using a given quantifier depth, n, and using m blocksof alternating quantifiers, for any m <= n. Using thesecharacterizations, we prove, among other results, that there is astrict hierarchy of alternating quantifiers for both languages. Thequestion whether there was such a hierarchy had been completely opensince it was asked in [Etessami, Vardi, Wilke 1997].