build a tree from a list