sir I do not understand the backtracking concept in this statement
soln [i][j]=0;
sir does the zero be assign to all the path or just the last location , please explain me because I did not get it because Mr. prateek was explaining in Indian language.
Recursion rat in a maze
Hello @mzk1994 this part is used in backtracking when we dint find the way further.
if there is ‘x’ further and the block is blocked then we have no way to go further from there then it means upto which block we have arrived we came wrong and that path is not the correct choice so we have to mark it as the path we cannot cinsider to be the countable path as it is not leading us to the end.
for this we are marking the path which cant lead us to the solution as 0.
if you have any other doubt you can ask here:
Happy Learning!!
sir here the code to print just a one path even if there more than a solution
bool right_success=rat_in_maze(maxe,soln,i,j+1,m,n);
if(right_success)
return true;
bool down_success=rat_in_maze(maze,soln,i+1,j,m,n);
if(down_success)
return true;
soln[i][j]=0;
return false;
+++++++++++++++++++++++++++++++
and here the code to print all the paths if there more than one
bool right_success=rat_in_maze(maze,soln,i,j+1,m,n);
bool down_success=rat_in_maze(maze,soln,i+1,j,m,n);
soln[i][j]=0;
if(right_success||down_success)
return true;
return false;
+++++++++++
so what is the difference because I see them same??
with all respect
Hello @mzk1994 this is the code:
i have commented in this where you have to print false and commented that line(13).
thanks so much sir,
sir if I want to print just a one path not all paths, how can I code it?
with all respect sir
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.