Тёмный

Depth First & Breadth First Graph Search - DFS & BFS Graph Searching Algorithms 

Back To Back SWE
Подписаться 242 тыс.
Просмотров 213 тыс.
50% 1

Free 5-Day Mini-Course: backtobackswe.com
Try Our Full Platform: backtobackswe....
📹 Intuitive Video Explanations
🏃 Run Code As You Learn
💾 Save Progress
❓New Unseen Questions
🔎 Get All Solutions
DFS and BFS are not just graph search algorithms. They are a fundamental method for searching relationships in a certain way and visiting nodes of any sort in a desired order.
These relationships may be represented in a graph, or we may be checking the distance one string is in character changes from another string, OR we may be traversing a tree a certain way.
These are searching concepts, not just graph concepts.
Implementation
DFS can be done iteratively using a stack or done recursively because the call stack will serve as the stack to remember points to backtrack to.
A stack structure can replace our stack frames from recursion, this is why DFS can be written recursively, due to the Last-In-First-Out (LIFO) of the order nodes are processed.
BFS is done iteratively. It uses a queue that has a First-In-First-Out processing order.
Use Cases
DFS is good for things like backtracking, getting to leaf nodes in a tree, or anything where we want to prioritize going very deep into a path and exhausting possibilities before coming back.
BFS is better for things like finding if a path exists between one node to another since it prioritizes width of search over depth (hence "breadth-first") and finding distance or "levels" something is away from something else.
The Method
1.) Choose the data structure based on the search.
2.) Add the start node.
3.) Remove the a node from the data structure.
4.) If the node has not been seen
4a.) Mark it as seen in the "seen" set.
4b.) Do work on the node.
5.) For each of the children
5a.) If child has not been seen (not bee processed)
5ai.) Add the child to the data structure.
Repeat while the data structure is not empty.
Time Complexities
If relationships are represented with an adjacency list then:
Time: O(V + E)
Space: O(V)*
Where V is the total number of vertices (or nodes) visited and E is the total numbers of edges traversed.
*Although things will vary. We only care about the MAXIMUM amount of nodes in the data structure at one time. If we are doing DFS on balanced tree the space complexity would be O(h) where h is the height of the tree since we would only have a path h nodes long at MAX living on the stack. Same for if we do a level order traversal of a tree. The space will only be the MAXIMUM WIDTH of the tree because we would only keep that many nodes on the queue at MAX at one time. And on and on...just depends, ask your interviewer whether they want worst, average, or best case analysis.
"adjacency list" means each node stores its adjacent neighbors in a list
++++++++++++++++++++++++++++++++++++++++++++++++++
HackerRank: / @hackerrankofficial
Tuschar Roy: / tusharroy2525
GeeksForGeeks: / @geeksforgeeksvideos
Jarvis Johnson: / vsympathyv
Success In Tech: / @successintech

Опубликовано:

 

