filmov
tv
Find all possible paths between two points in a matrix using dynamic programming

Показать описание
Finding all possible paths in a matrix seems a bit tricky when you here it for the first time.
The first thing any naive programmer goes after is solving it using brute force technique, just count all possible paths. However, even though it will work for a small matrix but
it will fail when the matrix is large.
Dynamic programming technique always comes as a saviour while solving such problems and while solving to count all possible paths between two vertices of a matrix dynamic programming
will again come to our rescue.
The problem consists of a matrix of m X n dimension
In our example, let's say m=3 and n=4 which means the matrix has 3 rows and 4 columns.
All you have to do is find all possible paths between 2 points in the matrix from the top-left cell to the bottom-right cell of the matrix.
There is only small constraint which is, you can either move down or right. Keep in mind that you can't move up, or left. I believe that this constraint makes this matrix problem
much simpler in nature.
The key to find all possible paths to a given subproblem is to remember that the no of ways to that cell will be the same as the number of ways it takes to reach the cell at the top
as well as the cell at the left.
If you have watched Joey's previous videos of dynamic programming tutorial series then the solution to this problem will occur to you with little or no effort, but watching this video
together will be fun and I don't want you to be deprived of it so let's watch this video and solve together one of the simplest, most fun giving dynamic programming problems.
Introduction to dynamic programming
Longest Increasing subsequence using dynamic programming
01 Knapsack problem
The first thing any naive programmer goes after is solving it using brute force technique, just count all possible paths. However, even though it will work for a small matrix but
it will fail when the matrix is large.
Dynamic programming technique always comes as a saviour while solving such problems and while solving to count all possible paths between two vertices of a matrix dynamic programming
will again come to our rescue.
The problem consists of a matrix of m X n dimension
In our example, let's say m=3 and n=4 which means the matrix has 3 rows and 4 columns.
All you have to do is find all possible paths between 2 points in the matrix from the top-left cell to the bottom-right cell of the matrix.
There is only small constraint which is, you can either move down or right. Keep in mind that you can't move up, or left. I believe that this constraint makes this matrix problem
much simpler in nature.
The key to find all possible paths to a given subproblem is to remember that the no of ways to that cell will be the same as the number of ways it takes to reach the cell at the top
as well as the cell at the left.
If you have watched Joey's previous videos of dynamic programming tutorial series then the solution to this problem will occur to you with little or no effort, but watching this video
together will be fun and I don't want you to be deprived of it so let's watch this video and solve together one of the simplest, most fun giving dynamic programming problems.
Introduction to dynamic programming
Longest Increasing subsequence using dynamic programming
01 Knapsack problem
Комментарии