Implemented second tree matching algorithm