2 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 450   
@BackToBackSWE
@BackToBackSWE 5 лет назад
Table of Contents: (and side notes) Finding A Room 0:00 - 0:21 DFS & BFS Introduction 0:21 - 3:37 DFS & BFS Algorithm Outline 3:37 - 6:07 Depth First Search Example 6:07 - 10:16 Breadth First Search Example 10:16 - 14:00 The Pattern Of Breadth First Search 14:00 - 14:32 Wrap Up 14:32 - 15:02 Depth first and breadth first search on a graph. These are just approaches to searching and are raw by themselves. Graph search in "real life" makes use of certain heuristics along the way to get to the answer faster (whatever the problem may be). Also is this is DFS or BFS on a tree where a cycle is not possible then the hashset is not necessary.
@timgoppelsroeder121
@timgoppelsroeder121 5 лет назад
Dope thanks man
@BackToBackSWE
@BackToBackSWE 5 лет назад
ye
@taiwan.1
@taiwan.1 5 лет назад
You deserve an Academy Award for all these videos you have made.
@BackToBackSWE
@BackToBackSWE 5 лет назад
hahahahahaha
@mujtabaarfat717
@mujtabaarfat717 3 года назад
He did absolutely nothing . U were too lazy to understand it on ur own .
@yutaitadori7318
@yutaitadori7318 3 года назад
@@mujtabaarfat717 😐
@ashwinpande7095
@ashwinpande7095 2 года назад
@@mujtabaarfat717 damn bro who hurt u
@tachylamurray9452
@tachylamurray9452 2 года назад
DEADASS! Your content is so helpful and it just encourages me to see a person of color with so much passion. Thank you for these videos!
@reedmurphy3073
@reedmurphy3073 2 года назад
I remembered this video from the last time I needed to prepare for coding interviews, and now that it's that time again I came right back. I appreciate the simple, yet thorough explanation!
@Acroft96
@Acroft96 Год назад
For some reason, this concept was so hard for me to understand, but you explained it so well. I'm a visual learner and I think I finally get it, so thank you!
@BackToBackSWE
@BackToBackSWE Год назад
Really glad to help 🎉 Do you know about our 5-Day Free DSA Mini Course? Check it out here - backtobackswe.com/
@qingtianwang3511
@qingtianwang3511 3 года назад
Great video. Thanks! One BFS issue, though: The place to mark a node is seen/visited should be before it is enqueued, instead of after it is dequeued. This makes a difference, for example, when you need to trace back the shortest path via parent nodes.
@wanyi8761
@wanyi8761 3 года назад
Mate! I really appreciate you for all these videos! I always come to this channel first and watch a video when I got any data structure related problems huge fan!!
@AvivaScott
@AvivaScott 2 года назад
This is fantastic -- thank you for making a technical, educational video that's actually enjoyable to watch
@BackToBackSWE
@BackToBackSWE 2 года назад
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@pranitachikorde603
@pranitachikorde603 2 года назад
This guy can explain rocket science to a baby, in-depth knowledge with crystal clarity
@AdityaMishra-ve6yu
@AdityaMishra-ve6yu 4 года назад
This channel is surely one of my favourite on programming.The way he explains is breathtaking.He is breathtaking.😊
@BackToBackSWE
@BackToBackSWE 4 года назад
ur my favorite
@anarbay24
@anarbay24 3 года назад
You are breathtaking! You are all breathtaking!
@jfklittle
@jfklittle 3 года назад
@@anarbay24 Wake the f*ck up samurai! We have a city to burn!
@kellybmackenzie
@kellybmackenzie Год назад
Thank you SO MUCH! Your explanation of Depth First Search with a stack finally helped me understand it. Thank you so much!!
@BackToBackSWE
@BackToBackSWE Год назад
Thank you, appreciate it 😄 Also check out our Free 5 Day DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉
@lciduhtak4278
@lciduhtak4278 Год назад
Iam knowing the real problem I had in DFS , but now I knew it perfectly .. amazing 👍🏿
@hoangvietng7100
@hoangvietng7100 9 месяцев назад
Brilliant explanation! Thanks for your energetic effort, I love it.
@_janol
@_janol 5 лет назад
Great job done, after your explanation I finally understand everything. Keep on doing good work!
@BackToBackSWE
@BackToBackSWE 5 лет назад
That is the goal. Keep flourishing.
@AH-xb7eb
@AH-xb7eb 4 года назад
Got a google internship interview coming up, hope these vids help. You're a legend man
@BackToBackSWE
@BackToBackSWE 4 года назад
ok - let us know if u get ti
@II_xD_II
@II_xD_II 4 года назад
practising on cf will help more
@AH-xb7eb
@AH-xb7eb 4 года назад
@@BackToBackSWE Just passed the Hiring Committee! Thanks for your help!
@MundoTecChannel
@MundoTecChannel 3 года назад
@@AH-xb7eb nice! I’m having mine next week. What type of questions were you asked during the interview?
@AH-xb7eb
@AH-xb7eb 3 года назад
@@MundoTecChannel I was asked a graph problem, which is funny because this video goes over graph traversal. It was a leetcode medium type of question. I was also asked to create a class responsible for managing items, with several follow ups.
@vimalk2661
@vimalk2661 4 года назад
If I need some explanation . I look for your videos man. That's the end point for me, I just get what I need.
@BackToBackSWE
@BackToBackSWE 4 года назад
great.
@sudeepwegapitiya2157
@sudeepwegapitiya2157 3 года назад
Great! Clearly explain everything. Thank you !
@nofaldiatmam8905
@nofaldiatmam8905 3 года назад
you are way better than my professor explaining this at uni, thanks mate !
@MoSweiti666
@MoSweiti666 4 года назад
One minute in , I clicked the subscribe button! Thanks man!!
@BackToBackSWE
@BackToBackSWE 4 года назад
nice
@vasundhramanhas7884
@vasundhramanhas7884 5 лет назад
u r doing such a great job.Your content is the best. I wish u all the success in life. God bless you. I think I texted the wrong guy on insta named ben ephrem in order to thank you. :(
@BackToBackSWE
@BackToBackSWE 5 лет назад
haha
@yuezhang604
@yuezhang604 5 лет назад
The video is great! Your explanation is very clear and helpful! Can you also post a video of how to DFS on a string?
@BackToBackSWE
@BackToBackSWE 5 лет назад
I have a video for that. Decomposition of an IP address. And it is not really depth-first search. Wikipedia: "Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures."
@gyanprakash302
@gyanprakash302 3 года назад
Damn Such A beautiful explanation. Thankyou. Love from INDIA.
@mr_lamintun
@mr_lamintun 3 года назад
Thanks a lot for the very clear explanation. Keep up the great work.
@historian2
@historian2 2 года назад
Alright, it is 7 in the morning today we are doing a breakfast search! I was looking forward to a drive to the Ihop and enjoying some vicarious breakfast!
@Manu-wb2uv
@Manu-wb2uv 4 года назад
So we can basically use any kind of data structure for what nodes to process next. Stack for DFS, Queue for BFS, HashSet for random. I think in some cases HashSet would be more useful.
@BackToBackSWE
@BackToBackSWE 4 года назад
ye
@Manu-wb2uv
@Manu-wb2uv 4 года назад
​@@BackToBackSWE There is only one problem. If you use DFS iteratively to try and find cycle in a directed graph, you might run into lot's of implementation problems as you need to backtrack the remaining nodes and it;s quite hard to do it iterative.
@rogerwang21
@rogerwang21 4 года назад
Why isn’t the for loop nested in the if block on the same level in the code? I don’t think a node should be processed if it has already been seen.
@BackToBackSWE
@BackToBackSWE 4 года назад
I dont remember this video since it is way back
@Hav0c1000
@Hav0c1000 4 года назад
You are right. If you have already visited the current node, you don't need to add its children, because you've already done that, last time you visited the node.
@parthsohani2429
@parthsohani2429 4 года назад
Why the time complexity is O(V+E) and not O(VE) ? I mean if you look at the code ( when we implement dfs using adjacency list) we have one loop for stack and one (obviously inside it) for finding the connected vertex in the list. So, for each vertex we are having E operations. So, why we say O(V+E)?
@BackToBackSWE
@BackToBackSWE 4 года назад
Don't look at the loops. Consider what V and E are. V is the total vertices & E is total edges over the whole graph (not per vertex). So we at worst we touch all V vertices, at each we will do some amount of checks to look at adjacents. Across the search there are E edges to check and each can get touched once or twice. Either way that is O(E) work if a check is O(1). So overall, we will do V visits (if we avoid duplicate visits and touch the whole connected component) each using O(1) time to print a value and the like. The overall work of the edge checks is bounded O(E), each taking O(1). So overall we do O(V) in work from vertex visitation & O(E) work in edge inspection.
@Labattfartoui
@Labattfartoui 4 года назад
Why can't I have this much energy and clarity at 7am??? Great explanations. Thank u.
@BackToBackSWE
@BackToBackSWE 4 года назад
lol I was a rabid lion back in the day with no mic equipment
@AkamiTenzuo
@AkamiTenzuo 2 года назад
Best explanation ever!
@alanwang6563
@alanwang6563 4 года назад
You are extremely good at explaining things! Most of the DFS&BFS tutorial video on RU-vid is just to go through the code and example but you mentioned when and why we use DFS or BFS from a high-level perspective which is good for beginners to understand those algorithms.
@BackToBackSWE
@BackToBackSWE 4 года назад
thx
@johnnymeza5454
@johnnymeza5454 4 года назад
Hey I'm only 2 minutes in but god damn this is really well explained. I loved the visualization and the when to use each. Thank you! I'm a self taught developer so this content is just what I needed to help me solve a problem.
@BackToBackSWE
@BackToBackSWE 4 года назад
sure and great
@superchillh3o
@superchillh3o 5 лет назад
You are an excellent teacher, thank you
@BackToBackSWE
@BackToBackSWE 5 лет назад
sure
@iliatadzhibaev3573
@iliatadzhibaev3573 5 лет назад
The best explanation ever! Thank you so much!
@BackToBackSWE
@BackToBackSWE 5 лет назад
sure
@danielcohen1765
@danielcohen1765 5 лет назад
With DFS, Aren't you suppose to go deep and visit all the nodes(in this example) and then go back to the first node? It looks like you You traveresed with DFS exactly like BFS(Except the queue).... Great job with your Videos, thanks!
@BackToBackSWE
@BackToBackSWE 5 лет назад
I made this a while back, I'd have to rewatch to verify, I'm rapid fire responding to comments right now
@JacobAzzy10
@JacobAzzy10 4 года назад
Very helpful! Thank you!
@BackToBackSWE
@BackToBackSWE 3 года назад
sure
@joy-sm5sl
@joy-sm5sl 2 года назад
i really love the way you explain things. you always sound excited while explaining and that motivates me to learn and keep my attention on what you're saying. awesome content, sir! 🔥
@leaffsux
@leaffsux 4 года назад
Very helpful!Thank you very much.
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@venkatachengalvala4289
@venkatachengalvala4289 3 года назад
Minor mistakes but well-explained and really enthusiastic! :)
@charankumarr3506
@charankumarr3506 4 года назад
Man u r underrated. U deserve more subs
@BackToBackSWE
@BackToBackSWE 4 года назад
Nah I'm just normal and we will do fine
@javarepository2420
@javarepository2420 2 года назад
pulled it, processed it, add its children.
@siam-al-merchowdhury953
@siam-al-merchowdhury953 2 года назад
Can you please explain how curr.adjacents work inside enhanced for loop? time stamp 5:55
@mrodriguezglobe
@mrodriguezglobe 4 года назад
How do we handle disconnected graphs or directed graphs? Or maybe handling the two scenarios I mentioned is not necessary as far as leetcode / technical interview questions? Some guidance on these scenarios would be appreciated!
@BackToBackSWE
@BackToBackSWE 4 года назад
Ensure you start a DFS on all nodes and don't revisit nodes. If you don't have a reference to all nodes then you just won't discover the disconnected nodes.
@mrodriguezglobe
@mrodriguezglobe 4 года назад
@@BackToBackSWE Thank you for the reply, this helps me a lot
@OverLordOfDa3rdWorld
@OverLordOfDa3rdWorld 3 года назад
Impeccable explanations! Jesus lord..
@jedbrodriguez
@jedbrodriguez 3 года назад
7:50 Beginner here.. How do we make sure that E will be added first to the stack before H ? What if we added H first before E ? Won't the output be A,B,C,D, H .. which is incorrect?
@BackToBackSWE
@BackToBackSWE 3 года назад
The for loop over adjacents will enforce ordering and you can arbitrarily choose how you iterate over a layer. Was this for DFS or BFS? I just addressed bfs
@DavidEspinosa21
@DavidEspinosa21 4 года назад
I implemented the code in the video if anyone wants to see it or play with it: repl.it/@davidespinosa/DFSAndBFS2#Main.java
@SinKosh
@SinKosh 4 года назад
Thanks! Implementing in Java and Python works fine, but I can't seem to make it work in C++. Wonder if anyone else tried this specific implementation. C++ version: repl.it/@craycosh/PhonyUprightUpgrade#main.cpp Edit: Aight nvm, I should've used pointers lol
@BackToBackSWE
@BackToBackSWE 4 года назад
nice
@majesticflyingbrick
@majesticflyingbrick 3 года назад
Great vid, very clearly explained. But please don't edit out the parts where you are writing or erasing stuff on the whiteboard it makes it hard to keep track of the changes on the board.
@miaboloix1737
@miaboloix1737 4 года назад
Question: In an interview, what is the benefit of keeping a "seen" HashSet to keep track of visited Nodes vs. potentially defining the Node class to have a "visitited" boolean field and just toggling it?
@BackToBackSWE
@BackToBackSWE 4 года назад
Ultimately whatever works works. But that would be a bit odd since "seen" is not inherent to the data type and its purposing. As a programming choice that'd seem odd? Otherwise, whatever
@3Deviant_
@3Deviant_ 2 года назад
I would say it is better because what if the graph is giant, like 10^10 amount of nodes. When this search starts the visited array would be empty, whereas the other binary flip method will add that small amount of space taken up by the bit by the amount of nodes there are. So lets say a binary flip takes up 8 bits and there are 100 nodes. 8bits*100 space is taken up right away from the start. While the array method is still very small when it starts space wise since its empty.
@lucaslemosfranco2413
@lucaslemosfranco2413 4 года назад
Awesome!
@BackToBackSWE
@BackToBackSWE 4 года назад
Thanks!
@howtobuildProduction
@howtobuildProduction 2 года назад
Does curr.adjacents refer to the list of adjacent neighbors? How would that be implemented within the Node class?
@aishwaryam1052
@aishwaryam1052 4 года назад
Hello. I have a doubt. This algorithm is not working for the following graph g.addEdge(0, 1); g.addEdge(0, 2); g.addEdge(1, 2); g.addEdge(2, 0); g.addEdge(2, 3); g.addEdge(3, 3); The actual ans is 2 0 1 3 But i am getting the ans as 2 3 0 1
@BackToBackSWE
@BackToBackSWE 4 года назад
I'm not sure, I did this a while back
@manojthalari7075
@manojthalari7075 4 года назад
when will you upload connectivity cycles,articulation point,strongly connected components,dijkstra and topological sorting
@BackToBackSWE
@BackToBackSWE 4 года назад
uh
@II_xD_II
@II_xD_II 4 года назад
can ya make a video on adjacency list and matrix :(
@BackToBackSWE
@BackToBackSWE 4 года назад
I covered it in other videos I believe
@Fleshlight_Reviewer
@Fleshlight_Reviewer 4 года назад
thank you for this
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@grunze
@grunze 4 года назад
We use stack when it goes deep. Imagine like in a real scenario where you would want to hold items. If there was a hole you would not be able to hold items vertically, hence you would use stack as it is like a deep hole with its ends closed. But queue is open on both ends and would only hold items when parallel. Hence its broad and can be used during BFS. Just for a quick mapping in head.
@BackToBackSWE
@BackToBackSWE 4 года назад
nice
@sidagarwal43
@sidagarwal43 4 года назад
Beautiful explanation, cleared all my doubts,. Thanks man
@BackToBackSWE
@BackToBackSWE 4 года назад
nice and sure
@jimmyloluolajide7777
@jimmyloluolajide7777 3 года назад
Very informative. Thanks for sharing. Please, I have a question relating to this topic and would like to contact you. How do I reach you? Thanks
@hosseinrad6730
@hosseinrad6730 Год назад
E node is already in stack, why you visit it twice? Sth's not making sense I think
@SamTablet-z9t
@SamTablet-z9t 3 месяца назад
amazing. thanks
@The8merp
@The8merp 4 года назад
between the recursive and stack approaches for DFS, when should we use which and which is better in terms of time and space complexity
@BackToBackSWE
@BackToBackSWE 4 года назад
both are the same in time and space, the explicit stack just uses a stack in memory, the recursive uses the literal call stack to hold state (which is also a stack stack)
@mrinal2100
@mrinal2100 4 года назад
Please don't edit your video so much,there should be some continuity in the video. Watching it is as if someone is running a 100 m race. We don't mind watching 3 or mins extra
@BackToBackSWE
@BackToBackSWE 4 года назад
one of the first videos i ever made
@II_xD_II
@II_xD_II 4 года назад
Floyd Warshall Algorithm plz explain not getting it from any channel who have video on this topic
@BackToBackSWE
@BackToBackSWE 4 года назад
maybe
@II_xD_II
@II_xD_II 4 года назад
@@BackToBackSWE Dijkstra Prim Kruskal also
@elijahabel8219
@elijahabel8219 4 года назад
Is there any benefit to enqueueing already enqueued nodes in BFS? Why not add nodes to the hashmap when they're added to the queue, and then when considering adding a neighbor to the queue, check the hashmap before enqueueing it? The way you're suggesting, your machine code would contain unnecessary instructions. Let me know if I'm missing something. It makes perfect sense to do this for DFS since we want depth first, but I just don't see the benefit for BFS.
@BackToBackSWE
@BackToBackSWE 4 года назад
Yes that is how it should be done. Old video - I did it a while ago.
@elijahabel8219
@elijahabel8219 4 года назад
@@BackToBackSWE Ah, makes sense. Solid videos by the way! I'm revisiting some concepts I haven't in a while and it's useful.
@codeblooded6760
@codeblooded6760 4 года назад
How to calculate how many layers deep we went from source node to destination node in bfs? i.e number of moves taken?
@BackToBackSWE
@BackToBackSWE 4 года назад
pass layer as a param
@supamdeepbains5172
@supamdeepbains5172 4 года назад
Cool T-shirt bro!
@BackToBackSWE
@BackToBackSWE 4 года назад
thx
@DanielDiaz-rq3ko
@DanielDiaz-rq3ko Год назад
I’m about to graduate and with most jobs requiring a technical of some sort I finally decided to start grinding LC. The impostor syndrome feels so real but your videos are so insanely helpful I’m regaining my confidence. All I can say is thank you. It’s rare for people to be able to explain things so well it feels like.
@anilshekhar8905
@anilshekhar8905 5 лет назад
Brilliant ...
@BackToBackSWE
@BackToBackSWE 5 лет назад
love.
@zzzz26526
@zzzz26526 3 года назад
This is awesome! I still have trouble determining when I should use either BFS or DFS in a problem. Any tips on how you can be like "oh BFS or DFS can be used here"? This makes sense with nodes but how about when you're working with strings/2d arrays/etc.?
@Canonall
@Canonall 4 года назад
This channel is so underrated! Thanks so much for this!
@BackToBackSWE
@BackToBackSWE 4 года назад
thx.
@peevesthepoltergeist2070
@peevesthepoltergeist2070 2 года назад
BFS loves their neighbours more. DFS is conquer, can't settle.
@jubjubfriend64
@jubjubfriend64 4 года назад
Can you explain why BFS is not O(nlogn + m)? is it because each time you add or remove a node from a queue it's log|Q| time (rather than logn)? so you're effectively doing n number of log|Q| operations which round down to n number of primitive operations? ... like log(|Q|) < log(N) < N... thanks
@BackToBackSWE
@BackToBackSWE 4 года назад
Queue insert and removal is O(1). There are O(E) edges touched with O(1) work done on each and we visit O(V) vertices and do O(1) on each. This is O(V+E)
@jubjubfriend64
@jubjubfriend64 4 года назад
@@BackToBackSWE Right thank you! I realize now I was thinking of a priority queue structure rather than a simple linear based queue! makes sense now! Awesome vids in general btw
@mouseclicker4955
@mouseclicker4955 3 года назад
After watching this video, DFS and BFS finally clicked for me. I have watched countless videos on the subject, but you are the only one that explained it simply enough for me to understand. Thank you so much! Just subscribed.
@michaelouyang1416
@michaelouyang1416 2 года назад
Could we put the for loop block inside the if block?
@easifier
@easifier 2 года назад
thanks for the clear explanation it was very helpful :)
@BackToBackSWE
@BackToBackSWE 2 года назад
Thanks! why dont you try our 5 day free mini course backtobackswe.com/
@FitCoder
@FitCoder 4 года назад
Explained in a very simple manner.
@BackToBackSWE
@BackToBackSWE 4 года назад
thx
@journeytowardslife9830
@journeytowardslife9830 3 года назад
Great video ! I had one doubt , what if the graph had duplicate elements ? Since we use set , if there is one element say c and it's already seen and if there is another c , then it won't be processed right ? What to do in that case ?
@purovenezolano14
@purovenezolano14 4 года назад
Great stuff. Thanks!
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@b747
@b747 5 лет назад
This channel rocks... those explanations are crystal clear, this channel will grow in the order of O(n!) :-)
@BackToBackSWE
@BackToBackSWE 5 лет назад
haha k
@DishaSaraiya_xo
@DishaSaraiya_xo 4 года назад
@@BackToBackSWE I SAY O(2^N) !!!!!
@BackToBackSWE
@BackToBackSWE 4 года назад
@@DishaSaraiya_xo ok lol
@CuriousWithOscar
@CuriousWithOscar 4 года назад
Awesome videos man! I'm currently taking a Computer Science course with Lambda School and they have been teaching us all these Data Structure techniques that are pretty common in a workplace. From what I understand I have yet to work in a real world environment, I mean I've done some contract work being a Team Lead and managing a team but now I have to actually think like an engineer and I got to say your videos have been super helpful! Thank you for your free content and work you've put together. I really love this Profession field.
@BackToBackSWE
@BackToBackSWE 4 года назад
Great. Lambda school, nice! Keep going! The internet is here for you. Do you know anyone at Lambda school we could talk to? It'd be cool to do a deal with them as we grow.
@EinsteinNewtonify
@EinsteinNewtonify 4 года назад
I would have sorted the list for bfs in reverse order. E.g. in python you have th deque function which gives yo queue.leftpop for First In First Out.
@BackToBackSWE
@BackToBackSWE 4 года назад
ok
@mallikarjunpidaparthi
@mallikarjunpidaparthi 4 года назад
Wow! All my doubts are now gone after seeing this video... Thank you so much brother
@BackToBackSWE
@BackToBackSWE 4 года назад
great - sure
@icono__7136
@icono__7136 4 года назад
I'm confused: doesn't the for-each loop perform BFS? If so, why are we implementing a BFS loop in DFS method?
@icono__7136
@icono__7136 4 года назад
Nvm I got it
@BackToBackSWE
@BackToBackSWE 4 года назад
@@icono__7136 lol nice.
@wrestlingscience
@wrestlingscience 3 года назад
yo is that mckeldon library LMAO
@muskansinghal3685
@muskansinghal3685 3 года назад
While doing dfs example, you add elements to stack as B -> C--> D--> E , but order of element is wrong when these are popped out as B is getting popped first ?? Or are we pushing in order E--> D--> C--> B only ??
@sarahebal4391
@sarahebal4391 11 месяцев назад
Thank you, sir, you are extremely good at explaining! Are there other algorithms that I could use to find a set of feasible paths between two nodes in a graph? I'm not searching for all possible paths but i m looking for a set of most promessing path
@Anna-cl4rj
@Anna-cl4rj 3 года назад
You explain very well. You helped me with another concept last year, I was so happy to see your face in the search results for DFS and BFS algorithms because I have dry slides. I have hope for passing my AI class now haha.
@shwetadk1986
@shwetadk1986 5 лет назад
Love your videos !. Hey can you please do a video on Course Schedule - Leetcode problem 207
@BackToBackSWE
@BackToBackSWE 5 лет назад
I'm aware of that problem. But to be fair to patrons of this project I only take suggestions from those who support the project on Patreon. I didn't do this before the Patreon launched but now I have to be fair to them.
@jobomathaha7420
@jobomathaha7420 2 года назад
hey on BFS you left "H" when you were mentioning the children of D now it is changed the processing order and Thank you for the awesome video you're the best I know keep it up
@abdulmalekbaitulmal5658
@abdulmalekbaitulmal5658 4 года назад
damn man! If only others have your talents, education would be much easier.
@BackToBackSWE
@BackToBackSWE 4 года назад
thx
@robinsharma6487
@robinsharma6487 4 года назад
Great explanation. One thing is can we loop on a node's children only when it is unseen instead of going through the loop even though the node is already seen. This might save some constant time iterations.
@BackToBackSWE
@BackToBackSWE 4 года назад
ok
@TheBjjninja
@TheBjjninja 2 года назад
He said "so" one million times!
@BackToBackSWE
@BackToBackSWE 2 года назад
Trying "so" hard to make the best content. Hope you were able to understand the topic well.😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@gabrielabezerra3434
@gabrielabezerra3434 4 года назад
THANK YOU! Great channel you got there! Keep up the good work
@BackToBackSWE
@BackToBackSWE 4 года назад
ok thanks
@metehanemir7454
@metehanemir7454 4 года назад
You are so good and enthusiastic at explaining, I never get bored learning something from you. Real good!
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks
@vtserej
@vtserej 4 года назад
good video, question if a node has been seen we shouldn't even be looping thru the edges (DFS)
@BackToBackSWE
@BackToBackSWE 4 года назад
yeah, that's true
@leomonz
@leomonz 4 года назад
Node Adjacents...... Can I have peek to the Node class how it define Adjacent
@BackToBackSWE
@BackToBackSWE 4 года назад
It is a list of numbers or Node objects.
@leomonz
@leomonz 4 года назад
@@BackToBackSWE I think it is double LinkedList , so it is .next or .prev depends implementation
@serhattural3168
@serhattural3168 3 года назад
I think there is something wrong in your example both for DFS and BFS. There shouldnt be same element more than once both for Stack and Queue. But in your example you are using same items more than once in stack and queue.
@minhdang1994
@minhdang1994 3 года назад
Why don't we skip the adding loop after we check that the node is visited? I understand that we don't add any new node in the stack, but we still add some redundant operations right?
@nicholascastro4175
@nicholascastro4175 5 лет назад
Got an interview next week. Just what I needed! Good stuff, guys
@BackToBackSWE
@BackToBackSWE 5 лет назад
it is just Ben now (this is Ben) and good luck!
@G007-e9p
@G007-e9p 3 года назад
bro can you implement it on eclipse as it will highly help me, I am getting some errors when I copy your code over eclipse after importing all the files like it says change the parameter Node start to Integer start
@milanpatel6240
@milanpatel6240 3 года назад
I just loved the explanation. My fundamentals for DFS and BFS were never this much clear. Thanks for doing all good work. Keep it up and keep posting more videos like this
@prernachauhan6262
@prernachauhan6262 4 года назад
Can we have multiple BFS and DFS ordering possible? Unlike trees, in BFS here I can choose any child first, right?
@BackToBackSWE
@BackToBackSWE 4 года назад
Yes
@sravanchittupalli9364
@sravanchittupalli9364 3 года назад
Did I understand BFS and DFS in 15min?....Hellll yes 🔥🔥
Далее
When Goalkeepers Get Bored 🤯 #3
00:27
Просмотров 1,7 млн
Сколько стоит ПП?
00:57
Просмотров 145 тыс.
Peter Hitchens in heated clash over Israel's war
11:33
Breadth First Search (BFS): Visualized and Explained
10:41
Depth-first search in 4 minutes
4:01
Просмотров 259 тыс.