Longest path of a matrix

468 Views Asked by At

Given a matrix

$$ A = \begin{pmatrix} 1&2&3&4\\2&2&3&4\\3&2&3&4\\4&5&6&7 \end{pmatrix} $$

We know that the length of the longest path that is increasing is $7$, i.e. $1,2,3,4,5,6,7$ assuming we can only move up, down, left, right with no wrapping.

I wanted to attempt to program how to find the length of the longest path and the elements that are in the longest path. From what I read online it seems most people used a depth search algorithm.

I was thinking if it was possible to find the length of the largest path using linear algebra or if there is a simpler way then using depth first search and dynamic programming.

This problem was found on: here