Added algorithm for creating tree