The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+20 votes
2.2k views

Suppose that a robot is placed on the Cartesian plane. At each step it is allowed to move either one unit up or one unit right, i.e., if it is at $(i,j)$ then it can move to either $(i + 1, j)$ or $(i,j + 1)$.

How many distinct paths are there for the robot to reach the point $(10,10)$ starting from the initial position $(0,0)$?

  1. $^{20}\mathrm{C}_{10}$
  2. $2^{20}$
  3. $2^{10}$
  4. None of the above.
asked in Combinatory by Veteran (59.4k points)
edited ago by | 2.2k views
0
I am not able to solve question 85 even by referring the solution many times. Kindly, explain in detail. U are asking to subtract some paths and u are multiplying. Plz help me.

5 Answers

+40 votes
Best answer


In ques given, $r = \text{Move Right}$ and $u = \text{Move Up}$
so using ${10}$ combination of $r$ and ${10}$ combinations of $u$ moves we get a solution.

Convert the graphical moves to text and one such solution we get,

$= \{u, u, u, u, u, u, u, u, u, u, r, r, r, r, r, r, r, r, r, r\}$

now all possible arrangements of them is given by $= \frac{20!}{10! \times 10!} = {20 \choose 10}.$

Hence, option A is true.

 

answered by Boss (30.6k points)
edited by
+1

@amarVashishth

Can you give intuitive explanation for why Option C is incorrect ?

I calculated it & Realized Option C gives very less movement. I've understood how option D is correct, though I just want to know why option C is incorrect !

I've tried this on few small examples & I realized that by breaking one path, we are reducing total no of paths to destination by big factor, I think it is because there are lot of paths going through every move. Though if you can explain it more intituively that'll be great !

0

how are you getting option C

provide your solution.

0
I'm not saying Option C. What I'm saying is, how we are exactly reducing no of choices, by breaking one of up-right link ! I think it might be because of there are lot of choices even after that link.. That may be it, Just was confused little bit !
0
Suppose if we are allowed to take 2 steps up and 2 steps right. Then we need 5 steps of U and 5 steps of R. Then the answer should be $\frac{20!}{5! * 5!}$.

Please correct me if I am wrong.
0
"Suppose if we are allowed to take 2 steps up and 2 steps right. Then we need 5 steps of U and 5 steps of R. Then the answer should be 20!/(5! * 5!)"

Is this approach given by @rohan mishra correct???
0
good explanation
0
It will be 10!/5!*5!
+11 votes

This answer is not directly related to the QS But this may help to view this problem in a recursive way.

 

 

How many ways we can traverse this grid from $(0,0)$ to $(5,5)$.

Allowed moves from a cell are:

  1. Left to right by $1$ unit.
  2. Top to Bottom by $1$ unit.

This problem has $O(1)$ solution.

But we will see how we can use top-down recursion and memoization to calculate that value.

Currently, we have a problem size of $(6,6)$ i.e we have still to cover a $6^*6$ grid and we are at cell $(0,0)$.

 

 

Let's say we are at cell $(1,2)$ somehow.

 

Now, this situation we have a $4^*5$ grid to traverse. What are the steps we can take in this cell or in this state ?

Well two things can be done.

  1. Go right 
  2. Go down.

If we move right, then we will have to traverse a smaller grid of size $3^*5$

And if we move down, we will have to traverse a different smaller grid of size $4^*4$.

So, what we have seen is that from a bigger size problem of $4^*5$ grid we can arrive at smaller grid size problem by applying two different steps.

And if we sum up the two smaller subproblem solution we can get the result of bigger problem solution. (which was of size $4^*5$ ).

 

Therefore  $\text{solution}(m,n) = \text{solution}(m-1,n) + \text{solution}(m,n-1)$, this is the recursion and the Top Down approach will seek for solution of $(m,n)$ without knowing the solution of $(m-1,n)$ and $(m.n-1)$. Using recursion we will recurse towards smaller and smaller sub problem untill we hit in some base case.

And the base here is:

When we arrive at cell $(5,5)$. In this state, we have arrived at the destination and there nothing to do now, and how many ways to go from $(5,5)$ to $(5,5)$. It is equal to $1$ ( means don't move in this particular case).

Therefore  $ \text{solution}(1,1)$ $= 1$.

To speed up the solution and not repeating same sub problem, again and again, we will use memoization table.

Here is the code:

#define MAX_X 6
#define MAX_Y 8
int dp[MAX_X+1][MAX_Y+1];
int solve(int m,int n) {
  if(dp[m][n] != -1) return dp[m][n];
  int res = 0; 
  if(m > 1) res += solve(m-1,n);
  if(n > 1) res += solve(m,n-1);
  return dp[m][n] = res;
}
int main() {
  for(int i=0;i<(MAX_X+1);i++)
    for(int j=0;j<(MAX_Y+1);j++)
      dp[i][j] = -1;
  dp[1][1] = 1;
  int m = MAX_X,n = MAX_Y;
  printf("%d\n",solve(m,n));
  return 0;
}
answered by Veteran (56.4k points)
0

Superb. thanks :-)

0
ur explanations r damn too gd ....
+6 votes

84 At each move, robot can move either 1 unit right, or 1 unit up, and there will be 20 such moves required to reach (10,10) from (0,0). So we have to divide these 20 moves, numbered from 1 to 20, into 2 groups : right group and up group. Right group contains those moves in which we move right, and up group contains those moves in which we move up. Each group contains 10 elements each. So basically, we have to divide 20 things into 2 groups of 10 10 things each, which can be done in 20!/(10! ☓10!)=20C10 ways. So option (A) is correct.

answered by Loyal (5.9k points)
edited by
0

This is unordered partition hence ,should not it be 20!/((10!*10!)*2!) ?

0
No, it is not because the order of steps in each group have to be specific. For e.g. an up move from y=0 to y=1 has to appear before the up move from y=1 to y=2 which in turn has to come before further up moves. Similarly it can be inferred for x moves.

Secondly, logic here is to place moves from each group in their specific order into the available 20 choices. Ordering of the groups themselves need not be considered.
+3 votes
The answer for 84 is A. It is same as selecting 10 out of 20 elements.
answered by Boss (19.7k points)
0

20C10 or 210?

0
It is 20 C 10.
+3 votes

@amarvashishth has given nice explanation, but if you want to visualize how it does work then draw 2x2 grid and try to draw all path from (0,0) to (2,2) you can easily see how it does work and you also can verify answer for 10X10

here it give 4C2  =6  // { R,R,U,U} any path you follow you will encounter only two up and two right which is 4! /(2!*2!)

answered by Loyal (7.7k points)
edited by


Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

35,506 questions
42,827 answers
121,678 comments
42,181 users