implement tree search