- We’ll create a matrix to represent the grid, where each cell represents a node.
- Initialize the first row and first column with 1 (since there’s only one way to reach any cell in the first row or column).
- For each cell (except the first row and first column), the number of ways to reach it is the sum of the ways to reach the cell above it and the cell to its left.
- Finally, the value in the last cell (B) will give you the total number of paths from A to B.
- We can then backtrack to find all the paths.
find all pathbetween 2 node under constraint
2 views (last 30 days)
Show older comments
hey
i want to find all path between A to B ( start from left buttom)
i have tryed to use meshgrid and allpath command without succses
the constraint are the i can go right or up only
also, i need to write code that calculates the probability on each node to go up or right if given that all route is equal probability
i will appreciate hint how to write my code and which commands to use
here is the mesh
0 Comments
Answers (1)
Pratik
on 11 Jun 2024
Hi Shalom,
From what I can understand, we need to find all possible upward or rightward paths from the bottom-left corner to the top-right corner of a grid, and to calculate the probability of choosing to move right or up at any node, assuming each path is equally likely.
The problem can be approached using dynamic programming,
I hope this helps!
0 Comments
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!