Lecture 14: Depth-First Search (DFS), Topological Sort

  Рет қаралды 452,154

MIT OpenCourseWare

MIT OpenCourseWare

Күн бұрын

Пікірлер: 215
@saifabu1744
@saifabu1744 7 жыл бұрын
Erik is one of my favorite professors of all time
@excalibour00
@excalibour00 11 жыл бұрын
Topological Sort: 42:00
@cloveramv
@cloveramv 6 жыл бұрын
Wow I was smiling in my mind when this happened - 26:36 So much so for being a student of MIT. . . Sorry for bad english .
@mrodriguezglobe
@mrodriguezglobe 4 жыл бұрын
thank you , you're the best
@MichaelBrashier
@MichaelBrashier 8 жыл бұрын
I didn't know DFS when I was 7 but I did know BFS subconsciously. I used it to get home after riding all over town on my bicycle all day.
@ervinzhou8251
@ervinzhou8251 7 жыл бұрын
DFS might be a bit more handy in your case lmao.
@Maen963
@Maen963 4 жыл бұрын
😂😂😂
@zaramomadi5569
@zaramomadi5569 3 жыл бұрын
I love this comment
@hkjpotato
@hkjpotato 3 жыл бұрын
no how can u use bfs?u went to block a,then street 1, 2, 3 of block a, failed. Then you move to block b. Right?
@sergeykholkhunov1888
@sergeykholkhunov1888 3 жыл бұрын
02:05 depth-first search 08:58 example 14:11 running time 18:03 edge classification 30:40 cycle detection 41:57 topological sort (job scheduling)
@neuron8186
@neuron8186 3 жыл бұрын
"when I was 7 years old I did DFS without even knowing it"and here i am 20 yo banging my head against wall to understand topic
@ronitaryan5402
@ronitaryan5402 3 жыл бұрын
me too bro, me too
@perveenneha1423
@perveenneha1423 3 жыл бұрын
God !!!!! you just spoke my mind........ even i am 20 and literally i am hell scared of all backtracking questions ......... infact i have skipped all of them ........ hell
@SanghoBose5
@SanghoBose5 6 жыл бұрын
This has to be one of the best lecture in the series.
@mrodriguezglobe
@mrodriguezglobe 3 жыл бұрын
DFS Time Complexity: 14:10 Cycle Detection: 30:00 Topological Sort: 42:00
@siennahunter9043
@siennahunter9043 5 жыл бұрын
"when I was 7 years old I did DFS without even knowing it" weird flex but ok
@doom9603
@doom9603 5 жыл бұрын
flex is real xD
@rj-nj3uk
@rj-nj3uk 5 жыл бұрын
Yeah. I agree. But he is a prof at MIT and we are potatoes watching him teaching.
@BharCode09
@BharCode09 4 жыл бұрын
@@rj-nj3uk Well, I'm a tomato!
@bartekpacia
@bartekpacia 4 жыл бұрын
3:54
@grantfaith
@grantfaith 4 жыл бұрын
i lol'ed at his comment
@zulumopuku5370
@zulumopuku5370 4 жыл бұрын
These lectures are so easy to follow. Thanks alot MIT
@zaramomadi5569
@zaramomadi5569 3 жыл бұрын
Erik Demaine is amazing. His lectures are so fun to watch and easy to follow. I love his older lectures too but mannn his more recent ones are pure gold.
@booleangray2225
@booleangray2225 3 жыл бұрын
Any specific ones?
@ronthomas8331
@ronthomas8331 9 жыл бұрын
when he was 7 years old he wrote a program to solve a maze using dfs, and that too without knowing it was dfs.WOW!!!.
@spandanhetfield
@spandanhetfield 9 жыл бұрын
+ron thomas He is the youngest prof in the history of MIT. He made a prof at around 20. Check out his wiki page :D
@ChrisLeeX
@ChrisLeeX 8 жыл бұрын
+Spandan Madan That is friggin awesome. He has a geeky charisma about him as well.
@abaybektursun
@abaybektursun 8 жыл бұрын
+Spandan Madan bruh
@jackll2149
@jackll2149 8 жыл бұрын
He should be like one of the guys in big bang theory. The only difference is he is a real person.
@hanssarpei5429
@hanssarpei5429 8 жыл бұрын
f
@estebanlopez1701
@estebanlopez1701 4 жыл бұрын
Oh Lord, one of the brightest minds at MIT is saying that doesn't have a good memory, that's the only part of the lecture I didn't understand
@crjacinro
@crjacinro 4 жыл бұрын
he is a math genius. math doesn't need much memory. It needs intuition and logic.
@manishmberwani454
@manishmberwani454 10 жыл бұрын
Superb teacher...................Wish if all colleges students can see these videos and learn better!!!!
@JeewanthaBandara
@JeewanthaBandara 9 жыл бұрын
Manish M Berwani They can. :)
@manishmberwani454
@manishmberwani454 9 жыл бұрын
I have seen many colleges, where students never learn from internet!
@mohitnirwan9812
@mohitnirwan9812 4 жыл бұрын
It'd be really cool, if people who attended this class like 10 year ago would come here to see this video :D
@BikasKatwalK
@BikasKatwalK 4 жыл бұрын
Cycle Detection: 30:00 Topological sort: 42:00
@dragon_warrior_
@dragon_warrior_ 4 жыл бұрын
*IMDB Rating* : 10/10 for this whole 6006 series edit : + extra 100points for uploading the crispy notes
@MikeChaseJr
@MikeChaseJr 4 жыл бұрын
I wish I was bold enough to wear a pony tail, a t-shirt, and jeans to teach class lectures. I love this man.
@ikaros9727
@ikaros9727 4 жыл бұрын
This man is truly amazing. Would be kinda interesting to see the textbooks MIT uses
@nathanaelfarciert711
@nathanaelfarciert711 4 жыл бұрын
Ikaros97 According to the course website, CLRS is the textbook for this course
@ikaros9727
@ikaros9727 4 жыл бұрын
@@nathanaelfarciert711 Kinda funny because i use the same ^^ Its like everybody uses it but quite often its very mathematical and hard to understand
@HexagonalClosePacked
@HexagonalClosePacked 4 жыл бұрын
Erik: When I was 7 year old, one of the first computer program I wrote was for solving a maze. .... Me: When I was 7 years old, I fast and furious with my new bicycle and ended up with stitches...(that's as impressive as I can get for a 7 years old me)
@Victor-yn6jm
@Victor-yn6jm 4 жыл бұрын
I was playing with mud when I was 7 years old
@sulakshanachakraborty1238
@sulakshanachakraborty1238 3 жыл бұрын
I was eating mud when I was 7 years old
@mindlessripoff22
@mindlessripoff22 10 жыл бұрын
damn bruh shouts out to young demaine killing the algorithm game since a young'n!
@lambo2712
@lambo2712 3 жыл бұрын
7 years old im trying to learn to read my native language and this man already master computer language
@nonsolomacintosh
@nonsolomacintosh 6 жыл бұрын
In the 2005 course there was Leiserson talking shit about python. Now: "this is python notation"
@ShingHim
@ShingHim 6 жыл бұрын
Seems like the camera man is asleep half of the time but great lecture!
@quidquopro1185
@quidquopro1185 6 жыл бұрын
03:55 Have been sitting scratching my head the whole semester over graphs and algorithms and he drops this bomb on me 1 week before my exam. Thank you for the confidence boost mate.............................................................. (jk he is awesome :) )
@mehmetatabal6923
@mehmetatabal6923 4 жыл бұрын
No people, that's legit he did that in 7. This guy was one of the child prodigies and he is famous for it. He got his PhD at the age of 20. What really surprised me was he said I have a terrible memory which is something that I would think every genius like him would have.
@mearaftadewos8508
@mearaftadewos8508 2 жыл бұрын
that tells he has high expectation of himself
@gamingdork3681
@gamingdork3681 4 жыл бұрын
Thank u for this amazing lecture my algo professors need to learn from u both way to teach and also get some knowledge as they are absolutely terrible.
@Chatbot121
@Chatbot121 2 жыл бұрын
Breadcrumb analogy was perfect
@essamewaisha8746
@essamewaisha8746 6 жыл бұрын
Edge Classification 18:22
@brandoncruz1208
@brandoncruz1208 11 жыл бұрын
Wish I knew DFS when I was seven...
@jdleanne
@jdleanne 4 жыл бұрын
well i had my first c++ program written at age 25. Left that 10 yrs for other studies but still manage to work as a c++ developer during a postdoc fellowship. I don't think age matters but time management is a headache.
@souvikdas2759
@souvikdas2759 6 жыл бұрын
the difference between a avg teacher and a great one is how do you communicate when students mistake. For ex: what is the time complexity? some said 'V'. He said ' A little optimistic' !! WOW !!
@mearaftadewos8508
@mearaftadewos8508 2 жыл бұрын
Most teachers are egomeniac as my observation of their characters; they enjoy tearing down students' confidence with out providing much comprehendable explanations(most of the times). The best teachers don't thems self that seriously and tend to build students knowledge base and confidence at the same time.
@cesaredecal2230
@cesaredecal2230 4 жыл бұрын
Edit: he later corrected himself. Introduction to Algorithms (3rd edition) by T. Cormen says "We now show that forward and cross edges never occur in a depth-first search of an undirected graph". Then why did the professor say we have cross edges in an undirected graph?
@SajjadKhan2-m5b
@SajjadKhan2-m5b 13 күн бұрын
What?
@dakotadanderson
@dakotadanderson 5 жыл бұрын
thank you from DePaul, MIT
@4blossoms
@4blossoms 10 жыл бұрын
Erik Demaine is hot! He makes any lecture 100 times more interesting!!
@jasonavina8135
@jasonavina8135 3 жыл бұрын
This is a good lecture, but I think would be confusing for people that aren't already familiar with how a DFS works, which is simpler than it seems here. What I like about it is the how he shows the pseudocode for it and the reasoning behind that.
@lockersrandom6161
@lockersrandom6161 4 жыл бұрын
Thank You MIT.
@Augustinephillips
@Augustinephillips 11 жыл бұрын
I love Erik Demaine!
@TomerBenDavid
@TomerBenDavid 5 жыл бұрын
topological sort 42:00
@capetaquebratudo
@capetaquebratudo 6 жыл бұрын
I didn't know you could be extremely clever and didactic at the same time. Congratulations.
@dragon_warrior_
@dragon_warrior_ 4 жыл бұрын
adios
@w1d3r75
@w1d3r75 4 жыл бұрын
Check the parent and if it not visited, traverse recursively
@sicktastic.videos
@sicktastic.videos 2 жыл бұрын
Professor Erik Demaine solved DFS when he was 7.... Dang.
@bogdantodasca2093
@bogdantodasca2093 4 жыл бұрын
30:10 - after explaining tree / backward/forward edges - "So what?". Exactly what I was wondering
@joeyalfaro2323
@joeyalfaro2323 3 жыл бұрын
God alone knows man's heart his thoughts we can only go by what we see or hear. Compation is rear commodity in world more rare gold.
@jimnewton4534
@jimnewton4534 5 жыл бұрын
Doesn't a discussion of topological sort need to include mention of a tie-breaker function, and a discussion of whether the tie breaker guarantees a unique order which obeys the constraints? It seems to me, naively, that the DFS approach is insufficient with certain tie-breaker functions. It is a bit strange that both the lecturer and also Cormen [Intro to Algorithms, Thomas Cormen et.al] ignore the question of a deterministic topological sort. My first encounter with topological sort with with the linerarization of class precedence lists in object systems which allow multiple inheritance. It is of utmost importance that the the class precedence list be deterministically ordered.
@awesomefox4653
@awesomefox4653 8 жыл бұрын
14:12 DFS time complexity
@evanshareef2397
@evanshareef2397 4 жыл бұрын
O(V+E)
@samhitajoshi
@samhitajoshi 4 жыл бұрын
When I was 7, I knew how to backtrack and how to write.
@PratikShende91
@PratikShende91 10 жыл бұрын
thanks for that,.......now m clear about the concept behind that...
@thinhnguyenvan7003
@thinhnguyenvan7003 3 жыл бұрын
when I was 7 years old I did DFS without even knowing it" . Ok Its not too late for learning new things (Me at 29 and appease myself)
@HienNguyenTechIO
@HienNguyenTechIO 4 жыл бұрын
Thanks MIT
@csl1384
@csl1384 4 жыл бұрын
14:53 "collaborative effort" LOL
@TothAndris91
@TothAndris91 11 жыл бұрын
Thank you so much, it was very easy to understand!
@NytronX
@NytronX 6 жыл бұрын
14:18 - Rundown of DFS (Figure 22.4) on pg. 605
@sianmuanthangmilun6104
@sianmuanthangmilun6104 8 жыл бұрын
He knew a smattering of DFS when he was 7 years old. Morale: Not all precocious geeks end up like Mark Zuckerberg.
@ShakkIsLife
@ShakkIsLife 7 жыл бұрын
mark zuckerberg is a complete noob compared to erik
@dylancutler1978
@dylancutler1978 6 жыл бұрын
Zuckerberg was a psychology major who's considered a tech genius because he wrote an app that sold well. All it was at the time was a few hundred lines of PHP. Erik is on another level.
@sizwesandile2644
@sizwesandile2644 8 жыл бұрын
Big YELLOW chalks prints White!
@BharCode09
@BharCode09 4 жыл бұрын
That is yellow wrapper around white chalk i guess, to avoid sticking.
@vrindasinghal3654
@vrindasinghal3654 4 жыл бұрын
That is the plastic chalk holder so the hands of the professor do not get dirty
@saadabouzahir8696
@saadabouzahir8696 7 жыл бұрын
Parent dictionary has been declared in both function is it a global variable ? or the parent's function are different? because in DFS parents contain start vertex while in the seconde one it contains father of.. with only one source.
@nanwu4430
@nanwu4430 6 жыл бұрын
The parent map has to be global or pass down to recursive calls. Otherwise, it won't work.
@allandogreat
@allandogreat 2 жыл бұрын
We don't pay, but we get!
@IQisTwenty
@IQisTwenty 11 жыл бұрын
that's Erik ma boy
@neuron8186
@neuron8186 3 жыл бұрын
ayo my boi are you ok its been 7 years how life goin?
@md.dilshadulislam9113
@md.dilshadulislam9113 5 жыл бұрын
Humm my code was right as it was changing it's level and back level for each isolated components or for each non out degree vertices
@isabellehu9231
@isabellehu9231 3 жыл бұрын
28:13 but what if we don't follow that first edge? well then we follow the second one. using your logic, that first "tree" edge is actually a "back" edge! i think that these edges are just a by-product of dfs and not for generic graphs without using dfs, if that makes sense. cheers :D
@이효건-o4o
@이효건-o4o 3 жыл бұрын
haha i was doodling on the maze when i was 7 years old
@sudhanshudey758
@sudhanshudey758 3 жыл бұрын
In the graph shouldn't the arrow drawn on the edge be from B to D?
@andreibozantan
@andreibozantan 10 ай бұрын
Is it OK to use recursive DFS for topological sort in practice? Or should we use a iterative implementation to avoid possible stack overflows?
@jimnewton4534
@jimnewton4534 5 жыл бұрын
To further beat a dead horse, the discussion of forward/cross/backward edges is a bit confusing, and not exactly well defined. Perhaps it is better defined in the text book the lecturer keeps referring to. For example, there is a looping edge from f to f. If you mark nodes in lineage list using the method explained in the lecture (via started-examining finished-examining advise), then the loop edge will point to a parent node (by that algorithm), and thus be a backward edge. Is this the intent?
@panfayang
@panfayang 11 жыл бұрын
i want a cushion, too.....
@JesseLH88
@JesseLH88 3 жыл бұрын
I also played with trees at 7... real trees, like the wooden kind.
@SajjadKhan2-m5b
@SajjadKhan2-m5b 13 күн бұрын
💀
@JonLee108
@JonLee108 4 жыл бұрын
36:06 - what is the difference between "where we start the search" and "the first vertex that is hit by the DFS?" thanks!
@zeronothinghere9334
@zeronothinghere9334 4 жыл бұрын
You can start your search earlier, then go over v1 to vk, before you hit v1 again. That is meant with "the first vertex that is hit by the DFS", basically, the first time you do DFS on a node that has already been visited before by that same search.
@hbaduk
@hbaduk 7 жыл бұрын
where is lip gallagher
@yuf2316
@yuf2316 5 жыл бұрын
What if the first node you visit in DFS is some node in the middle and can never reach its parent? wouldn't its parent be set to none and never corrects?
@mikey.audio.
@mikey.audio. Жыл бұрын
I was never able to learn like this. How is it possible to take notes AND simultaneously learn a new complex topic? The time complexity of this teaching method is like O(n!). You literally have to wait until the professor reads his notes and writes it on the board before you can then read it and write it in your notebook, only to then have to read it again later because you were too busy taking notes to learn it. There's so much more I can say, but I'll leave it at that. I'm only here to remind myself of how useless lectures were for me. I learned by reading the textbook.
@joeyalfaro2323
@joeyalfaro2323 3 жыл бұрын
No I understand I loved algebra and geometry puzzles never understand what equals sign ment. Never even fazed me best way to learn anything pic good tracher
@MrSmokey247
@MrSmokey247 4 жыл бұрын
Isn't determing back edges for right and left just a matter of perspective? I don't really understand how the two algorithms for left and right back edges differ..
@muslimx6263
@muslimx6263 8 жыл бұрын
I don't know how to thank you.. just thanks
@zulumopuku5370
@zulumopuku5370 4 жыл бұрын
He mentioned a book. what book is that ? @MIT openCourseWare
@mitocw
@mitocw 4 жыл бұрын
The textbook for the course is Cormen, Thomas, Charles Leiserson, Ronald Rivest, and Clifford Stein. Introduction to Algorithms. 3rd ed. MIT Press, 2009. ISBN: 9780262033848. See the course on MIT OpenCourseWare for more info and materials (lectures notes, exams with solutions, assignments with solutions) at ocw.mit.edu/6-006F11. Best wishes on your studies!
@thejassai8592
@thejassai8592 7 жыл бұрын
12:20 D is a parent to nothing,so it is'nt in the parent [ ].So how do we know that it's already been visited?
@JiancongXie
@JiancongXie 3 жыл бұрын
The student are so coooool when the teacher want democratic math, the total number of hands-up doesn't exceed 10..... Really similar as my student age, most students are sleep when taken algorithm course.
@VedhasDeshpande
@VedhasDeshpande 9 жыл бұрын
This guy is so cool! \m/
@Di5TuRBeD
@Di5TuRBeD 10 жыл бұрын
3:15 theoddone
@jossef12
@jossef12 11 жыл бұрын
Well explained!, Thanks.
@abaybektursun
@abaybektursun 8 жыл бұрын
Thank you!
@giaple6237
@giaple6237 4 жыл бұрын
Explanations are a little bit convoluted, particularly the codes. I think this lecturer does not like but has to follow the textbook.
@LordMoopCow
@LordMoopCow 4 жыл бұрын
yeah but do you have a dfs on rs mate
@randy4443
@randy4443 3 жыл бұрын
How would I choose the starting node?
@salexkorsan8790
@salexkorsan8790 3 жыл бұрын
I need help, I want to sort in bash file, Example.... a="10" b="100" C="1000" I want to sort this $a $b $c How to sort ?? Max value between this
@debasismandal1924
@debasismandal1924 4 жыл бұрын
when i was 7 years old i wrote hello world without even knowing it was hello world
@eightball8008
@eightball8008 7 жыл бұрын
8:30 in the parameters for DFS, are those commas between| V and Adj or are they little n's?
@macdondb
@macdondb 4 жыл бұрын
Commas. He does kind of backwards commas
@guywithaname5408
@guywithaname5408 6 жыл бұрын
17:15 Erik becomes Markiplier
@teckyify
@teckyify 6 жыл бұрын
The part with the edges was chaotic, still don't know what's what.
@rj-nj3uk
@rj-nj3uk 5 жыл бұрын
Yes he totally confused me on that undirected edge part.
@ankursatya4733
@ankursatya4733 7 жыл бұрын
@ 28:35 why would we follow the edge from the 2nd node from ''S' back to 'S' in case of undirected graph?
@FantomX932
@FantomX932 7 ай бұрын
Why does he uses paper? He does not keep in the head these ideas?
@mohansinghrawat4324
@mohansinghrawat4324 7 жыл бұрын
thankyou sir....
@РоманБожко-ф6й
@РоманБожко-ф6й 7 жыл бұрын
Hello, everyone. I have a question about forward edge. The lecturer said that a forward edge is a node->descendant, but, imho it shouldn't be tree edge of the ancestor. So, if we write an edge from b to g - that one will be a forward. Am I right? Thanks for responses.
@aryangoyal5823
@aryangoyal5823 4 жыл бұрын
descendant word applies only when node is a tree edge of that ancestor
@pnachtwey
@pnachtwey 6 жыл бұрын
I like this instructor better than the other one but both always take too long stating the obvious. I would start by asking "why bother?" Where would you use a graph? Why would you use a depth first search over a breadth first search? What about cutoffs?
@simplyajith1
@simplyajith1 4 жыл бұрын
46:20. why ? who knows? , Let's prove it.
@davidFbeckham
@davidFbeckham 5 жыл бұрын
Thanks my dawg
@bharathkotha
@bharathkotha 8 жыл бұрын
why do we need V as an argument in DFS-Visit method ?
@xinliangzhu6944
@xinliangzhu6944 7 жыл бұрын
It's the set of vertices.
@NiGhTzz2903
@NiGhTzz2903 7 жыл бұрын
In case someone else has the same question, he said at 5:18 that the V doesnt have to be there in the argument and the students can erase it.
@mohansinghrawat4324
@mohansinghrawat4324 7 жыл бұрын
i think text book u have is cormen lieserson
@tayyabmughal10000
@tayyabmughal10000 3 жыл бұрын
He wrote DFS algo when he was 7 years old . .....😬😬
@linkon_
@linkon_ 10 жыл бұрын
in DFS node goes from A to B and A to C Doesn't make B and c siblings?? When explaining types of edges @21:00 If node d is traversed first then node b and then node e and then node g when you draw an edge between G and C how it make crossed egde?? It should be backward and .. Cross edge should be like edge from F to itself.. ???
@Joshuaposada
@Joshuaposada 9 жыл бұрын
Linkon Manwani How does it go from A to C? if there was a line connecting them then it would be a cross edge and yes as sub tree they would be siblings.
@stretch8390
@stretch8390 8 ай бұрын
Does this lecture have DAGs?
Lecture 15: Single-Source Shortest Paths Problem
53:15
MIT OpenCourseWare
Рет қаралды 247 М.
Lecture 13: Breadth-First Search (BFS)
50:48
MIT OpenCourseWare
Рет қаралды 706 М.
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 23 МЛН
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 3,2 МЛН
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 7 МЛН
Smart Sigma Kid #funny #sigma
00:33
CRAZY GREAPA
Рет қаралды 7 МЛН
Lecture 7: Counting Sort, Radix Sort, Lower Bounds for Sorting
52:09
MIT OpenCourseWare
Рет қаралды 405 М.
Daniel Everett, "Homo Erectus and the Invention of Human Language"
1:10:43
Harvard Science Book Talks and Research Lectures
Рет қаралды 521 М.
Topological Sort Algorithm | Graph Theory
14:09
WilliamFiset
Рет қаралды 473 М.
MIT Introduction to Deep Learning | 6.S191
1:09:58
Alexander Amini
Рет қаралды 743 М.
2023 MIT Integration Bee - Finals
28:09
MIT Integration Bee
Рет қаралды 2,1 МЛН
Lecture 4: Heaps and Heap Sort
52:32
MIT OpenCourseWare
Рет қаралды 867 М.
26. Chernobyl - How It Happened
54:24
MIT OpenCourseWare
Рет қаралды 2,9 МЛН
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 23 МЛН