Breadth First Search (BFS): Visualized and Explained

Sdílet
Vložit
  • čas přidán 12. 06. 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

Komentáře • 135

  • @Reducible
    @Reducible  Před 3 lety +105

    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 Před 3 lety +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 Před 3 lety

      Please make more videos ,really great channel and content

    • @wokguysrandomstuff5535
      @wokguysrandomstuff5535 Před 3 lety +1

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

    • @ultramasculine
      @ultramasculine Před 3 lety +1

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

    • @susantabasak1327
      @susantabasak1327 Před 2 lety

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

  • @masonbiddle6750
    @masonbiddle6750 Před 3 lety +229

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

    • @andrewprahst2529
      @andrewprahst2529 Před 3 lety +1

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

    • @Mayank-mf7xr
      @Mayank-mf7xr Před 2 lety +1

      He is the 3b1b of Computer Science.

    • @saivenkatrapol6462
      @saivenkatrapol6462 Před 8 měsíci

      heyyy a 3blue1brown fan.. hard to come by

    • @ParthPaTeL-wm3kt
      @ParthPaTeL-wm3kt Před 5 měsíci

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

  • @maxwellhunt3732
    @maxwellhunt3732 Před 3 lety +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  Před 3 lety +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 Před 2 lety +1

      Same , do you do competitive programming too?

    • @maxwellhunt3732
      @maxwellhunt3732 Před 2 lety +1

      @@AkshatSinghania yep!

  • @udaraabeyrathne7167
    @udaraabeyrathne7167 Před 2 lety +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.

  • @jarmanbrar4114
    @jarmanbrar4114 Před 3 lety +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.

  • @xaceffulgent
    @xaceffulgent Před 8 měsíci +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!!

  • @MattCM89
    @MattCM89 Před 4 měsíci +2

    Hands down best vidoe on youtube for learning this!

  • @yixe2253
    @yixe2253 Před 3 lety +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  Před 3 lety +4

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

    • @filipm133
      @filipm133 Před rokem

      @@Reducible he was right, great content

  • @srujanjoshi3780
    @srujanjoshi3780 Před 3 lety +2

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

  • @wlockuz4467
    @wlockuz4467 Před 2 lety +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.

  • @aaroncroft7514
    @aaroncroft7514 Před rokem

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

  • @thiagovicentini6366
    @thiagovicentini6366 Před 3 lety +1

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

  • @hasnat_malik
    @hasnat_malik Před 3 lety +5

    your way of teaching is absolutely amazing

  • @hamzakhalid4311
    @hamzakhalid4311 Před 3 lety +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.

  • @liuculiu8366
    @liuculiu8366 Před 3 lety

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

  • @jamesmcgreivy2882
    @jamesmcgreivy2882 Před 3 lety +2

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

  • @ktuluchou8050
    @ktuluchou8050 Před 2 lety

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

  • @sivsivsree
    @sivsivsree Před 3 lety +4

    This channel is a gold mine!

  • @kyoungjunhan1098
    @kyoungjunhan1098 Před 2 lety

    @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 :)

  • @mandelbrot3162
    @mandelbrot3162 Před 3 lety +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!

  • @orion2843
    @orion2843 Před 3 lety

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

  • @VladyYakovenko
    @VladyYakovenko Před 2 lety

    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

  • @yatharthmishra01
    @yatharthmishra01 Před 2 lety

    Beautifully explained ! Keep up the good work.

  • @mayankmudgal1728
    @mayankmudgal1728 Před rokem

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

  • @rtcwtwister
    @rtcwtwister Před 3 lety

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

  • @AshishKumar-xx3dx
    @AshishKumar-xx3dx Před 3 lety

    Again an awesome explanation by Reducible

  • @manupratap6406
    @manupratap6406 Před 3 lety

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

  • @dnm9931
    @dnm9931 Před rokem

    Beautiful and clear explanation! Thank you so much!

  • @alexbrodbelt297
    @alexbrodbelt297 Před 3 lety +1

    This is incredible, I cannot thank you enough!

  • @shanehowe2751
    @shanehowe2751 Před rokem

    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

  • @thequantartist
    @thequantartist Před 3 lety

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

  • @alex19991014
    @alex19991014 Před rokem

    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.

  • @user-wc1sm8cj8s
    @user-wc1sm8cj8s Před 3 lety +1

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

  • @henrroo
    @henrroo Před 2 lety

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

  • @matiaslast2100
    @matiaslast2100 Před 3 lety +1

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

    • @lefuturiste27
      @lefuturiste27 Před 3 lety

      lol that was python, great to do pseudocode I guess

  • @erv993
    @erv993 Před 3 lety

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

  • @mohdrasid6737
    @mohdrasid6737 Před 3 lety

    such a clear and detailed explanation 👏. Thank you 😇

  • @lastshots300
    @lastshots300 Před 2 lety

    absolutely loving your content - great stuff

  • @emre5740
    @emre5740 Před 2 lety

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

  • @vikasviki7490
    @vikasviki7490 Před 3 lety +1

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

  • @ParthVerma-kc1wr
    @ParthVerma-kc1wr Před 10 měsíci

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

  • @user-hy8rg4lt4p
    @user-hy8rg4lt4p Před 3 lety

    This video is absolutely amazing!! Thank you!!

  • @rubamushtaq1657
    @rubamushtaq1657 Před 2 lety

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

  • @ahmedouerfelli4709
    @ahmedouerfelli4709 Před 3 lety +3

    You deserve much more subscribers.

  • @kobic8
    @kobic8 Před 2 lety

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

  • @marioprado8789
    @marioprado8789 Před 11 měsíci

    That level explanation. Awesome!

  • @1mr12
    @1mr12 Před 24 dny

    that was eazy, simple, adorable !

  • @robtito2009
    @robtito2009 Před 3 lety

    You guys deserve so much more subscribers

  • @arekysa
    @arekysa Před 3 lety

    This channel is so much underrated

  • @Jbdoster
    @Jbdoster Před rokem

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

  • @monickverma2944
    @monickverma2944 Před 3 lety

    this is the best. i beg u not to stop

  • @yeah5037
    @yeah5037 Před rokem +1

    Very nice video, thank you!

  • @user-rt2br5ox5d
    @user-rt2br5ox5d Před rokem

    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.

  • @petesantago5977
    @petesantago5977 Před 2 lety

    Excellent content - thank you.

  • @dipankarkumarsingh
    @dipankarkumarsingh Před 2 lety

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

  • @hasnat_malik
    @hasnat_malik Před 3 lety

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

  • @navneet5084
    @navneet5084 Před 3 lety

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

  • @huseinjavidmehr1228
    @huseinjavidmehr1228 Před rokem

    was fluent explanation thank you

  • @zhougood8998
    @zhougood8998 Před 3 lety +2

    it helps me a lot!!!

  • @BerArchegas
    @BerArchegas Před 3 lety

    Amazing vid, amazing channel

  • @SomebodyYouUsedToSee
    @SomebodyYouUsedToSee Před 3 lety

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

  • @essamgouda1609
    @essamgouda1609 Před 2 lety

    CZcams is indeed full of gems.

  • @KumarDinesh-zw2vq
    @KumarDinesh-zw2vq Před měsícem

    Wow man. Love you

  • @mohamedmoumni8916
    @mohamedmoumni8916 Před 2 lety

    great Job , Thanks A lot.

  • @carljustinemosquida4727

    hope more graphs algos in the future

  • @Saleh-le2zf
    @Saleh-le2zf Před 3 lety

    I still love you man!

  • @brendawilliams8062
    @brendawilliams8062 Před 3 lety +1

    Thankyou.

  • @nihao852
    @nihao852 Před měsícem

    legend

  • @handlebred
    @handlebred Před 8 měsíci

    very good vide;)

  • @Speykious
    @Speykious Před 3 lety +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

  • @TheStylestatement
    @TheStylestatement Před rokem

    Best one

  • @ullaskunder
    @ullaskunder Před 3 lety

    Perfect

  • @marco_gallone
    @marco_gallone Před 3 lety +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  Před 3 lety +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

  • @stevenperez5260
    @stevenperez5260 Před 2 lety

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

  • @ananyapamde4514
    @ananyapamde4514 Před 3 lety

    Gold

  • @rhaq426
    @rhaq426 Před rokem

    cool intro

  • @kautilyap9856
    @kautilyap9856 Před 3 lety +8

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

    • @Reducible
      @Reducible  Před 3 lety +31

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

    • @kautilyap9856
      @kautilyap9856 Před 3 lety +1

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

  • @riyadh5449
    @riyadh5449 Před rokem

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

  • @justinrush6620
    @justinrush6620 Před 3 lety

    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 Před 2 lety

    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])

  • @gamerkaue88
    @gamerkaue88 Před 3 lety

    Here before 1k views.

  • @m0lecules
    @m0lecules Před 6 měsíci

    👍

  • @theunknown4834
    @theunknown4834 Před 3 lety

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

  • @patriot925th
    @patriot925th Před měsícem

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

  • @andrewprahst2529
    @andrewprahst2529 Před 3 lety

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

  • @silviuvaipan7850
    @silviuvaipan7850 Před rokem

  • @brendawilliams8062
    @brendawilliams8062 Před 2 lety +1

    When you have shoe laces and need to tie them

  • @godwinwabz5379
    @godwinwabz5379 Před rokem

    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

  • @ingenia-tec5194
    @ingenia-tec5194 Před 2 lety

    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 Před 2 lety

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

  • @michaelheuss6502
    @michaelheuss6502 Před 2 lety

    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.

  • @watchlistsclips3196
    @watchlistsclips3196 Před 3 lety +1

    Can anyone send me this grid problem code in cpp

  • @orion2843
    @orion2843 Před 3 lety

    Btw Do you also you Manim Library of Python?

  • @jackabrams5859
    @jackabrams5859 Před 3 lety

    thumbnail looks like the reverse transmutation circle from FMAB

  • @AjithKumaR-jw9wt
    @AjithKumaR-jw9wt Před 2 lety

    0:14

  • @tedarcher9120
    @tedarcher9120 Před 3 lety

    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)]

  • @personaladdress3539
    @personaladdress3539 Před rokem

    this is the island problem right ??

  • @nurhusni
    @nurhusni Před 3 lety +1

    Is this channel related to 3blue1brown?

    • @Reducible
      @Reducible  Před 3 lety +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 Před 3 lety

      @@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 Před měsícem

    B - Boss
    F - Fighting
    S - Stages

  • @davidequattrocchi5083
    @davidequattrocchi5083 Před 2 lety

    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.