Question
Need help with this for practice! Please answer swiftly or I will not upvote.

A computer programmer lives in his home located at the upper left corner of the street grid pictured here and works in a building located at the lower right corner. The pictured grid's lines represent streets. On his way to work, the programmer drives along any street and can tyen at any intersection but can only go down or right and cannot go back. How many different paths are there for the programmer to drive from home to work? Please make and describe an algorithm, define every variable, write the recurrent formulas and boundary conditions to solve this issue, and please show all necessary calculations to find the total number of paths. Do not just put it all into words or else I will downvote.

home work
0 0
Add a comment Improve this question Transcribed image text
Answer #1

To count all the possible paths from top left to bottom right of a m x n matrix with the constraints that from each cell we can either move only to right or down and cannot go back.

N and M, denoting the number of rows and number of column respectively. count of all the possible paths from top left to bottom right of a m x n matrix.

Input : m = 2, n = 2;

Output : 2

There are two paths

(0, 0) --> (0, 1) --> (1, 1)

(0, 0) --> (1, 0) --> (1, 1)

Once approach is to generate all paths and then, determine which paths are valid.

The keys involved are:

Java program to Print all possible paths from

top left to bottom right of a mXn matrix

Java program to Print all possible Routes from

top left to bottom right of a mXn matrix

starting of mXn matrix

   i, j: Current position (For the first call use 0,0)

   m, n: Dimentions of given the matrix

Here m = 6 and n = 4, we start from (0, 0) and go to the end (5, 3) we can consider any one path lets say we choose

(0, 0) -> (0, 1) -> (0, 2) -> (1, 2) -> (2, 2) -> (3, 2) -> (4, 2)

Therefore, we moved 3 steps to the right and 5 steps downwards. Even if we take any other path same number of right and down steps will be required.

======================================================

public class FindPath

