Ep20 - Rat in a Maze | Recursion | DSA series by Fraz | Notes available in description

  Рет қаралды 10,695

LearnYard

LearnYard

Күн бұрын

Пікірлер: 62
@ManikMahajan-b7x
@ManikMahajan-b7x 10 ай бұрын
🎯 Key Takeaways for quick navigation: 00:00 *🧩 Recursion Basics and Problem Introduction* - Recursion and backtracking explained as interconnected concepts. - Introduction to the maze problem where a rat needs to navigate through a grid to reach a destination. - Description of the maze grid structure and the objective of reaching a specific destination cell. 03:52 *🛤️ Understanding Recursive Approach to Maze Problem* - Explains how the maze problem is inherently recursive. - Describes the recursive nature of exploring all possible paths from a given position to the destination. - Emphasizes the need for systematically exploring all possible directions in the maze. 08:20 *🧭 Implementing Recursive Solution and Backtracking* - Details the recursive function for exploring paths in the maze. - Discusses the importance of backtracking to avoid revisiting already explored cells. - Demonstrates how to mark visited cells and backtrack to explore alternate paths. 10:25 *📊 Space and Time Complexity Analysis* - Analyzes the space complexity related to recursion, emphasizing the height of the recursion tree. - Explores the time complexity through the geometric progression of recursive calls. - Provides a breakdown of the number of nodes in the recursion tree to deduce the time complexity formula. 15:36 *💻 Coding the Recursive Solution* - Walks through the coding process of implementing the recursive solution in C++. - Demonstrates how to handle base cases, explore directions, mark visited cells, and backtrack. - Provides a step-by-step explanation of the code implementation.
@gigachad2419
@gigachad2419 2 жыл бұрын
This Guy is Really Important to our Coding Community Linked List Series was 💯💯 Ans now Recursion Series is going to be the Best one too!!
@arghya_0802
@arghya_0802 2 жыл бұрын
Whenever we want to generate all possible paths or answers, we need to think in terms of Recursion and Backtracking. Backtracking is simply undoing the change which we have already done. Summary: 1. We(mouse) are standing at (0,0) and we need to generate all possible paths so that the mouse reachers the last cell of the maze (n-1,n-1) 2. We are allowed to move in 4 directions only- Up, Down, Left and Right. We need to return a vector ans containing all possible paths through which the mouse can reach the end of maze. 3. Base conditions are pretty simple. Firstly, we cannot go beyond the boundaries of the matrix, secondly we cannot go to a cell which contains a blockage that is, matrix[i][j] denotes a blockage or wall and we cannot go through it. Also we need to mark every cell as visited with any other value(Fraz sir has marked with 0 for better understanding) such that we don't come back to the same cell again and again. Lastly, when we reach the target cell (n-1,n-1) we need to put our path string in ans[] vector and return as we have completed our objective. a) if(i =n) return; b) if(matrix[i][j] == 0) return; c) if(i==n-1 && j==n-1) { ans.push_back(path); return; } 4. Now, we have four options. But according to the problem we need to print the paths in sorted manner so we will move like- Down, Left, Right, Up. And before that we will mark the cell as visited by matrix [i][j] = 0 and Back-track at the end. // Mark as visited matrix[i][j] = 0; // Move Down help(i+1,j,path+'D'); // Move Left help(i,j-1,path +'L'); //Move Right help(i,j+1,path + 'R'); // Move Up help(i-1,j,path+'U); // Undo the change matrix[i][j] = 1; 5. Recursion will generate all the possible paths to reach end. We don't have to do anything else. Time Complexity: O(4^n*n) [ Because in worst case we will have a maze all filled with 1 and we will traverse all the cells to reach the end. And we have n*n cells in the maze and for each cell we have 4 option that's why Time Complexity is O(4^n*n) ] Space Complexity: O(n*n) [ This is equal to the height of the Recursive Tree and since we need to reach the end (n-1,n-1) from (0,0) that's why we need to traverse the entire matrix. ]
@saurabhN1393
@saurabhN1393 2 жыл бұрын
Thanks I think 3.b)if(matrix[i][j] == 0) return; code is missed by Fraz in the video.
@arghya_0802
@arghya_0802 2 жыл бұрын
@@saurabhN1393 Welcome🤗
@saurabhN1393
@saurabhN1393 2 жыл бұрын
@@arghya_0802 I like your notes.Do you maintain notes for Babar DSA or any other series as well? Do you know when Fraz will start uploading DP videos? He is a great teacher.
@arghya_0802
@arghya_0802 2 жыл бұрын
@@saurabhN1393 No I only commented on Fraz sir's video. And I don't know when the series will get resumed😔
@DPCODE72
@DPCODE72 2 жыл бұрын
Yesterday, I was visiting ur channel all the the time for next lecture Over recursion. I couldn't get next lecture then go for sleeping. Now just now I would see that one video would be uploaded on it. There's no any word to tell about ur consistency & dedication. Uh are a such down to earth man for students. Who don't have selfishness natural at all........God bless uh bhaiya!!......One thing it was most awaited video so far " RAT IN THE MAZE".......I will like to meet to uh once bhaiya!! Bhaiya.....I would complete all the questions of Contest 1 yesterday well.....Now am waiting for Contest 2!!
@aryanraj728
@aryanraj728 2 жыл бұрын
Thanks for amazingly simple solution 🙋🏻‍♂️🤗
@vishalgowrav
@vishalgowrav 2 жыл бұрын
Episode 20 completed!! Rat in a maze Here, we will be given a rat and maze(matrix) and we need to find to find in how many paths the rat can reach the (n-1) (n-1) destination Here, the position in which rat can travel will be denoted by 1 and the positions which are prohibited are denoted by 0 1) Here, for each position we have four directions D, L, R, U so we can go in all these directions to reach the destination 2) So we will call recursive functions for all the four directions and ask recursion to do the next step 3) The base conditions are:- i and j cant go negative or out of the grid and if can't go to positions which are prohibited 4) And also we can travel through the position which we already travelled so while we are travelling we mark that position as 0 Time complexity:- O(4^n*n) Space complexity:- O(n*n) Once again amazing Explanation bhaiya!! 😍
@chinmaypanchal2521
@chinmaypanchal2521 Жыл бұрын
Did the question by my own sir, thankyou so much for your recursion course. god bless you 😇
@amiagarwal1083
@amiagarwal1083 2 жыл бұрын
Thank you for the efforts you put in and your consistency is incredible 🔥💫
@AtomicAkshay
@AtomicAkshay 2 жыл бұрын
Notes: Similar problem to word search, gives us more confidence on how backtracking can be used to solve similar problems. Was able to do by making some changes in word search problem's code. T: O(4^(n * n)) S: O(n * n)
@gauravkumar3036
@gauravkumar3036 2 жыл бұрын
Your explanation is dope
@it_08amanagarwal35
@it_08amanagarwal35 2 жыл бұрын
Excellent lecture bro keep uploading we keep learning
@Shakib.Siddiqui
@Shakib.Siddiqui 2 жыл бұрын
Bhai aj me soch rha tha lecture nhi upload kiya...... Thank you bhai 😎
@LearnYardYT
@LearnYardYT 2 жыл бұрын
Aaega bro daily
@Lucifer-xt7un
@Lucifer-xt7un 2 жыл бұрын
Extremely good content bro
@AmitYadav-kr6vf
@AmitYadav-kr6vf 2 жыл бұрын
Great sir, Thank you❤🌹🙏
@CodeandColors22
@CodeandColors22 2 жыл бұрын
You are vrry hardworking bhiya 🥰❤
@PRIYANSHUKUMAR-un9zu
@PRIYANSHUKUMAR-un9zu 2 жыл бұрын
Great bhaiya, thanks u so much🔥🔥❤❤
@HarshitSharma-si4wl
@HarshitSharma-si4wl 2 жыл бұрын
Very good explanation
@HarshitSharma-si4wl
@HarshitSharma-si4wl 2 жыл бұрын
Thank you bhaiya
@Ajaysingh-dg8pi
@Ajaysingh-dg8pi Жыл бұрын
Bro can you let me know what are you using to draw out things, I mean which digital pen?
@it_08amanagarwal35
@it_08amanagarwal35 2 жыл бұрын
Bro when I solve this question before your video came it kind of look confusing as I am not able to understand what they are trying to say by not using same cell again and agai again but when u solve it on board then I solve it in one time code before seeing ur code❤❤❤❤❤❤❤❤❤❤❤❤❤
@Abhishek-fo3fc
@Abhishek-fo3fc 2 жыл бұрын
Done understood ✅❤
@sanketbhagat1222
@sanketbhagat1222 2 жыл бұрын
Thankyou so much bhaiya for your content.
@brijeshgaba5230
@brijeshgaba5230 2 жыл бұрын
bhaiya when basic of programming language with dsa will launched . we are waiting .
@darshankalathiya8667
@darshankalathiya8667 2 жыл бұрын
very nice pls keep uploading videos. !
@ranitbandyopadhyay
@ranitbandyopadhyay 2 жыл бұрын
great video. Good explanation
@ratnasanjay
@ratnasanjay 2 жыл бұрын
Thankyou bhaiya for this nice session
@kaifhasan8960
@kaifhasan8960 2 жыл бұрын
thank you bhaiya for have a such good content.
@emtiazahmed5333
@emtiazahmed5333 2 жыл бұрын
Hey bro,, i am hare,😁😁 for u... 😍 thank.u bhAiya🥰
@chiragkarnwal6740
@chiragkarnwal6740 2 жыл бұрын
Thanks for the video sir♥
@aimanshaikh7201
@aimanshaikh7201 2 жыл бұрын
Plz start beginners DSA course soon We are waiting
@sankalpgahlot6190
@sankalpgahlot6190 2 жыл бұрын
Bro You are using c++ but i'm Java programmer how would I understand the DSA syntax
@LearnYardYT
@LearnYardYT 2 жыл бұрын
Did you understand the concept?
@rabindradocument8934
@rabindradocument8934 2 жыл бұрын
How we will solve find the number of even numbers can be formed using the digits from 0 to 9 such that 3 and 5 are not adjacent.
@rabindradocument8934
@rabindradocument8934 2 жыл бұрын
Implement this using code.
@abhishekc3556
@abhishekc3556 2 жыл бұрын
Thank you 🔥🔥
@saurabhN1393
@saurabhN1393 2 жыл бұрын
Thanks I think if(matrix[i][j] == 0) return; code is missed by Fraz in the video.
@anixdrv
@anixdrv Жыл бұрын
In which language.. the solution of problem is coded?
@aimanshaikh7201
@aimanshaikh7201 2 жыл бұрын
When beginners DSA course will start
@BurhanAijaz
@BurhanAijaz 2 жыл бұрын
day 20 bohut zyada late ab kal dekhunga, abhi mood nahi hai 12 k baad padne ka
@DPCODE72
@DPCODE72 2 жыл бұрын
Yesterday, I was visiting ur channel all the the time for next lecture Over recursion. I couldn't get next lecture then go for sleeping. Now just now I would see that one video would be uploaded on it. There's no any word to tell about ur consistency & dedication. Uh are a such down to earth man for students. Who don't have selfishness natural at all........God bless uh bhaiya!!......One thing it was most awaited video so far " RAT IN THE MAZE".......I will like to meet to uh once bhaiya!!
@bahanebaaz3232
@bahanebaaz3232 2 жыл бұрын
want this video because I was having doubts
@aliaslam614
@aliaslam614 2 жыл бұрын
👍💯
@vivekgupta6696
@vivekgupta6696 2 жыл бұрын
Maja Aggaya bhaiya
@anupkumargorai771
@anupkumargorai771 2 жыл бұрын
👍🏻
@mohdumar6990
@mohdumar6990 2 жыл бұрын
Consistency++
@pratyekmotivation7481
@pratyekmotivation7481 Жыл бұрын
#include void solve(vector&a,char ch,int x,int y,string &s,vector&ans,vector&d){ if(xa[0].size()-1||a[x][y]!=1||d[x][y]!=-1){ return; } if(x==a.size()-1&&y==a.size()-1){ s.push_back(ch); ans.push_back(s); s.pop_back();//backtracking is required to check different possible cases in a given question return; } if(x==0&&y==0){ } else{ s.push_back(ch); } d[x][y]=0; solve(a,'L',x,y-1,s,ans,d); solve(a,'R',x,y+1,s,ans,d); solve(a,'D',x+1,y,s,ans,d); solve(a,'U',x-1,y,s,ans,d); s.pop_back(); d[x][y]=-1; } vector < string > searchMaze(vector < vector < int >> & arr, int n) { // Write your code here. vectord; for(int i=0;i
@divyanshsagar
@divyanshsagar 2 жыл бұрын
Episode 20 done!
@HarshRaj-kp7gk
@HarshRaj-kp7gk 2 жыл бұрын
#🥰🥰
@zeeshanansari2232
@zeeshanansari2232 2 жыл бұрын
ThnQ ones again
@mohammedsaqib1250
@mohammedsaqib1250 2 жыл бұрын
codes kab aayenge
@rabindradocument8934
@rabindradocument8934 2 жыл бұрын
Fraz is better than didi and bhaiya who just rant I am for you.
@mirzaadnanbeg5987
@mirzaadnanbeg5987 2 жыл бұрын
Reach++
@nithins3895
@nithins3895 2 жыл бұрын
bro i was watching your previous videos and trying to solving those bro im didnt getting space and time complexity between two solution Combination ||| solution -1 ------------------------------------------- static void Solve(int ind,int k,int sum,int n,ArrayList ans,ArrayList ds){ if(ds.size()>=k){ if(sum==0){ ans.add(new ArrayList(ds)); } return; } if(ind==10)return; ds.add(ind); Solve(ind+1,k,sum-ind,n,ans,ds); ds.remove(ds.size()-1); Solve(ind+1,k,sum,n,ans,ds); } ---------------------------------------------------------------------------- SOlution 2 : static void Solve(int ind,int k,int sum,int n,ArrayList ans,ArrayList ds){ if(ds.size()>=k){ if(sum==0){ ans.add(new ArrayList(ds)); } return; } for(int i=ind;i
@nithins3895
@nithins3895 2 жыл бұрын
Bro please help me
@Lucifer-xt7un
@Lucifer-xt7un 2 жыл бұрын
Consistency ++
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Towers of Hanoi: A Complete Recursive Visualization
21:13
Reducible
Рет қаралды 513 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,3 МЛН
Every Sorting Algorithm Explained in 120 minutes (full series)
1:57:33
Kuvina Saydaki
Рет қаралды 82 М.
L19. Rat in A Maze | Backtracking
25:10
take U forward
Рет қаралды 233 М.
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 681 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН