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

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ธ.ค. 2018
  • Free 5-Day Mini-Course: backtobackswe.com
    Try Our Full Platform: backtobackswe.com/pricing
    📹 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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 448

  • @BackToBackSWE
    @BackToBackSWE  5 ปีที่แล้ว +52

    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.

  • @taiwan.1
    @taiwan.1 4 ปีที่แล้ว +262

    You deserve an Academy Award for all these videos you have made.

    • @BackToBackSWE
      @BackToBackSWE  4 ปีที่แล้ว +4

      hahahahahaha

    • @mujtabaarfat717
      @mujtabaarfat717 3 ปีที่แล้ว +1

      He did absolutely nothing . U were too lazy to understand it on ur own .

    • @yutaitadori7318
      @yutaitadori7318 2 ปีที่แล้ว +6

      @@mujtabaarfat717 😐

    • @ashwinpande7095
      @ashwinpande7095 2 ปีที่แล้ว +13

      @@mujtabaarfat717 damn bro who hurt u

    • @tachylamurray9452
      @tachylamurray9452 ปีที่แล้ว

      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!

  • @pranitachikorde603
    @pranitachikorde603 ปีที่แล้ว +6

    This guy can explain rocket science to a baby, in-depth knowledge with crystal clarity

  • @reedmurphy3073
    @reedmurphy3073 ปีที่แล้ว +8

    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!

  • @AdityaMishra-ve6yu
    @AdityaMishra-ve6yu 4 ปีที่แล้ว +63

    This channel is surely one of my favourite on programming.The way he explains is breathtaking.He is breathtaking.😊

    • @BackToBackSWE
      @BackToBackSWE  4 ปีที่แล้ว +16

      ur my favorite

    • @anarbay24
      @anarbay24 3 ปีที่แล้ว +4

      You are breathtaking! You are all breathtaking!

    • @jfklittle
      @jfklittle 3 ปีที่แล้ว

      @@anarbay24 Wake the f*ck up samurai! We have a city to burn!

  • @mouseclicker4955
    @mouseclicker4955 2 ปีที่แล้ว +1

    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.

  • @chrisbaca3997
    @chrisbaca3997 3 ปีที่แล้ว

    Out of all the videos I watch on these topics you make it seem very clear.
    Now you gave me confidence to finally solve this stuff.
    Thanks!

  • @milanpatel6240
    @milanpatel6240 3 ปีที่แล้ว +1

    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

  • @joy-sm5sl
    @joy-sm5sl 2 ปีที่แล้ว +4

    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! 🔥

  • @Labattfartoui
    @Labattfartoui 3 ปีที่แล้ว +5

    Why can't I have this much energy and clarity at 7am??? Great explanations. Thank u.

    • @BackToBackSWE
      @BackToBackSWE  3 ปีที่แล้ว +1

      lol I was a rabid lion back in the day with no mic equipment

  • @_janol
    @_janol 5 ปีที่แล้ว +26

    Great job done, after your explanation I finally understand everything. Keep on doing good work!

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว +2

      That is the goal. Keep flourishing.

  • @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!!

  • @metarun
    @metarun 3 ปีที่แล้ว

    Man you are awesome. Love the energy more than anything. You could find a hundred videos on DFS and BFS but you cant find the energy. Cheers.

  • @cambeeler6374
    @cambeeler6374 4 ปีที่แล้ว +1

    Can't wait to see your other videos on BFS & DFS and practically how they are leveraged. I really "get you" and your way of explaining. Thank you!!

    • @BackToBackSWE
      @BackToBackSWE  4 ปีที่แล้ว +1

      nice ha, if you like this join our class, I'm posting videos there as "the new TH-cam" channel

  • @adamlee5620
    @adamlee5620 2 ปีที่แล้ว

    This is one of the most intuitive explanations of DFS/BFS!!

  • @DowryGoat
    @DowryGoat 3 ปีที่แล้ว

    Hey, this explanation is freaking baller. I've been working as a SWE for a couple years but forgot a few of the basics. Switching jobs right now and while I study this has been clutch. Still struggling to get DFS recursively. But the stack way is foolproof right now!
    Thanks dude!

  • @alanwang6563
    @alanwang6563 4 ปีที่แล้ว +5

    You are extremely good at explaining things! Most of the DFS&BFS tutorial video on TH-cam 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.

  • @nicholascastro4175
    @nicholascastro4175 5 ปีที่แล้ว +4

    Got an interview next week. Just what I needed! Good stuff, guys

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว +3

      it is just Ben now (this is Ben) and good luck!

  • @metehanemir7454
    @metehanemir7454 3 ปีที่แล้ว +2

    You are so good and enthusiastic at explaining, I never get bored learning something from you. Real good!

  • @Anna-cl4rj
    @Anna-cl4rj 3 ปีที่แล้ว +1

    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.

  • @AH-xb7eb
    @AH-xb7eb 3 ปีที่แล้ว +27

    Got a google internship interview coming up, hope these vids help. You're a legend man

    • @BackToBackSWE
      @BackToBackSWE  3 ปีที่แล้ว +5

      ok - let us know if u get ti

    • @II_xD_II
      @II_xD_II 3 ปีที่แล้ว +1

      practising on cf will help more

    • @AH-xb7eb
      @AH-xb7eb 3 ปีที่แล้ว +7

      @@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 ปีที่แล้ว +1

      @@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.

  • @abdulmalikquadri7604
    @abdulmalikquadri7604 2 ปีที่แล้ว

    You just helped me write a 7 page document on depth first search and how it applies to a maze, I cannot thank you enough.

  • @DaggerMan11
    @DaggerMan11 3 ปีที่แล้ว

    you have a real gift for CS and for teaching, my man

  • @hoangvietng7100
    @hoangvietng7100 4 หลายเดือนก่อน

    Brilliant explanation! Thanks for your energetic effort, I love it.

  • @andrews2945
    @andrews2945 4 ปีที่แล้ว +1

    Great explanation! It's such a relief to finally find a video of someone I can actually understand.

  • @etimezz
    @etimezz 2 ปีที่แล้ว

    your channel is really helping me with my university data structures course!

  • @Canonall
    @Canonall 4 ปีที่แล้ว +4

    This channel is so underrated! Thanks so much for this!

  • @mallikarjunpidaparthi
    @mallikarjunpidaparthi 3 ปีที่แล้ว +2

    Wow! All my doubts are now gone after seeing this video... Thank you so much brother

  • @DanielDiaz-rq3ko
    @DanielDiaz-rq3ko 8 หลายเดือนก่อน +1

    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.

  • @AaronMOliver
    @AaronMOliver ปีที่แล้ว

    This is the best video on the topic I’ve ever seen, thank you so much for this!

  • @PorterRockwellsMyGrandpa
    @PorterRockwellsMyGrandpa ปีที่แล้ว +3

    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  ปีที่แล้ว +1

      Really glad to help 🎉 Do you know about our 5-Day Free DSA Mini Course? Check it out here - backtobackswe.com/

  • @RajSehmi5293
    @RajSehmi5293 2 ปีที่แล้ว

    Not all heros wear cape. This guy is JUST AMAZING.. He is a REAL HERO..!!
    Word out there needs to know about this guy.

  • @shivarammuthukumaraswamy7164
    @shivarammuthukumaraswamy7164 3 ปีที่แล้ว +1

    Thanks for taking your time to do this.Really appreciate it.

  • @johndubchak
    @johndubchak 4 ปีที่แล้ว +2

    This is some fantastic instruction, my friend. I look forward to more.

  • @sercan272727
    @sercan272727 3 ปีที่แล้ว

    appreciate the content man , its pretty clear explanation, keep it up !

  • @AvivaScott
    @AvivaScott 2 ปีที่แล้ว +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 😀

  • @mr_lamintun
    @mr_lamintun 2 ปีที่แล้ว

    Thanks a lot for the very clear explanation. Keep up the great work.

  • @nikoinfanto729
    @nikoinfanto729 4 ปีที่แล้ว +1

    Just what I was looking for! Clear and concise!!

  • @shreeshsrivastava3614
    @shreeshsrivastava3614 5 หลายเดือนก่อน

    Yo, you explained so clearly. Thank you!

  • @CuriousWithOscar
    @CuriousWithOscar 4 ปีที่แล้ว +2

    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 ปีที่แล้ว +2

      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.

  • @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/ 🎉

  • @historian2
    @historian2 2 ปีที่แล้ว +1

    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!

  • @lciduhtak4278
    @lciduhtak4278 ปีที่แล้ว

    Iam knowing the real problem I had in DFS , but now I knew it perfectly .. amazing 👍🏿

  • @amiraghdam
    @amiraghdam 3 ปีที่แล้ว

    Thanks for the great tips provided! Helped me a lot :)

  • @iliatadzhibaev3573
    @iliatadzhibaev3573 4 ปีที่แล้ว +1

    The best explanation ever! Thank you so much!

  • @gabrielabezerra3434
    @gabrielabezerra3434 3 ปีที่แล้ว +2

    THANK YOU! Great channel you got there! Keep up the good work

  • @qingtianwang3511
    @qingtianwang3511 3 ปีที่แล้ว +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.

  • @nofaldiatmam8905
    @nofaldiatmam8905 3 ปีที่แล้ว

    you are way better than my professor explaining this at uni, thanks mate !

  • @sidagarwal43
    @sidagarwal43 3 ปีที่แล้ว +3

    Beautiful explanation, cleared all my doubts,. Thanks man

  • @andrewsistek7600
    @andrewsistek7600 ปีที่แล้ว

    this helped me out tremendously. Thanks for the clear explanation!!

    • @BackToBackSWE
      @BackToBackSWE  ปีที่แล้ว

      Glad it helped 😄 We'd love for you to check out our Free 5 Day DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉

  • @sudeepwegapitiya2157
    @sudeepwegapitiya2157 2 ปีที่แล้ว

    Great! Clearly explain everything. Thank you !

  • @benoitpoux6241
    @benoitpoux6241 3 ปีที่แล้ว +1

    Great explanations, so easy to implement after seing this.
    Thanks a lot from France !

  • @shishirpai380
    @shishirpai380 ปีที่แล้ว

    Thank you for easily and effectively explaining this topic in a concise manner!

    • @BackToBackSWE
      @BackToBackSWE  ปีที่แล้ว

      Happy Holidays! Really glad to help 🎉 Do you know about the 5 Day Free Mini Course? Check it out here - backtobackswe.com/

  • @sravanchittupalli9364
    @sravanchittupalli9364 2 ปีที่แล้ว

    Did I understand BFS and DFS in 15min?....Hellll yes 🔥🔥

  • @yuezhang604
    @yuezhang604 5 ปีที่แล้ว +2

    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 ปีที่แล้ว +2

      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."

  • @DavidEspinosa21
    @DavidEspinosa21 3 ปีที่แล้ว +1

    Love your videos. Super useful and really articulate, thanks!

  • @MoSweiti666
    @MoSweiti666 4 ปีที่แล้ว +1

    One minute in , I clicked the subscribe button!
    Thanks man!!

  • @fantasy9960
    @fantasy9960 ปีที่แล้ว

    wow thank you! You explained the concepts so well and clearly!

  • @jobomathaha7420
    @jobomathaha7420 ปีที่แล้ว

    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

  • @mardokaymosazghi1296
    @mardokaymosazghi1296 5 ปีที่แล้ว +2

    Nice Explanation as always!

  • @alex-pictures
    @alex-pictures ปีที่แล้ว

    Great explanation, this was very clear ! thanks for the help

  • @johnnymeza5454
    @johnnymeza5454 4 ปีที่แล้ว +5

    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.

  • @Series0Tubes
    @Series0Tubes 3 ปีที่แล้ว +1

    Thank you for making this video!

  • @shilpag08
    @shilpag08 3 ปีที่แล้ว +1

    By far the best explanation! Thanks

  • @venkatachengalvala4289
    @venkatachengalvala4289 3 ปีที่แล้ว +3

    Minor mistakes but well-explained and really enthusiastic! :)

  • @JacobCritch
    @JacobCritch 4 ปีที่แล้ว +1

    Incredible explanation. Very passionate 👍. Needed a refresher on this before Amazon interview.

    • @BackToBackSWE
      @BackToBackSWE  4 ปีที่แล้ว

      nice

    • @JacobCritch
      @JacobCritch 4 ปีที่แล้ว

      @@BackToBackSWE Failed cause they asked me binary search 😂😂

  • @Iam_number_one
    @Iam_number_one 2 หลายเดือนก่อน

    thank you so much ; you're the man .

  • @khaledrefai8120
    @khaledrefai8120 4 ปีที่แล้ว +1

    Simple and easy to understand , Thank you very much

  • @kunalgulati6994
    @kunalgulati6994 3 ปีที่แล้ว +1

    This video is truly a blessing

  • @superchillh3o
    @superchillh3o 5 ปีที่แล้ว +1

    You are an excellent teacher, thank you

  • @easifier
    @easifier 2 ปีที่แล้ว +1

    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/

  • @azzzydzz
    @azzzydzz 3 ปีที่แล้ว

    Legend man! thanks!

  • @chtruckerhat
    @chtruckerhat 3 ปีที่แล้ว +1

    youre actually such a good teacher man

  • @FitCoder
    @FitCoder 3 ปีที่แล้ว +2

    Explained in a very simple manner.

  • @chughgaurav
    @chughgaurav 3 ปีที่แล้ว

    Amazing explanation :)

  • @sgbalakrishna
    @sgbalakrishna 2 ปีที่แล้ว

    Thank you so much you teach really well!

  • @AkamiTenzuo
    @AkamiTenzuo ปีที่แล้ว

    Best explanation ever!

  • @ghazalsahebzamani4925
    @ghazalsahebzamani4925 4 ปีที่แล้ว +1

    Very helpful!Thank you very much!!

  • @sumansantra777
    @sumansantra777 3 ปีที่แล้ว +1

    Thank you a lot Dude for helping backbenchers like me. :)

  • @supamdeepbains5172
    @supamdeepbains5172 4 ปีที่แล้ว +1

    You're videos are really helpful

  • @TheA7xaddicted
    @TheA7xaddicted 3 ปีที่แล้ว

    you just saved my degree man :') bless

  • @zzzz26526
    @zzzz26526 3 ปีที่แล้ว +1

    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.?

  • @kennethochieng37
    @kennethochieng37 4 ปีที่แล้ว +1

    You are a talented teacher!

  • @jagicyooo2007
    @jagicyooo2007 3 ปีที่แล้ว +1

    Goes deep and comes back out!

  • @deanhunter6304
    @deanhunter6304 3 ปีที่แล้ว +1

    Amazing explanation!

  • @shwetadk1986
    @shwetadk1986 5 ปีที่แล้ว +3

    Love your videos !. Hey can you please do a video on Course Schedule - Leetcode problem 207

    • @BackToBackSWE
      @BackToBackSWE  5 ปีที่แล้ว +3

      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.

  • @gyanprakash302
    @gyanprakash302 3 ปีที่แล้ว +1

    Damn Such A beautiful explanation. Thankyou. Love from INDIA.

  • @ZNhatAnhZ
    @ZNhatAnhZ ปีที่แล้ว

    really helpful man!!

  • @jordanrectan4793
    @jordanrectan4793 2 ปีที่แล้ว

    14:59 that is what she said!
    great video, thanks a bunch!!

  • @fuckooo
    @fuckooo 3 ปีที่แล้ว +1

    Nice channel bro, subbed!

  • @purovenezolano14
    @purovenezolano14 3 ปีที่แล้ว +2

    Great stuff. Thanks!

  • @sarahebal4391
    @sarahebal4391 7 หลายเดือนก่อน

    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

  • @vimalk2661
    @vimalk2661 4 ปีที่แล้ว +1

    If I need some explanation . I look for your videos man. That's the end point for me, I just get what I need.

  • @AbdoulieTamba
    @AbdoulieTamba 4 ปีที่แล้ว +3

    Glad to see another brotha doing this. Wish we had more of us in tech

  • @mibrahimdev
    @mibrahimdev 3 ปีที่แล้ว

    Give this man a Golden Teacher medal

  • @jit3191
    @jit3191 3 ปีที่แล้ว +1

    Great Explanation, will you be able to do a video on Topological Sort, please

    • @BackToBackSWE
      @BackToBackSWE  3 ปีที่แล้ว

      thanks and we have that on backtobackswe.com (paywall)

  • @grunze
    @grunze 4 ปีที่แล้ว +2

    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.

  • @charankumarr3506
    @charankumarr3506 4 ปีที่แล้ว

    Man u r underrated. U deserve more subs

    • @BackToBackSWE
      @BackToBackSWE  4 ปีที่แล้ว

      Nah I'm just normal and we will do fine

  • @pippoflow
    @pippoflow 2 ปีที่แล้ว

    In the DFS code, if a vertex has been seen and is being popped again, its adjacent vertices must have been seen already. So if that if condition in the middle doesn't hold (i.e. if seen contains current vertex), you should continue the loop right away.

  • @robertrey7002
    @robertrey7002 5 ปีที่แล้ว +1

    great stuff man