treeAlgorithm