An algorithm to compare any number of trees