Tree construction and matrix formation.