Table of Contents: Leave The Library Plz 0:00 - 0:17 The Problem Introduction 0:17 - 2:50 Our Fundamental Operations 2:50 - 3:50 Beginning The Depth-First Search 3:50 - 7:26 We Hit Dead End #1 7:26 - 9:50 We Get Back On Track 9:50 - 12:03 We Hit Dead End #2 12:03 - 13:27 We Get Back On Track Again 13:27 - 14:31 We Reach Our Target: The End 14:31 - 15:00 Returning Back Upwards With The Path 15:00 - 15:28 The Top Level Caller Gets The Path 15:28 - 15:59 Time Complexity 15:59 - 16:42 Space Complexity 16:42 - 17:09 Wrap Up 17:09 - 17:30 The code for this problem is in the description. Fully commented for teaching purposes.
@amirmohideen994 жыл бұрын
code is missing
@BackToBackSWE4 жыл бұрын
The repository is deprecated - we only maintain backtobackswe.com now
@punitpawar42314 жыл бұрын
@@BackToBackSWE Is it possible for you to share the link to this code ?
@Thadnill4 жыл бұрын
@@punitpawar4231 I wonder this as well
@UECDishaKhattri4 жыл бұрын
yes it would be wonderful if you just provide the code link
@frogspawn85 жыл бұрын
Bruh, your lectures are WAY clearer and more concise than some of the “best” professors I’ve encountered. Kudos to you!
@BackToBackSWE5 жыл бұрын
thx
@ers-br2 жыл бұрын
I thought he was a professor ... and he's just a student. Really good explanations.
@FrancoMunizAR4 жыл бұрын
You and Abdul Bari are the kings of explaining algorithms and problem solving. Thanks a LOT for everything you do!
@johnbanyan113 жыл бұрын
Damn true
@jst89224 ай бұрын
NeetCode, DEEPTI TALESRA, Jenny's Lectures CS IT, Tushar Roy - Coding Made Simple, Nikhil Lohia too.
@lmnefg1214 жыл бұрын
I really like that you explain things in such a simple way and teaches the most fundamental method. As a matter of fact, it is always most difficult to learn the most fundamental stuff.
@BackToBackSWE4 жыл бұрын
thanks.
@betatester034 жыл бұрын
Man, you are an excellent teacher. I stumbled onto one of your videos earlier and immediately started up another, right after. I'm about five videos in, now. I've got books upon books about algorithms, I've read articles, related papers, tutorials, pseudo-code implementations, and public code-bases on software repo's, but this is the first time I've gained a simple, clear intuition for some of these concepts. Thank you so much for taking the time to make these videos. I'll refer people to your content any chance I get.
@BackToBackSWE4 жыл бұрын
Sure - thank you.
@TJ-rf1xl5 жыл бұрын
Best explanation I've seen of DFS so far. I wish my professors explained things this way. I likely would have dropped out of my MSc if it wasn't for your channel!
@BackToBackSWE5 жыл бұрын
dang, nice!
@GraniLP3 жыл бұрын
Big thanks to you! Currently I am a bit angry that my university is not capable of explaining such stuff in a nice way, but you did it in less time and in a much clearer way!
@sindisiwemncube46652 жыл бұрын
This dude is a brilliant tutor. Never have i ever understood an algorithm this clearly, Juss did.
@abyssking40623 жыл бұрын
Till now, your video is still saving lives. I finally completed my damn maze assignment after your explanation. Wherever you are bro, THANK YOU!!!
@qiuyangshen35694 жыл бұрын
The call stack is a state! So brilliant words!
@BackToBackSWE4 жыл бұрын
ye
@deepusasidharan20123 жыл бұрын
Yes...it cud be completed or uncompleted(waiting for child stack to complete)
@ceek795 жыл бұрын
Honestly, you sitting in front of a computer would be a waste of talent! Take advantage of your skill to explain complex stuff the easy way and make a business out of it.
@BackToBackSWE5 жыл бұрын
👀👀💰💸💰
@jonathandaniel73215 жыл бұрын
@@BackToBackSWE start a university with only you as teacher
@BackToBackSWE5 жыл бұрын
@@jonathandaniel7321 I do not want to do that.
@Dunig24 жыл бұрын
This is so clear to me, I’m amazed at how easy you make this to understand
@BackToBackSWE4 жыл бұрын
nice
@sairamankilambi50074 жыл бұрын
I saw the BFS & DFS (15 min) video followed by the maze problem. Wow! It clears out when and where to chose BFS over DFS. Thanks a LOT!
@BackToBackSWE4 жыл бұрын
sure
@ravitanwar95375 жыл бұрын
hey man , i'm the one who asked for minimum window substring on leetcode . just wanna tell you that you doing a pretty good job and this channel HAS the potential. keep coming up with these videos and if possible with python language . cheers!
@BackToBackSWE5 жыл бұрын
hmmmm, yeah, good idea. I need to brush up on my Python though. My languages in order of strength: Java, Typescript (a superset of course), Javascript ...then some experience with C, C#, Ruby
@ravitanwar95375 жыл бұрын
@@BackToBackSWE n i think it'll also be a good idea if you specify the difficulty level before the video . for eg :- easy , medium , hard on leetcode ,
@BackToBackSWE5 жыл бұрын
@@ravitanwar9537 Every video has badges of the difficulty.
@darkhorse6214 жыл бұрын
Best Explanation for DFS I've come across so far. Thanks a lot !!! Keep up the good work guys.
@BackToBackSWE4 жыл бұрын
thx
@thatolebethe88962 жыл бұрын
Dude thanks for thee constant repition. Really helped cement how depth first search works
@BackToBackSWE2 жыл бұрын
Glad to hear that! explore our 5 day free mini course for some cool content - backtobackswe.com/
@psn9991005 жыл бұрын
WOW. best explanation so far. After this I am gonna do Maze I, II and III on Leetcode. I got asked this for Amazon OA and i screwed up cuz my fundamentals were not good. thanks
@BackToBackSWE5 жыл бұрын
nice and sure
@Hav0c10004 жыл бұрын
Hey man, after listening to your excellent explanation, I was able to go and code this up! Thanks! You are a really good teacher!
@BackToBackSWE4 жыл бұрын
sure
@darod60985 жыл бұрын
Just amazing. I'm really grateful for your work
@BackToBackSWE5 жыл бұрын
long way to go...very very very very long way
@xxbighotshotxx5 жыл бұрын
@@BackToBackSWE Don't forget to enjoy the journey :)
@PJ-hi1gz3 ай бұрын
bro you explain so clear, it's a wonderful gift to have and share with others
@shubhamk8404 жыл бұрын
you have an amazing skill of teaching, even 10 years old can understand your explanation.
@BackToBackSWE4 жыл бұрын
thanks
@erinkerciku2 жыл бұрын
I don't usually leave likes on videos but you deserve it my guy.
@kgopotsomasela46272 жыл бұрын
Your patience is admirable
@alikizander Жыл бұрын
Your delivery and presentation is just on POINT. I don't like it, I LOVE IT. You helped me tackle a PACMAN PROBLEM USING THE UNIFORM-COST SEARCH BY JUST WATCHING THIS VIDEO
@sanctusfides2 жыл бұрын
"Can I go up, yes I can!" is going to be looping in my head for a week after this video
@maharshidave44725 жыл бұрын
Hello, sir you have high degree of patience to expain each and every minute detail. And I wish you will soon reach your traget of 100K subscribers and keep it up.😀
@BackToBackSWE5 жыл бұрын
thx
@banelemakhanya2595 Жыл бұрын
@@BackToBackSWE hi, would love help on mazes
@ritwik1214 жыл бұрын
the visualizations are really fantastic. awesome work ben :)
@BackToBackSWE4 жыл бұрын
thx
@stephentanksleymusic72404 жыл бұрын
This was fantastic. Thank you so much for such a clear, effective explanation of recursive DFS algorithms for maze traversal!
@BackToBackSWE4 жыл бұрын
sure!
@ebiigweze33844 жыл бұрын
"AND NOW WE ARE THIS CELL" ........that is a drinking game right there...number of times that was said, man would be wasted in no time...cool tutorial bro .. keep it up
@BackToBackSWE4 жыл бұрын
hahahahahahaha
@vrdash4 жыл бұрын
The video goes in-Depth of the topic literally and thus my search for DFS is complete :p
@BackToBackSWE4 жыл бұрын
nice
@pavel96525 жыл бұрын
This is the library floor plan. The library will be closing in 15 minutes. Implement one of the fundamental graph searching algorithms (DFS/BFS) to find the exit from the building ;)
@BackToBackSWE5 жыл бұрын
yes
@siddhantrai75295 жыл бұрын
One of the best explanation of maze problem... Beautiful
@BackToBackSWE5 жыл бұрын
thanks
@jkim51185 жыл бұрын
What's the main pros and cons of doing this in BFS and DFS? I thought DFS would be better, but it seems like only BFS is accepted on Leetcode. What are your thoughts? Also, do you think we should also know how to do Dijkstra for these kinds of search questions but with weights?
@BackToBackSWE5 жыл бұрын
BFS always finds the shortest path. The reason DFS times out is because it will get really far from the answer and waste time. BFS will find the object faster...generally...think about it...BFS goes out level by level and doesn't go deep into anything. This is good and bad. Ponder on these things.
@zackgrey44724 жыл бұрын
Beautiful video, you just earned a subscriber. I really admire your content!!!
@BackToBackSWE4 жыл бұрын
thx
@goldfishbrainjohn24624 жыл бұрын
This helped me a lot!! I love the way you teach. Thanks. Subscribed immediately Edit: The code below is my version of DFS for a maze problem and the concept is based on this video. Appreciate it. function solve(lines) { let wAndH = lines.shift(); wAndH = wAndH.split(' '); let [w, h] = wAndH; w = Number(w); h = Number(h); let nestedArr = lines.map(item => { let a = []; a.push(item); return a; }) nestedArr = nestedArr.map(item => { return item[0].split(""); }) let blockStart = []; let blockEnd = []; for(let i = 0; i < w; i++){ blockStart.push('#'); blockEnd.push('#'); } nestedArr.splice(0, 0, blockStart) nestedArr.splice(h+1, 0, blockEnd); nestedArr.forEach(item => { item.unshift('#'); item.push('#'); }) let roadCoordinates = []; function findRoad(arr = [], h = 0, w = 0, road) { const checkUp = (arr, h, w) => { if(arr[h-1][w] === '.') { return true; } else { return false; } } const checkRight = (arr, h, w) => { if(arr[h][w+1] === '.') { return true; } else { return false; } } const checkDown = (arr, h, w) => { if(arr[h+1][w] === '.') { return true; } else { return false; } } const checkLeft = (arr, h, w) => { if(arr[h][w-1] === '.') { return true; } else { return false; } } if(arr[h] != 'undefined') { if(arr[h][w] === '.') { if(checkUp(arr, h, w)) { arr[h][w] = '1'; road.push([w,h]) findRoad(arr, h-1, w, road); } else if(checkRight(arr, h, w)) { arr[h][w] = '1' road.push([w,h]) findRoad(arr, h, w+1, road); } else if(checkDown(arr, h, w)) { arr[h][w] = '1' road.push([w,h]) findRoad(arr, h+1, w, road); } else if(checkLeft(arr, h, w)) { arr[h][w] = '1' road.push([w,h]) findRoad(arr, h, w-1, road); } else if(arr[h][w] === '.') { arr[h][w] ='1'; road.push([w,h]) } } else { console.log('Wrong') } } } findRoad(nestedArr, 1, 1, roadCoordinates) nestedArr.pop(); nestedArr.shift() nestedArr.forEach(item => { item.pop(); item.shift() }) roadCoordinates.pop(); console.log(roadCoordinates.length) }
@BackToBackSWE4 жыл бұрын
great, thanks, sure, and great
@adityamohan3934 жыл бұрын
Amazing explanation, but not able to find the code in the description.
@ryangallagher12852 жыл бұрын
The best explanation on the internet.
@BackToBackSWE2 жыл бұрын
That's nice of you
@erichlf5 жыл бұрын
Amazon asked me this in the phone interview and even though I knew it I promptly fucked it up.
@BackToBackSWE5 жыл бұрын
Eh, whateves
@wrestlingscience3 жыл бұрын
absolutely no one: backtobackswe: can i go up yes can i go up yes can i go up no
@HemanthaKumarYadav4 жыл бұрын
The way you explain is simply amazing sir!
@studyonline32364 жыл бұрын
client, at the end of a successful dfs, to node at the start: Yo got the result? start node : yes client: What did it cost? node: realisation at 9:50 and 13:31
@BackToBackSWE4 жыл бұрын
wut lol
@无名字-q7k3 жыл бұрын
Thanks! this is useful, im currently making a game which npc will randomly trigger travel event, but i need the npc to calculate the clear path to the end and avoid crash into rock and hill 😂
@leelavathisettu27623 жыл бұрын
Where is the code for the DFS approach
@anssha26434 жыл бұрын
Best explanation of DFS. Thanks a lot. God bless you
@BackToBackSWE4 жыл бұрын
sure
@ShikharKumar-fz6ti21 күн бұрын
Amazing video, do you have one of these Maze path for BFS, A*, Uniform Cost Search?
@kirillzlobin7135 Жыл бұрын
Maaan, you are the legend. Thank you for your brilliant explanation!!!
@BackToBackSWE Жыл бұрын
Happy Halloween 🎃 Thank you from one legend to another, kirillzlobin! You get some extraaa treats - 50% Off our exclusive lifetime membership use the code SPOOKY50 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=SPOOKY50
@umairbijapure75843 жыл бұрын
U hv given a greatest explanation i ever had on KZbin..but implementation is also important right..plz do explain codes as well
@lifecodesher58184 жыл бұрын
this man is international version of sumeet sir of pepcoding
@BackToBackSWE4 жыл бұрын
what lol
@fmpwizard2 жыл бұрын
Awesome explanation! Very clear and the right amount of details
@jefferyxie32483 жыл бұрын
Thanks so much for the video! This makes so much more sense now
@multichannellk19664 жыл бұрын
Where is the solution code please give me the link
@BackToBackSWE4 жыл бұрын
The respository is deprecated - we only maintain backtobackswe.com now.
@andyhujian4 жыл бұрын
Good talk. But it's different from maze leetcode. In leetcode problem, it can't choose directions at will. It needs to hit a wall before making a turn.
@BackToBackSWE4 жыл бұрын
ok
@santasingh90454 жыл бұрын
take a bow,man!
@BackToBackSWE4 жыл бұрын
bow
@julianbullmagic4 жыл бұрын
keep posting videos, I would love to see more of this
@BackToBackSWE4 жыл бұрын
ok will do
@mariasandru75 жыл бұрын
What if we wanted to search for all the possible paths? I am talking about the Unique Paths III problem on Leetcode. Amazing video btw!
@BackToBackSWE5 жыл бұрын
We can just do a DFS and imagine this as a tree. The "leaf" is the end, we keep track of the path up to the end then add it as an answer, then backtrack, and if we reach the end again we again register the different way we got there.
@mariasandru75 жыл бұрын
@@BackToBackSWE Thank you! I got accepted from the first submission:D
@BackToBackSWE5 жыл бұрын
@@mariasandru7 nice
@richardaguilar76924 жыл бұрын
Thank you so much for this! Very clear and concise explanation of DFS.
@BackToBackSWE4 жыл бұрын
sure
@aliceabejo80443 жыл бұрын
What the decimals please?
@Yusifinify3 жыл бұрын
Brilliant - clear and concise!
@ramraut1805 жыл бұрын
The great video. Thank you so much for your contribution. Keep continuing making this type of video. Thumbs up !
@BackToBackSWE5 жыл бұрын
sure
@toyadavrahul5 жыл бұрын
Great Explanation!! would be better with some pseudo code!! Else found it really helpful. Thanks!!
@BackToBackSWE5 жыл бұрын
nice
@267praveen3 жыл бұрын
Ques - why we didn't chose BFS here? And what was the reason behind chosing DFS? You did mention that BFS gives shortest path but then switched to DFS. Can you please shed some more light?
@manurajput53483 жыл бұрын
Hey can you explain why the time complexity is V+E. We are checking 4 (i.e. E) edges for each vertices(V). So shouldn't the complexity be 4V i.e. V.E?
@svdfxd5 жыл бұрын
Awesome explanation. Keep up the good work. Do you have a concise list of Algorithms that we must study? I have gone through udemy courses but there are many many algorithms. It would be good if there is a list which lists all important algorithms.
@BackToBackSWE5 жыл бұрын
For interviews or to become a great computer scientist? For interviews check this readme: github.com/bephrem1/backtobackswe To become a great computer scientist I'm not totally sure. There is too much to cover here in one comment.
@svdfxd5 жыл бұрын
For the interviews :). Thanks a lot.
@BackToBackSWE5 жыл бұрын
@@svdfxd Yeah, read EPI. Watch all Hacker Rank videos on KZbin. And....watch my videos in the coming months :)
@lawlietnao_music5 жыл бұрын
dude I hecking love you, if I get the offer I'll definitely donate the shit out of u
@BackToBackSWE5 жыл бұрын
Don't, just get the offer.
@zackzayco91353 жыл бұрын
Great information 💪🏽💯 I appreciate it
@atmafra1971Ай бұрын
Very helpful, thanks a lot!
@promamukherjee58743 жыл бұрын
If I'm not mistaken, this approach is backtracking, right? And its complexity is to the exponential order of 2^(n*m) where n*m is the order of the matrix, but for a vanilla DFS we should have linear complexity, O(m*n)
@kyawn51154 жыл бұрын
Great content! Keep up the good work!!
@BackToBackSWE4 жыл бұрын
ok
@akhilk51214 жыл бұрын
I am confused. You said in your bfs,dfs fundamentals that bfs can be used to check "if a path exist" . Here you said bfs is going to give the shortest path so its better to use dfs to find "if a path exist". What did i miss?
@BackToBackSWE4 жыл бұрын
Both can be used for path search
@MdMainuddinJU3 жыл бұрын
Subscribed the channel, Liked the video, it deserves it.
@jonaurz4 жыл бұрын
you explained so well, thank you!
@BackToBackSWE4 жыл бұрын
sure
@exkorbuto15 жыл бұрын
Well, I had a similar problem but there can be too many paths, that adds complexity. And I had to choose the shortest.
@BackToBackSWE5 жыл бұрын
nice
@sidb80664 жыл бұрын
Hey! Great video! What;s the difference between DFS and Backtracking on this problem? Cant both be used and wont both work the same way?
@BackToBackSWE4 жыл бұрын
DFS is a search methodology. Backtracking entails looking at candidate solutions in an exhaustive way (often following a search path) and "backtracking" to abandon partial solutions once they can't lead to a final solution. Both can happen at the same time. Example: "Search a graph for paths from the start to the end with cost < 100, no nodes have a negative cost." If I am on a path and my cost hits 140 I could be deep into a path (if I am using DFS) but I'd backtrack to the previous node I was at since I can't recover (i shouldn't have stepped on the next node in the first place but you get the idea).
@martinharris44164 жыл бұрын
OMG YOU'RE SOOO DEEEEP
@BackToBackSWE4 жыл бұрын
ok
@rizzbod Жыл бұрын
this is amazingly amazing explanation. thnx buddy
@jeffreyslominsky76564 жыл бұрын
Thank you, your explanations are great!
@BackToBackSWE4 жыл бұрын
sure and thanks
@drizle92314 жыл бұрын
That was a very clear explaination.Keep it up ! 😊
@BackToBackSWE4 жыл бұрын
ok
@chrisliu54035 жыл бұрын
appreciate it man, well explained.
@BackToBackSWE5 жыл бұрын
sure
@adrizamishra75683 жыл бұрын
Thank you for saving us!
@althafa83715 жыл бұрын
atlast i found non indian tutorial :P , good explanation bro
@BackToBackSWE5 жыл бұрын
ye, indians r brothers tho
@dinner4chiahao Жыл бұрын
Your vids are brilliant.
@nanamahmoud1474 жыл бұрын
I want to ask how did you decide the order of the operations "up","right","left",down" , is it because you compared the starting cell and the goal/end cell and found out you should prioritize "up" and "right" operations ? so thats why they are at the top of the order of the operations and you check on them first?
@nanamahmoud1474 жыл бұрын
and can you please provide me the of the code that corresponds to this problem
@niddynoddy4 жыл бұрын
I'm currently having a problem with implementing DFS in ruby, and have had it for a week now. Is there a way to get the code out of this video anymore?
@rubaiyathussain31245 жыл бұрын
Thank you. i fully grasp it.
@BackToBackSWE5 жыл бұрын
nice
@Thadnill4 жыл бұрын
If I want to use the DFS to generate a maze in C++, and not necessarily solve it, how should I think and start out? Thanks for the great video!
@BackToBackSWE4 жыл бұрын
sure and you can google that?
@maxinteltech33213 жыл бұрын
Awesome explanation
@shathamaayouf60485 жыл бұрын
I need you to switch positions with my German lecturer
@BackToBackSWE5 жыл бұрын
hahahaha
@rishabhmalhotra22254 жыл бұрын
Can you explain how to represent the maze in the form of a graph?
@BackToBackSWE4 жыл бұрын
cell is a node, edges are the 4 adjacent walls
@Thadnill4 жыл бұрын
Woa, you just got my sub! P.S do you have the code available? I can't find it
@BackToBackSWE4 жыл бұрын
Thanks, and the code repository is deprecated - we only maintain backtobackswe.com now.
@gk797974 жыл бұрын
Awesome explanation sir!!!
@BackToBackSWE4 жыл бұрын
sure
@deepusasidharan20123 жыл бұрын
Great Visulazation material....Please draw a small CallStack as well.....
@alanye75422 жыл бұрын
So amazing! Thanks!
@dongshuowu34545 жыл бұрын
Amazing as usual.
@BackToBackSWE5 жыл бұрын
thanks haha
@algorithmimplementer4155 жыл бұрын
May I ask, if you are given an adjacency matrix of m x m, in that case what would be the time complexity of DFS path finding algorithm? Could you also explain?
@BackToBackSWE5 жыл бұрын
Sure, this search should give you what you need: www.google.com/search?q=DFS+with+adjacency+matrix+time+complexity&oq=DFS+with+adjacency+matrix+time+complexity&aqs=chrome..69i57j0l5.7645j1j7&sourceid=chrome&ie=UTF-8
@parthsohani24294 жыл бұрын
When should we go for bfs for such maze problems? Other way round, when should we go for dfs for such maze problems?