Lecture 13: Breadth-First Search (BFS)

Sdílet
Vložit
  • čas přidán 11. 06. 2024
  • MIT 6.006 Introduction to Algorithms, Fall 2011
    View the complete course: ocw.mit.edu/6-006F11
    Instructor: Erik Demaine
    License: Creative Commons BY-NC-SA
    More information at ocw.mit.edu/terms
    More courses at ocw.mit.edu

Komentáře • 299

  • @lifeoftomi_
    @lifeoftomi_ Před 4 lety +329

    You know what I like about the MIT lectures? They tell you the application/use case of what you're being taught. That makes a huge difference for beginners who have no way of visualizing these abstract concepts. Many people who get discouraged with stuff like this aren't able to relate with the content and feel like it's something crazy out there. It's the simple things.

    • @manavarora7644
      @manavarora7644 Před 4 lety +13

      I could not agree more with this. The biggest difference that I spotted along the lecture

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

      That's not the case for junior or senior level MIT OCW courses. The same professor teaches an advanced data structures course on CZcams and those are so academic and abtruse that he doesn't write code and only sometimes gives applications. Like his succinct binary trees data structure video. He gives one use (the Oxford English dictionary), but besides that he just explains its math.

    • @user-eg2jr8dt1j
      @user-eg2jr8dt1j Před 3 lety +6

      The secret is that some of the professors actually don't KNOW why they are teaching what they are teaching. Professors aren't always allowed to just "profess" what they know these days. This is the grand illusion of academia, many who know what's going on, don't teach. Many who teach would simply prefer to waste their time in a laboratory doing research work.

    • @shohanur_rifat
      @shohanur_rifat Před 2 lety

      Right you are my friend.

    • @missriri-if9yl
      @missriri-if9yl Před 4 měsíci

      u so real

  • @sergeykholkhunov1888
    @sergeykholkhunov1888 Před 3 lety +83

    00:40 graph search
    02:00 recall graph
    05:20 applications of graph search
    10:30 pocket cube 2x2x2 example
    20:25 graph representations
    20:40 adjacency lists
    26:00 implicit representation of graph
    29:05 space complexity for adj list
    31:05 breadth-first search
    34:05 BFS pseudo-code
    36:58 BFS example
    43:27 shortest path
    48:35 running time of BFS

    • @solwex
      @solwex Před rokem

      Hey there! There are some other videos in this course playlist that explain the terms used in this one.
      - represent graph in Python: czcams.com/video/5JxShDZ_ylo/video.html
      - adjacency list in Python: czcams.com/video/C5SPsY72_CM/video.html
      - examples of theta, O, omega: czcams.com/video/P7frcB_-g4w/video.html
      - what is hashing: czcams.com/video/0M_kIqhwbFo/video.html
      - python implementation of iterator: czcams.com/video/-DwGrJ8JxDc/video.html

  • @thepeopleofblore
    @thepeopleofblore Před 7 lety +364

    20:57: Representation of graphs
    31:10: BFS

  • @tanweermahdihasan4119
    @tanweermahdihasan4119 Před 3 lety +25

    Can we just take a moment to appreciate how brilliantly the camera work accompanied this already perfect lecture!

  • @jessielucky5530
    @jessielucky5530 Před 5 lety +47

    Super genus guy!
    From Wikipedia
    Demaine was born in Halifax, Nova Scotia, to artist sculptor Martin L. Demaine and Judy Anderson. From the age of 7, he was identified as a child prodigy and spent time traveling across North America with his father.[1] He was home-schooled during that time span until entering university at the age of 12.[2][3]
    Demaine completed his bachelor's degree at 14 years old at Dalhousie University in Canada, and completed his PhD at the University of Waterloo by the time he was 20 years old.[4][5]

    • @tianna308
      @tianna308 Před rokem +2

      omg can't believe I graduated from the same university as him.

  • @chanpol321
    @chanpol321 Před 7 lety +28

    Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key'[1]) and explores the neighbor nodes first, before moving to the next level neighbors.
    BFS was invented in the late 1950s by E. F. Moore, who used it to find the shortest path out of a maze,[2] and discovered independently by C. Y. Lee as a wire routing algorithm (published 1961).[3][4]

  • @farhan787
    @farhan787 Před 4 lety +48

    "There are more configurations in a 7*7*7 cube than the number of particles in the known universe" 27:35
    - Erik Demaine (2011)

    • @wetbadger2174
      @wetbadger2174 Před 3 lety

      So how does anyone solve it?

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

      @@wetbadger2174 by not trying all possible combinations/permutations but trying only the ones that make sense.

  • @rikampalkar
    @rikampalkar Před 2 lety +5

    One of THE best explanation of BFS, I’ve came across. It’s something about the way he explains. Brilliant.

  • @seansmith1685
    @seansmith1685 Před 7 lety +57

    I think Erik's lectures are very good

  • @RobinLinus
    @RobinLinus Před 9 lety +34

    Totally appreciate you mentioning the diameter O(n^2/log n) of n x n x n rubic's cube!!!

  • @sahilvelhal1435
    @sahilvelhal1435 Před 4 lety +33

    MIT teachers make student love the subject they teach :)

  • @vivekmittal229
    @vivekmittal229 Před 4 lety +9

    I really like the sound of the chalk.

  • @NewtonCazzaro
    @NewtonCazzaro Před 7 lety +15

    This is amazing, I am a student of Algorithms at the University of Nevada, Las Vegas. I really appreciate this class, thank you so much for the CZcams videos MIT!!!!

    • @awful999
      @awful999 Před 2 měsíci

      damn that’s crazy i’m studying cs there right now, im taking algorithms at the moment

  • @jirokaze6380
    @jirokaze6380 Před 4 lety +2

    His friendly tone makes the revising process so much easier!

  • @IamFilter94
    @IamFilter94 Před 8 lety +192

    Scissors cuts Paper
    Paper covers Rock
    Rock crushes Lizard
    Lizard poisons Spock
    Spock smashes Scissors
    Scissors decapitates Lizard
    Lizard eats Paper
    Paper disproves Spock
    Spock vaporizes Rock
    (and as it always has) Rock crushes Scissors

  • @janmadle4243
    @janmadle4243 Před 7 lety +198

    This lecture was really "Breadth"-takíng :-D ty Erik

  • @7th_CAV_Trooper
    @7th_CAV_Trooper Před 2 lety +2

    When I was a kid I used a screw driver to pry the Rubics cube apart and put it back together solved. That's when my parents knew I would be an engineer and not a mathematician.

  • @sam.kendrick
    @sam.kendrick Před 6 lety +4

    Thank you! Love Erik's lectures!

  • @shreyakjain9692
    @shreyakjain9692 Před 4 lety

    Thank you MIT for providing these lectures. These are very helpful.

  • @siddhantjain9596
    @siddhantjain9596 Před 7 lety +21

    My god! His t-shirt also has a graph!! Brilliant!

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

    Much better than the newer version. Glad I come back and watch this.

  • @99DaNtEmAN23
    @99DaNtEmAN23 Před 9 lety +21

    This guy's lectures really puts the Computer Science lectures at UofT to shame. But then again he is a prodigy, still doesn't justify why we get grad-students as "profs" though. Just my 2 cents

    • @lolpe1000
      @lolpe1000 Před 6 lety

      Well in the UoC, our prof doesn't even go into much depth... The guy in this video is amazing.

    • @bharasiva96
      @bharasiva96 Před 6 lety +5

      They go "Breadth-First" I suppose.

    • @raymondlion314
      @raymondlion314 Před 5 lety

      At UIUC, we were taught such stuff in C++ :(

  • @sarpersar8010
    @sarpersar8010 Před 8 lety +4

    Thanks to Erik Demaine

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

    Best lecture on BFS..
    Erik Demaine rockss....

  • @vedient
    @vedient Před 5 lety +16

    Lectures like this make me feel how lucky MIT students are !!!

    • @hortsss
      @hortsss Před 4 lety +1

      @@SimonWoodburyForget but I think the point is to just give students an introduction of the subject so they can work on real problems

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

      @Simon WoodburyForget Because you are forgetting that Computer Science is a...science. CS is not programming. Programming is monkey work. Algorithms are at the heart of CS. You don't need code because this isn't meant for practical uses. CS is just math for computers.

  • @devyashsanghai585
    @devyashsanghai585 Před 7 lety +30

    Love the way he is wearing a t-shirt with 5 vertices and and 5 directed edges. Whcih would require a space complexity of O(10) to be stored.

    • @m.yousafjaved6039
      @m.yousafjaved6039 Před 7 lety +1

      undirected ?

    • @naviseven5697
      @naviseven5697 Před 7 lety +7

      It's a reference from a rock paper scissors game from the big bang theory, so it is directed.

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

      So 0(1)

  • @seansmith1685
    @seansmith1685 Před 7 lety +10

    "There are more configurations in this cube than there are particles in the known universe. Yeah. I just calculated that in my head, haha" - Erik

  • @rodi-soonshin-kwon
    @rodi-soonshin-kwon Před rokem +1

    Very clear and intuitive 💎 Thanks for sharing this invaluable resouces! Big shout out to MIT 🔥🎓

  • @rohitsurana9281
    @rohitsurana9281 Před 7 lety +16

    Thanks MIT and Eric.Best teaching that too for free.

  • @andreportaro
    @andreportaro Před 4 lety +2

    42:40 Just want to applaud at an amazing explanation and demo 👏

  • @gnulinux2000
    @gnulinux2000 Před 2 lety

    Absolutely must watch, adding where they are used and application gives good perception which otherwise made graph dry subject for me.

  • @TheFootballPlaya
    @TheFootballPlaya Před 3 lety

    this guy is the man. his lectures are awesome.

  • @panagiotistzakis6799
    @panagiotistzakis6799 Před rokem

    Amazing lecture sir and of course your are from MIT because your level of knowledge is very high!!Thanks for your time..

  • @yl4441
    @yl4441 Před 3 lety

    Thank you so much for posting this video!!! Its too hard to find videos explain algorithms clearly and easy to understand.

  • @robertalaverdyan3150
    @robertalaverdyan3150 Před 4 lety +2

    Wonderful. I wake up watching these lectures and sleep watching them.

  • @lifanzhong9782
    @lifanzhong9782 Před rokem

    Thanks for the wonderful lectures Erik!

  • @nbro5529
    @nbro5529 Před 9 lety +21

    Erik Demaine - "...but in the textbook, and I guess in the world..." lol

  • @ReaRalte
    @ReaRalte Před 9 lety +1

    Better than my College's class, thumbs up.

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

    Thank you for a very clear explanation.

  • @josh54
    @josh54 Před 5 lety +22

    Wish my professor wasn't lazy and wrote all the notes on the board like this instructor. I can't keep up with half-assed powerpoints that my professor rushes through

    • @HanifCarroll
      @HanifCarroll Před 4 lety

      I don't know if he gave you guys the powerpoint slides, but if he did, then you wouldn't have to spend time copying them down because you'd know you would get them. That way, you can spend time writing down the things that will be more helpful for you.

    • @David-kx3xf
      @David-kx3xf Před 3 lety

      Mine used wolphram mathematica live, and it was an absolute mess 🤦🏻‍♂️

  • @rafiaqutab8174
    @rafiaqutab8174 Před 9 lety +6

    You are such an amazing teacher! I wish I had you in college

    • @ru2979
      @ru2979 Před rokem

      I wish I had u 🥺👉👈

  • @sujivsontitus5463
    @sujivsontitus5463 Před 9 lety +22

    May be the camera person should consider finding a balance between landscape and portrait shooting,
    instead of taking the actions in portrait always. It gets difficult to see the contents in the board with the staff,
    since the focus is set to one "focussed" part of the black board. This is just my thought. btw MIT rocks!

    • @MaicahRu
      @MaicahRu Před 8 lety +2

      Sujivson Titus True, a little frustrating when he's pointing at something but it's off the screen, or you're reading through something but part of it is cut off

  • @LiSek9611
    @LiSek9611 Před 3 lety

    great lectures, thank you for uploading this

  • @chanpol321
    @chanpol321 Před 7 lety +2

    Time and space complexity[edit]
    The time complexity can be expressed as
    O ( | V | + | E | ) {\displaystyle O(|V|+|E|)}
    ,[5] since every vertex and every edge will be explored in the worst case.
    | V | {\displaystyle |V|}
    is the number of vertices and
    | E | {\displaystyle |E|}
    is the number of edges in the graph. Note that
    O ( | E | ) {\displaystyle O(|E|)}
    may vary between
    O ( 1 ) {\displaystyle O(1)}
    and
    O ( | V | 2 ) {\displaystyle O(|V|^{2})}
    , depending on how sparse the input graph is.
    When the number of vertices in the graph is known ahead of time, and additional data structures are used to determine which vertices have already been added to the queue, the space complexity can be expressed as
    O ( | V | ) {\displaystyle O(|V|)}
    , where
    | V | {\displaystyle |V|}
    is the cardinality of the set of vertices (as said before). If the graph is represented by an adjacency list it occupies
    Θ ( | V | + | E | ) {\displaystyle \Theta (|V|+|E|)}
    [6] space in memory, while an adjacency matrix representation occupies
    Θ ( | V

  • @gaganb
    @gaganb Před 3 lety

    I can smell the chalk dust through the video. Takes me back, great stuff.

  • @carlosseda5619
    @carlosseda5619 Před 2 lety

    Amazing explanation, thank you!

  • @ariadnel5809
    @ariadnel5809 Před 6 lety

    Thank you this video is a great help.

  • @RICHUNCLEPENNYBAGS77
    @RICHUNCLEPENNYBAGS77 Před 10 lety

    Clear. I read the chapter corresponding to this in the Algorithm Design Manual but I wasn't feeling like it really all came together but this did it for me.

  • @solwex
    @solwex Před rokem

    Simply evergreen content!!

  • @MrWhileloops
    @MrWhileloops Před 5 lety

    Excellent lecture.

  • @zlw8844
    @zlw8844 Před 5 lety

    Erik is the best teacher who explains data structure and algorithms so clearly and in a simple way.

  • @lockersrandom6161
    @lockersrandom6161 Před 3 lety

    Thank You MIT.

  • @ruchirmumbarkar8758
    @ruchirmumbarkar8758 Před 4 lety

    Thank you!
    His t-shirt also has graph on it!

  • @SaiVineet
    @SaiVineet Před 10 lety +4

    This guy is so cool!

  • @MetallicDETHmaiden
    @MetallicDETHmaiden Před 5 lety

    Great video!! learned a ton!

  • @adityatrivediii
    @adityatrivediii Před 4 lety

    Thanks! Nicely Explained

  • @jakefischer8281
    @jakefischer8281 Před 3 lety

    I like the way he writes.

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

    he is a great teacher

  • @hnupadhyaya
    @hnupadhyaya Před 4 lety +1

    Dear all,
    In this lockdown stage in home, please provide game equipments to your children/students to play. If not help them to watch "Math Art Studio" in you tube. They will play with their names and learn different concepts in mathematics.Those who have seen it they have learnt maths and enjoyed its beauty every day.

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

    Thank YOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU, it took me 3 days to understand how to track the path in bfs

  • @kordaler
    @kordaler Před rokem +1

    Here are points in other videos in this course's playlist that explain terms used in this video:
    - represent graph in Python: watch?v=5JxShDZ_ylo&t=1709s
    - adjacency list in Python: watch?v=C5SPsY72_CM&t=189s
    - examples of theta, O, omega: watch?v=P7frcB_-g4w&t=130
    - what is hashing: watch?v=0M_kIqhwbFo&t=22
    - python implementation of iterator: watch?v=-DwGrJ8JxDc&t=978
    I found this useful. Hope some of you find it useful as well. If you find more terms for which I can add pointers, let me know.
    If a few people think that this is useful, I can add this information for a few more videos. If you are looking for this info in any specific videos, let me know. If I have made these notes for those videos, I will add.
    Cheers!

    • @solwex
      @solwex Před rokem

      Very useful. Would be more convenient if the link was properly given.

  • @user-my3yg3nz8r
    @user-my3yg3nz8r Před 2 lety

    This is amazing.

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

    yay MIT lecture in my room

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

    Don't understand why people complain about the chalk. As he writes down so am I doing in my notebook and I find this to be working very smoothly [especially as I can pause the video and also think for myself and try to prove what he said] - I'm getting most of what he says - less so to get a proof on the spot for n x n x n - but hey, he published a paper with et al. on this subject so :) that's accessible for later.

  • @Zero-bl6ym
    @Zero-bl6ym Před 7 lety +1

    Eric is great!

  • @MarzukiSondoss
    @MarzukiSondoss Před 10 lety +1

    Das is fantastisch! vilen dank

  • @benaya6
    @benaya6 Před 5 lety +9

    amazing lecturer. Mr. cameraman, please dring cofee or something and keep up

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

      Cameraman did a good job of knowing when we'd rather look at the board than him walking.

  • @shivammalviya1718
    @shivammalviya1718 Před 5 lety

    Thank you very much sir

  • @musfiqniazrahman
    @musfiqniazrahman Před 10 lety

    it's, in fact, from 34:14

  • @David-kx3xf
    @David-kx3xf Před 3 lety +3

    There are two ways to study algorithms: the MIT way, or the hard way

  • @spontaneoushorts
    @spontaneoushorts Před 8 lety

    :O its amazing then my whole CIT department

  • @goodnis6180
    @goodnis6180 Před 8 lety

    thank you

  • @parattakornchaisiriyanon2253

    Awesome Teacher

  • @onurduygu3281
    @onurduygu3281 Před 3 lety

    Thank you Eric! Eric choupo moting

  • @Jbdoster
    @Jbdoster Před 4 lety +1

    I had a great laugh around 19:00, thank you

  • @rashedsami1959
    @rashedsami1959 Před 6 lety

    Erik Demaine

  • @VivekTiwari03
    @VivekTiwari03 Před rokem

    Man I feel smarter just by sitting here even though I have no clue what happened in those 50 minutes.

  • @devmahad
    @devmahad Před rokem

    [FOR MY REFERENCE]
    1) Graph Applications
    2) Graph BFS Algo.
    3) Time Complexity

  • @StevenMcconnon
    @StevenMcconnon Před 11 lety

    thanks!

  • @isbestlizard
    @isbestlizard Před 3 lety

    I've always wanted to know HOW a rubics cube is actually mechanically put together that it allows so much random rotation of everything without breaking or getting gummed up. :O

  • @monatabuk
    @monatabuk Před 11 lety

    thanks

  • @user-jh4dj1ef4d
    @user-jh4dj1ef4d Před 2 lety

    30:40 BFS
    14:44 bookmark

  • @erics.4113
    @erics.4113 Před 3 lety +1

    This makes me think about the extraordinary gap in intellect between human beings.

  • @lancepereira9337
    @lancepereira9337 Před 7 lety +2

    Is that the guy from the Nova Origami special that proved you can make and 3 dimensional shape by folding a flat sheet of something?

    • @mitocw
      @mitocw  Před 7 lety +4

      Yes, Erik Demaine was in that Nova program on Origami. :)

  • @aishsagar
    @aishsagar Před 10 lety +1

    for n x n x n rubic cube, looks like the solution would be 2^(n+1)+n+1. based on 2x2x2 and 3x3x3 values. is it right?

  • @9033664044
    @9033664044 Před 7 lety

    Can Someone explain how the number of possible states is derived for 2*2*2 cube?

  • @Balakrishnan1991
    @Balakrishnan1991 Před 10 lety

    thanks...

  • @bhaveshgupta3846
    @bhaveshgupta3846 Před 10 lety

    what if i want to know all the shortest paths to a node in the example that is there in this lecture! for example there might my exponentially many ways to get to node f from s. and there might be many shortest paths.But BFS gives us only one! i want to know the no. of all the shortest paths between two nodes s and f. How can I achieve this?

  • @MuhammadHassan-lu4ox
    @MuhammadHassan-lu4ox Před 4 lety

    That hip movements at @5:02

  • @PeterParker-hm7ub
    @PeterParker-hm7ub Před 3 lety

    this is gold

  • @shabananisha1911
    @shabananisha1911 Před 9 lety

    thank u sir ...

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

    This is a great lecture. i really appreciate the level of teaching from MIT. This is what makes a good university: its professors.
    even though this video is 7 years old, i cant believe they're using chalk boards at MIT. White boards are so much cleaner and easier to read / write on.

  • @wthered
    @wthered Před 7 lety

    I love his T-shirt!!!!

  • @KaisarAnvar
    @KaisarAnvar Před rokem

    His T-Shirt: Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors.

  • @wetbadger2174
    @wetbadger2174 Před 3 lety

    How do you feed a graph into this method? I hate when people don't show the whole code. Is the adjacency list supposed to be a dictionary/hashtable?

  • @caesar1CZ
    @caesar1CZ Před 2 lety

    Prof. Demaine is just incredible. Enjoyable lecture, lots of examples and applications. Would love to meet him in person!

  • @user-on6nm4ex2q
    @user-on6nm4ex2q Před 6 lety

    What does "24 symmetries of the cube" refer to?

  • @akshanshthakur9235
    @akshanshthakur9235 Před 8 lety +38

    How can someone dislike this video?

  • @niharpatil4046
    @niharpatil4046 Před 7 lety +1

    How are there 24 possible symmetries?

  • @jereziah
    @jereziah Před 5 lety +1

    That Shirt... (a graph showing how to play rock, paper, scissors, lizard, Spock)