construct tree from array