added tree basic algo logic