Similar Items: Algebraic and logical descriptions of generalized trees