The problem is that you cannot represent a matrix as a tree, due to the fact that there are more than one tree for a matrix. First you have to decide, how you will turn the matrix into a tree.