I am currently trying to implement an algorithm that shares many similarities with the matrix-to-tree algorithm (I found these 2 threads pretty relevant....https://coderevie