Breadth-first search in 4 minutes

Breadth-first search in 4 minutes.
Code: github.com/msambol/dsa/blob/m...
Sources:
1. Introduction To Algorithms, Third Edition (CLRS) [www.amazon.com/Introduction-A...]
2. en.wikipedia.org/wiki/Breadth...
LinkedIn: / michael-sambol

Пікірлер: 86

  • @MichaelSambol
    @MichaelSambol2 жыл бұрын

    After I made the video, I changed the code in GitHub to use a deque instead of an array for the queue. This allows us to pop the first element in 0(1) time. More here: wiki.python.org/moin/TimeComplexity.

  • @Ðogecoin

    @Ðogecoin

    Жыл бұрын

    Good video

  • @leonh2140
    @leonh2140 Жыл бұрын

    I love that your slides are so minimalistic, for me it's the perfect amount of content to support what you say

  • @adhoc3018
    @adhoc30182 жыл бұрын

    It's good to see that you are back. Your past videos have helped me a lot, thank you.

  • @Hydrus_
    @Hydrus_2 жыл бұрын

    I have an algorithm test coming up on graphs and this came out at exactly the right time! Thank you!!

  • @amaegbutah5957
    @amaegbutah59572 жыл бұрын

    You are literally saving my life! I’m so glad that you’re uploading again!!

  • @mey1823
    @mey18232 жыл бұрын

    Thank you for your quick illustrations! I enjoy your videos a lot.

  • @servantofthelord8147
    @servantofthelord81477 ай бұрын

    Wow, you've added so much value in such a short amount of time. Thank you sir!

  • @kevincaballero6133
    @kevincaballero6133 Жыл бұрын

    Great video. Makes the concept very easy to understand. Thank you for the way you made it.

  • @Cloydz
    @Cloydz2 жыл бұрын

    your videos keep me sane i swear

  • @dr.walidsoula
    @dr.walidsoula2 жыл бұрын

    You deserve more views, thank you for your videos

  • @JK-ls8kh
    @JK-ls8kh2 жыл бұрын

    you are literally helping me to survive my exam :) big thanks

  • @mihailtrajkoski1774
    @mihailtrajkoski17745 ай бұрын

    Damn because of your videos, I managed to prepare for the exam tomorrow. I had no idea how I was going to get through so much material in one day, thank you.

  • @guirck
    @guirck11 ай бұрын

    That is so concise! Perfectly explained!

  • @MichaelSambol

    @MichaelSambol

    11 ай бұрын

    thanks!

  • @anujain3350
    @anujain33506 күн бұрын

    such calm voice! Love it

  • @smikkelbeer7890
    @smikkelbeer7890 Жыл бұрын

    Clear and straight forward. Thank you.

  • @ezio9595
    @ezio9595 Жыл бұрын

    very useful and straight to the point, it was useful thanks!

  • @memeingthroughenglish7221
    @memeingthroughenglish7221Ай бұрын

    I love your videos so much! Great illustrations, great explanations, many topics, and I can learn something completely new in under 5 minutes!

  • @MichaelSambol

    @MichaelSambol

    Ай бұрын

    Thank you!

  • @anasalnablsi3623
    @anasalnablsi3623Ай бұрын

    honestly i understand it perfectly in that brief explanation many thanks to you

  • @brandoncazares8452
    @brandoncazares8452 Жыл бұрын

    Thanks, you literally saved my life.

  • @victorkoroshilov9015
    @victorkoroshilov90152 жыл бұрын

    This man does not miss 🔥

  • @RownitaTasneem-qf5sr
    @RownitaTasneem-qf5sr Жыл бұрын

    This video is well-explained.Thanks a lot for this ....

  • @lennyb.9616
    @lennyb.96162 ай бұрын

    thank you so much for explaining this in less than 5 min

  • @user-jf6dd2iy2s
    @user-jf6dd2iy2s2 ай бұрын

    Dude you are the best, cheers

  • @yuezhang8313
    @yuezhang8313 Жыл бұрын

    Thanks for your clear explanation

  • @mateoldnsk2693
    @mateoldnsk26934 ай бұрын

    You saved my entire life. Thank you so much.

  • @MichaelSambol

    @MichaelSambol

    4 ай бұрын

    💪🏼❤️

  • @user-kp3ox6cc9k
    @user-kp3ox6cc9k6 ай бұрын

    Best Explanation on youtube so far..Every other video is from 15 to 20 minutes..and here you are doing it in 4 minutes😂

  • @crazycroze
    @crazycroze Жыл бұрын

    Legit the best explanation out there.

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    Thank you!

  • @QuackDocElias
    @QuackDocElias4 ай бұрын

    thank you, so much easier to understand

  • @Jeetuni
    @Jeetuni Жыл бұрын

    Michael Sambol should take the place of my tenured professor that teaches Algorithms.

  • @NoOne-ev3jn
    @NoOne-ev3jn Жыл бұрын

    The Queue in place always go over my head, now with the visualisation it makes it a lot more easier and obvious 😅😅😅

  • @isabelcerdan4128
    @isabelcerdan412810 ай бұрын

    Thank you for this videos

  • @jefferson5773
    @jefferson5773 Жыл бұрын

    thank you for your clear explanation

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    You're welcome!

  • @Motivational-Mango
    @Motivational-Mango4 ай бұрын

    I learned more in 4 minutes than all the 30 years of my life

  • @nightshocker03
    @nightshocker03 Жыл бұрын

    Ive been using recursion in dfs thinking it would work here too Thank you for helping me realize my mistake

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    Def easier iteratively for BFS! github.com/msambol/youtube/blob/master/search/breadth_first_search.py

  • @jawadhaidar3931
    @jawadhaidar39317 ай бұрын

    Thank you for the vide! What is the addrd value of the last if statement

  • @marianpascu8474
    @marianpascu8474 Жыл бұрын

    Bro, you are a god of explaining and teaching, so quick, so simple, so smart, not like other teachers who sound like broken records and x2 speed you tube videos.

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    Thank you, Marian!

  • @frederiquebaaij
    @frederiquebaaij2 жыл бұрын

    Could you please make a video on the Hungarian Method for a bipartite graph, using only the graph? Or is this not a subject you can cover?

  • @MichaelSambol

    @MichaelSambol

    2 жыл бұрын

    I'll add it to my list..

  • @misterawkward930
    @misterawkward9307 ай бұрын

    i love you so much and i hope you live a long happy life

  • @isimbulamadmobenibulsun660
    @isimbulamadmobenibulsun660 Жыл бұрын

    ty very muchh

  • @Nico1a5
    @Nico1a53 ай бұрын

    And what are you searching for in there?

  • @ZenMadeGaming

    @ZenMadeGaming

    2 ай бұрын

    The letter X

  • @kristofkatona2188
    @kristofkatona21888 ай бұрын

    great video my

  • @divelix2666
    @divelix2666 Жыл бұрын

    Why do you need "visited" queue? It can still work without it, doesn't it? UPD: just figured out that your algorithm is for general graph, but you apply it to a tree (special case of graph) so "visited" is redundant for tree case.

  • @jaironicolasgomez1349
    @jaironicolasgomez1349 Жыл бұрын

    I love you!

  • @f.u.spammers3846
    @f.u.spammers38462 жыл бұрын

    Why not make "visited" a property of the node object so you don't have to create a separate 'visited' array?

  • @headyshotta5777

    @headyshotta5777

    Жыл бұрын

    what if you have to run more than one search on the same set of nodes? you would have to traverse the entire tree twice to reset your nodes for a single search. with an array you can just clear it. Much easier.

  • @kvelez
    @kvelez7 ай бұрын

    Great.

  • @cupofjava5480
    @cupofjava5480 Жыл бұрын

    1:31 isn't the que popping 'C' first ?

  • @arjunyonzan8557
    @arjunyonzan8557 Жыл бұрын

    Thanks

  • @danielkerber8761
    @danielkerber8761 Жыл бұрын

    you mentioned the use of queue, but used a stack with pop function, no?

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    The concept is the same where the abstract data structure is a queue, i.e., FIFO. In the video I used an array and did pop(0), but I later switched the code to use deque and popleft() [same concept as pop(0)] because it's more efficient. See here: github.com/msambol/youtube/blob/master/search/breadth_first_search.py#L17-L19. Let me know if that doesn't make sense!

  • @dannggg
    @dannggg2 жыл бұрын

    would be easier if you add what is the front and what is the end of the queue because other examples and other i see the queue is other way. I mean it doesn't matter since i figured it out after a few minutes but i think it would make it easier to understand quickly whats happening lol

  • @MichaelSambol

    @MichaelSambol

    2 жыл бұрын

    I should have added that, you're right. Apologies!

  • @dannggg

    @dannggg

    2 жыл бұрын

    @@MichaelSambol no worries just reviewing for algorithms test tomorrow And this really did helped me. Thanks for making these videos!!!

  • @KBoxx
    @KBoxx29 күн бұрын

    He said first in first out and queue but is demonstrating a last in first out stack data structure.

  • @MichaelSambol

    @MichaelSambol

    29 күн бұрын

    It's FIFO :)

  • @kdewanik
    @kdewanik Жыл бұрын

    Respect 🫡

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    🫡

  • @ramyakavyar
    @ramyakavyar Жыл бұрын

    Hi, the audio is not clear on your videos. It goes on mute in between for a few seconds. Could you please fix this on all your videos. It would be really helpful. Thanks.

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    Sorry about that. I'm working on the right settings. Thanks for the feedback.

  • @MichaelSambol

    @MichaelSambol

    Жыл бұрын

    Is my latest video better, on Fibonacci heaps?

  • @ramyakavyar

    @ramyakavyar

    Жыл бұрын

    @@MichaelSambol Nope. It isn't any better. Fibonacci heaps also has the same issue.

  • @Xolomilco
    @Xolomilco4 ай бұрын

    Confusing how you pop the [0] element yet you show that element as being on the far right of the array order, which would not be the [0] element in actual code...

  • @MichaelSambol

    @MichaelSambol

    4 ай бұрын

    Sorry that's confusing! Check the latest code here, I hope it clarifies it: github.com/msambol/dsa/blob/master/search/breadth_first_search.py.

  • @tutaf
    @tutaf3 ай бұрын

    Muhammad Sumbul 😳😳

  • @danielkim7024
    @danielkim70242 ай бұрын

    What happens if the graph in question contains cycles? If we're marking nodes as visited when we pop them, won't that mean there will be multiple instances of a node being enqueued into the queue until they are actually reached and dequeued i.e. marked visited?

  • @amirhoxha6231
    @amirhoxha6231 Жыл бұрын

    o nanq

  • @velerus3620
    @velerus36202 жыл бұрын

    First

  • @WhiteFontStudios
    @WhiteFontStudios8 ай бұрын

    My lord. Sometimes play back speed 2x just isn't enough

  • @bitwodeddemissie7955

    @bitwodeddemissie7955

    5 ай бұрын

    Use revanced there is 5x

  • @legolorian3271

    @legolorian3271

    3 ай бұрын

    Maybe stop watching tik tok so you have an attention span longer than a minute

  • @NippieMan

    @NippieMan

    2 ай бұрын

    @@legolorian3271 he does talk pretty slow I won’t lie.

  • @lejuan9002

    @lejuan9002

    2 күн бұрын

    ​@@legolorian3271 chad

  • @hellogais2177
    @hellogais21775 ай бұрын

    You say first in first out like we are supposed to know where you put elements in and out, can't you put them in either at the top or at the bottom? And why do you say vertically and horizontally without showing a tree, the orientation can be different, we have to fast forward to see what tree you have in your mind, but we can't read yours

  • @ogolasaura1805
    @ogolasaura180510 ай бұрын

    you code has issues i think this is the right way for BFS def bfs(graph, node): visited = [] queue = [] visited.append(node) queue.append(node) while queue: s = queue.pop(0) print(s, end=" ") for n in graph[s]: # Corrected indentation if n not in visited: visited.append(n) queue.append(n)

  • @MichaelSambol

    @MichaelSambol

    10 ай бұрын

    Definitely a few different ways to do it. See here: github.com/msambol/dsa/blob/master/search/breadth_first_search.py

  • @kafychannel
    @kafychannel Жыл бұрын

    thank you so much for clear explanation