creating tree representation from table representation