Breadth First Search (BFS): Visualized and Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 พ.ค. 2024
  • In this video we break down the BFS algorithm in a visual manner with examples and key intuition. We then show the implementation of the algorithm with code and then finish off the video by demonstrating how you can use the BFS algorithm to solve the Flood Fill problem.
    0:00 Introduction
    0:45 BFS Intuition/Examples
    2:39 BFS Implementation
    5:19 Flood Fill Problem
    Support: / reducible
    This video wouldn't be possible without the open source manim library created by 3blue1brown: github.com/3b1b/manim
    Here is link to the repository that contains the code used to generate the animations in this video: github.com/nipunramk/Reducible
    Music:
    Lift Motif by Kevin MacLeod is licensed under a Creative Commons Attribution license (creativecommons.org/licenses/...)
    Source: incompetech.com/music/royalty-...
    Artist: incompetech.com/
    All other music by Aakash Gandhi

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

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

    Hey everyone, quick channel update: this channel recently hit 1K subscribers! Thank you all for your support and kind comments on all my videos. I got a lot of ideas for interesting content in future videos so stay tuned (hit that subscribe button)! As always, thanks for watching!

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

      really good content, would you consider making a video about A* algorithm and topological sort, also maybe some data structure like red/black tree, segment tree, I'd be watching them!

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

      Please make more videos ,really great channel and content

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

      What? 6 month ago you had only 1k subs? Unbelievable

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

      please, do more videos. it's much more interestring than reading books

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

      We certainly need more videos from you on the topic (GRAPH)

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

    Love the 3blue1brown vibes. This is the best way to learn for me and you do a great job explaining everything.

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

      Nice profile picture.
      I do wonder what the software is though

    • @Mayank-mf7xr
      @Mayank-mf7xr 2 ปีที่แล้ว +1

      He is the 3b1b of Computer Science.

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

      heyyy a 3blue1brown fan.. hard to come by

    • @ParthPaTeL-wm3kt
      @ParthPaTeL-wm3kt 4 หลายเดือนก่อน

      @@andrewprahst2529 The animation is made through python manim library created by 3b1b

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

    This is amazing content! I'm a high school student who loves computer science, and this is just amazing. I know a lot of effort must have gone into these videos (what with having to learn manim and everything), I hope you continue into the future

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

      Thanks for the awesome comment! And yeah, these videos do take a lot of time and effort, but it's a lot of fun for me so I plan on continuing for the foreseeable future!

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

      Same , do you do competitive programming too?

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

      @@AkshatSinghania yep!

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

    I must say, this is one of the most effectively explained videos for DS & Alogs. Even though video is around 10.40 minutes, it's well ordered, planed and well explained to the point. Recommend this channel to anybody, who is looking for a quick but more elaborated explanations on Data Structures and Algorithms.

  • @xaceffulgent
    @xaceffulgent 7 หลายเดือนก่อน +1

    I finally understand BFS!! THANK YOU SO MUCH. That ball and string intuition piece made my mouth drop. And I finally truly understand a flooding algorithm - how why and when to use it. THANK YOU!!

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

    Another highly polished video. You deserve so much more subscribers (sickening to see only 1k subscribers for such high quaility content). You are 3Blue1Brown
    of computer science for me and hopefully you get millions of subscribers like him.

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

    Hands down best vidoe on youtube for learning this!

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

    Your graph theory series is amazing, I wish there was more to this series with more advanced topics! only thing I would like to point out is that you can mark vertexes as visited right after pushing them to stack/queue, Because you can be certain that if a vertex is in the stack/queue it is waiting to be visited , this avoids unnecessary insert/remove operations on stack/queue.

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

    I wish if you were my DSA lecturer, just came across you channel I wish if i knew your channel a year ago. Keep making these high standard videos. Would love to see a whole series about Data Structures and Algorithms.

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

    The ball and string analogy alone was enough to get me to like the video :D

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

    The work you are doing here is fantastic, hope all the best for you man, thanks a lot

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

    Such well organized content and finely polished presentation. Instantly subscribed. Appreciate the effort!

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

    BEST CODING VIDEO I HAVE EVER WATCHED! So elegantly explained, thanks so much!!! 🙏🏻

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

    This channel is a gold mine!

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

    this is amazing, thank you for making them. These videos are timeless, people will be coming back to them in 2 years

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

      Glad you enjoyed it -- thanks for the awesome comment.

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

      @@Reducible he was right, great content

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

    @2:39
    So so so so so so so helpful to actually have a visualized explanation of the implementation of the codes!!
    Thank you so much!! You are absolutely brilliant :)

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

    The flood fill problem is a great example for the use of graph traversal algorithms! Definitly going to show it to my students.

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

    Love these videos! Really interesting topics and they’re super easy to follow

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

    This is incredible, I cannot thank you enough!

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

    Absolutely stunning! Love the animations and the intuitive vibe just like 3b1b;

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

    I love the music, so relieving, make me concentrate on what you are talking about.

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

    I really do appreciate your graph theory videos they are really clear and I love the way you are making me think about the problems and solutions. Please make more videos about graph theory and maybe showing some examples of problems solved with graph theory

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

    your way of teaching is absolutely amazing

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

      Glad you enjoyed it!

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

    Beautiful and clear explanation! Thank you so much!

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

    Excellent explanation and example. Love it when you mention the real life example of the “Fill” button in Paint🎨 app, it gave me a instant picture of BFS.

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

    Beautifully explained ! Keep up the good work.

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

    Thankyou so much for this video!! This is awesome. Today my DS teacher gave me the same problem and voila! I got you.Thanks✌🏼, You cleared my confusion!

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

    Oh yeah
    This is definitely the one
    It’s been years since my undergrad and this helped me review thank you so much

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

    I am addicted to such content. Plz if someone else also creates such content pl tell.
    Ur videos make maths so beautiful. Hats off👏👏

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

    The quality of this channel is incredible. 3blue1brown level.

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

    Amazing Content Sir,like no one else in Computer Science Domain. Really Appreciate you animation,background music and hardwork you put in every video❤️😁❤️

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

    Just want to say this is a fantastic explanation!! I am taking cs50ai and the first problem is the use BFS to find the shortest path between two actors and I just solved it thanks to this video

  • @AshishKumar-xx3dx
    @AshishKumar-xx3dx 3 ปีที่แล้ว

    Again an awesome explanation by Reducible

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

    such a clear and detailed explanation 👏. Thank you 😇

  • @marioprado8789
    @marioprado8789 10 หลายเดือนก่อน

    That level explanation. Awesome!

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

    absolutely loving your content - great stuff

  • @user-wc1sm8cj8s
    @user-wc1sm8cj8s 3 ปีที่แล้ว +1

    really great contents, I really understand a lot from your videos!
    *Keep it up*

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

    That's a great efford! I wish I discovered this channel earlier. Thanks

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

    Your explanation was so good, thank you very much, keep doing these kind of videos bro!

  • @user-hy8rg4lt4p
    @user-hy8rg4lt4p 2 ปีที่แล้ว

    This video is absolutely amazing!! Thank you!!

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

    this is awesome man! it has a clear explanation with pseudocode easy enough to understand and make an implementation thanks!!

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

      lol that was python, great to do pseudocode I guess

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

    Awesome Content, Please add more such videos, Graph and DP would be Awesome.

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

    amazing!!! helped me a lot, as a junior that is just introduced to this topic

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

    You deserve much more subscribers.

  • @ParthVerma-kc1wr
    @ParthVerma-kc1wr 9 หลายเดือนก่อน

    This was so insanely good! Although I watched the video a few times. I could understand everything!!

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

    Wow, that's a very cool explanation! I think I understand it much better now, thx!

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

    this is the best. i beg u not to stop

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

    This channel is so much underrated

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

    This problem seems like a building block to solve graph problems. Thank you for sharing this.

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

    You guys deserve so much more subscribers

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

    Excellent content - thank you.

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

    Very nice video, thank you!

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

    I might have been traversing the internet the DFS way, that's why I found your channel so late!

  • @user-rt2br5ox5d
    @user-rt2br5ox5d 11 หลายเดือนก่อน

    Absolutely amazing. Please make as many videos as you possibly can on graph theory. I'd buy a complete DSA course from you if you choose to make one.

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

    Please please please keep uploading videos ... they are soooooooo good .....

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

    it helps me a lot!!!

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

    Bro , You are just tooooooooooooo good , please make more algorithm videos

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

    was fluent explanation thank you

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

    man i'm new to the channel and am lovin it

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

    very good vide;)

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

    Amazing vid, amazing channel

  • @KumarDinesh-zw2vq
    @KumarDinesh-zw2vq วันที่ผ่านมา

    Wow man. Love you

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

    great Job , Thanks A lot.

  • @Saleh-le2zf
    @Saleh-le2zf 3 ปีที่แล้ว

    I still love you man!

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

    TH-cam is indeed full of gems.

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

    Thankyou.

  • @nihao852
    @nihao852 13 วันที่ผ่านมา

    legend

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

    Perfect

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

    hope more graphs algos in the future

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

    Best one

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

    I just watched this video after I intuitively found by myself an algorithm to capture a group of stones in a GO game setup

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

    I recognize that the only difference in the two algorithms (BFS vs DFS) is that BFS uses a queue vs DFS uses a stack. But you presented a really clean algorithm using recursion in DFS. Can BFS be reduced down to a recursive form too?

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

      Well, it's always possible, but it really doesn't make sense to use recursion since DFS recursion is just using the call stack. Recursion implicitly uses a stack. BFS uses a queue which is basically the opposite of the stack so it really doesn't fit the recursive framework. See this for a more thorough discussion and some of the possible ways: stackoverflow.com/questions/2549541/performing-breadth-first-search-recursively

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

    Curious why you didn't just use a min/max function with neighbors to avoid boundary issues? Wouldn't that be a simpler implementation?

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

    i wish i watch this video before I build my minesweeper game if so I wouldn’t have a hard time figuring out flood fill on my own
    btw I think the isValid function can be write like this
    def isValid(img, row, col):
    return row in range(len(img)) and col in range(len(img[0])

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

    cool intro

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

    Can you please develop a course comprising on data structures, algorithms and problem solving paradigms??

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

      Or ... I could just make a course equivalent series of videos on TH-cam for free :P

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

      @@Reducible Yeah you can! That would be the best thing! But like can you do them simultaneously and in one video

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

    I was wondering to know what software did you use for the graph animations?

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

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

    Gold

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

    Here before 1k views.

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

    When you have shoe laces and need to tie them

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

    Hello.... Thanks for creating your content.. however, I realized that in your animation, while visiting vertex 3, you added 2 to the queue.
    However, 2 is adjacent to vertex 0, therefore, it would be visited at the same level with vertices 1, and 3. Therefore, adding it into the queue would result into revisiting of the vertex, which isn't efficient

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

    Is this better with sets for v instead of a list?

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

    Wow, how lovely you accent is😇.. damn to Hindi accent!

  • @patriot925th
    @patriot925th 23 วันที่ผ่านมา

    around 6:30, you said (row, col): (2,2). but it seems like (3,3). what am I missing here?

  • @ingenia-tec5194
    @ingenia-tec5194 2 ปีที่แล้ว

    Hi :D
    Thanks for the video :D
    How can we use the BFS implementation focused to Objects in Python? The Atributes of the Objects needs to indicate the neighbors that the object have ? :O
    Its really interesting :D How do u use this algoritms in a programing language ? :D
    Thanks a lot :D

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

    9:32 havent you alredy changed the value of the of the starting pixel, and later pixels wont match it?

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

    I'm just here because I really like lines and stuff

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

    👍

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

    It's been a long time since I took algorithms, but I think we skipped BFS in general and went straight to Dijkstra's algorithm.

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

    Btw Do you also you Manim Library of Python?

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

    Can anyone send me this grid problem code in cpp

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

    thumbnail looks like the reverse transmutation circle from FMAB

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

    this is the island problem right ??

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

    If you code in Python, never initialise a list as [something]*N, because it will create a list with N the same objects, which will break your program. Instead, use [False for _ in range(N)]

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

    Is this channel related to 3blue1brown?

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

      Directly, no. I love his work and I think his channel is one of the best educational channels out there. I use the same animation library he uses so I guess the content will have a similar style in that sense.

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

      @@Reducible please can you make a documentation of manim? it is very difficult to work with it .
      Can you tell how do I label points marked on a 2d graph.

  • @Tainted-Azazel
    @Tainted-Azazel 22 วันที่ผ่านมา

    B - Boss
    F - Fighting
    S - Stages

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

    I've been using variants of this algorithm for years. I never thought I had invented it first... but knowing it for sure is still somewhat disappointing.

  • @AjithKumaR-jw9wt
    @AjithKumaR-jw9wt ปีที่แล้ว

    0:14

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

    can you make more leetcode solution videos please?