 <p>You should be able to use Dijstra's algorithm, where the nodes are "between" the cells of the matrix and the connections are implied by the weights of the cells. </p> <p>For a detailed answer, please refer to this question: <a href="http://stackoverflow.com/questions/32798373/javascript-pathfinding-in-a-5000050000-grid-2d-array/32811146">Javascript: Pathfinding in a (50000*50000 grid) 2d array?</a></p>