{     private static void showRoute(int mat[][], int m, int n, int i, int j, int Route[], int idx)     {

        Route[idx] = mat[i][j];

   if (i == m - 1)         {

            for (int k = j + 1; k < n; k++)           {

                Route[idx + k - j] = mat[i][k];

            }

            for (int l = 0; l < idx + n - j; l++)             {

                System.out.print(Route[l] + " ");

            }

            System.out.println();

            return;

        // Reached the right corner of the matrix we are left with only the downward movement.

        if (j == n - 1)         {

            for (int k = i + 1; k < m; k++) {

                Route[idx + k - i] = mat[k][j];

            }

            for (int l = 0; l < idx + m - i; l++)   {

                System.out.print(Route[l] + " ");

            }

            System.out.println();

            return;

        }

        // Print all the Routes that are possible after moving down

        showRoute(mat, m, n, i + 1, j, Route, idx + 1);

         // Print all the Routes that are possible after moving right

        showRoute(mat, m, n, i, j + 1, Route, idx + 1);

    }

    // Test code

    public static void main(String[] args) {

        int m = 4; //number of rows

        int n = 6; //number of cols

        int mat[][] = { { 1, 2, 3, 4,5,6 }, { 7, 8, 9 ,10,11,12},                                                                                     {13,14,15,16,17,18},{19,20,21,22,23,24}}; //m * n matrix

        int totalLengthOfRoute = m + n - 1;

        showRoute(mat, m, n, 0, 0, new int[totalLengthOfRoute], 0);

    }

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

1 7 13 19 20 21 22 23 24

1 7 13 14 20 21 22 23 24

1 7 13 14 15 21 22 23 24

1 7 13 14 15 16 22 23 24

1 7 13 14 15 16 17 23 24

1 7 13 14 15 16 17 18 24

1 7 8 14 20 21 22 23 24

1 7 8 14 15 21 22 23 24

1 7 8 14 15 16 22 23 24

1 7 8 14 15 16 17 23 24

1 7 8 14 15 16 17 18 24

1 7 8 9 15 21 22 23 24

1 7 8 9 15 16 22 23 24

1 7 8 9 15 16 17 23 24

1 7 8 9 15 16 17 18 24

1 7 8 9 10 16 22 23 24

1 7 8 9 10 16 17 23 24

1 7 8 9 10 16 17 18 24

1 7 8 9 10 11 17 23 24

1 7 8 9 10 11 17 18 24

1 7 8 9 10 11 12 18 24

1 2 8 14 20 21 22 23 24

1 2 8 14 15 21 22 23 24

1 2 8 14 15 16 22 23 24

1 2 8 14 15 16 17 23 24

1 2 8 14 15 16 17 18 24

1 2 8 9 15 21 22 23 24

1 2 8 9 15 16 22 23 24

1 2 8 9 15 16 17 23 24

1 2 8 9 15 16 17 18 24

1 2 8 9 10 16 22 23 24

1 2 8 9 10 16 17 23 24

1 2 8 9 10 16 17 18 24

1 2 8 9 10 11 17 23 24

1 2 8 9 10 11 17 18 24

1 2 8 9 10 11 12 18 24

1 2 3 9 15 21 22 23 24

1 2 3 9 15 16 22 23 24

1 2 3 9 15 16 17 23 24

1 2 3 9 15 16 17 18 24

1 2 3 9 10 16 22 23 24

1 2 3 9 10 16 17 23 24

1 2 3 9 10 16 17 18 24

1 2 3 9 10 11 17 23 24

1 2 3 9 10 11 17 18 24

1 2 3 9 10 11 12 18 24

1 2 3 4 10 16 22 23 24

1 2 3 4 10 16 17 23 24

1 2 3 4 10 16 17 18 24

1 2 3 4 10 11 17 23 24

1 2 3 4 10 11 17 18 24

1 2 3 4 10 11 12 18 24

1 2 3 4 5 11 17 23 24

1 2 3 4 5 11 17 18 24

1 2 3 4 5 11 12 18 24

1 2 3 4 5 6 12 18 24

56

Add a comment
Know the answer?
Add Answer to:
Need help with this for practice! Please answer swiftly or I will not upvote. A computer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A computer programmer lives in his home located at the upper left corner of the following...

    A computer programmer lives in his home located at the upper left corner of the following street grid and works in a building located at the right lower corner. In the grid, lines represent streets. There are five horizontal streets and seven vertical streets. On his way to work, he can drive along any street and turn at any intersection, but can only go down or right, and cannot go back. How many different paths are there for him to...

  • Please help with 1-10. I will upvote answer when fully complete. I need the correct answer...

    Please help with 1-10. I will upvote answer when fully complete. I need the correct answer to each because it will be graded immediately therefore I will make sure to upvote! Question 11 pts Suppose we use 4-bit two’s compliment integer representation. What is 0101 + 0001 ? Group of answer choices 0000 0101 0111 0110 Question 21 pts Suppose we use 4-bit two’s compliment integer representation. What is 1110 + 0111 ? Group of answer choices 0000 0101 0110...

  • #1. I need help with the Calculus problem below. For an upvote, please be sure to...

    #1. I need help with the Calculus problem below. For an upvote, please be sure to show all work for the solution associated with the problem below and circle your final answer. Sketch the curve represented by the parametric equations (indicate the orientation of the curve). x=t-2, y = +2 - 3 -8-7-6-5-4-3-2-1 1 2 3 4 5 6 7 8 -8-7-6-5-4-3-2-1 1 2 3 4 5 6 7 8 -8-7-6-5-4-3-2-1 1/2 3 4 5 6 7 8 -8-7-6-5-4-3-2-1 1...

  • Please help me with a solution using Python Taxi zum zum def taxi zum_zum(moves) : A...

    Please help me with a solution using Python Taxi zum zum def taxi zum_zum(moves) : A Manhattan taxicab starts at the origin point (e, e) of the two-dimensional integer grid, initially heading north. It then executes the given sequence of moves, a string made up of characters L for turning 90 degrees left (while standing in place), 'R' for turning 90 degrees right (ditto), and 'M for moving one step forward according to its current heading. This function should return...

  • please i need help in all three this is the second time i post this so...

    please i need help in all three this is the second time i post this so please help and do it right this time and show all the work Sketch the graph of the polar curve r=3 for OSOS 4x and indicate the orientation. Set up an integral to determine how long the curve is, is unrolled (10 pts.] 6. Graph the polar equations r-Sco) and = 3 col) for #/2515./2. Label any key points needed to find the area...

  • please read the questions carefully. I need the right answer. 3. A CT Public Transportation Commission...

    please read the questions carefully. I need the right answer. 3. A CT Public Transportation Commission survey asked 380 commuters (170 women and 210 men) "What is your primary mode of transportation to work?" The following table summarizes the results of the survey: Total Male 31 Female 37 68 Public Transportation Drives alone 162 102 264 Other means 17 31 48 Total 210 170 380 a. [2 pts) What is the probability that a randomly selected responder Drives alone? b....

  • I need help for Q11 Please if you can, answer this question too. I need B...

    I need help for Q11 Please if you can, answer this question too. I need B Q11. A complete graph is a graph where all vertices are connected to all other vertices. A Hamiltonian path is a simple path that contains all vertices in the graph. Show that any complete graph with 3 or more vertices has a Hamiltonian path. How many Hamiltonian paths does a complete graph with n vertices has? Justify your answer Q1. Draw thee 13-entry hash...

  • Please help me answer all the questions. Please show work so I can understand the process....

    Please help me answer all the questions. Please show work so I can understand the process. Thanks! (: Problem #1 (8 points) 41 Given a table of activities associated with a project, their durations and preceding activities: activityDuration Precedes ol ne : A (start) 1 wks B,C D.E F.G 1 wk 3 wks 2 wks 1 wk 1 wk 2 wks 2 wks 2 wks (end) 2 points Draw an Activity on Nodes (AoN) diagram of the project, including activity...

  • Computer experts, please help with the codes. I would very appreciate your help with the codes...

    Computer experts, please help with the codes. I would very appreciate your help with the codes and clear comments for those parts. Thank you very much! 1) Write an Arduino program that turns on a motor for 1000 encoder counts. You will watch the wheel rotate and expect it to rotate 3 full turns. When you have the wheel rotating 3 full turns for 1000 encoder counts, you will know that you are correctly measuring the encoder data. 2) Write...

  • BIG UPVOTE FOR RIGHT ANSWER Viscous fluid flow 2nd edition Frank White I need answer of...

    BIG UPVOTE FOR RIGHT ANSWER Viscous fluid flow 2nd edition Frank White I need answer of 2.17 I have attached 2.14 question and solution for reference. 2.17 As an extension of Prob. 2-14, consider the heat-transfer aspect by assuming a uniform entrance profile T = To and an exit profile approximated by T(r) = T0(1.5 + 0.5r2/ri). For flow with constant (p, F, cp, k) and negligible kinetic- and potential-energy changes, use the integral relations to compute the total heat...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT