Using tree to generate the index