Тёмный

Kruskal's algorithm in 2 minutes 

Michael Sambol
Подписаться 126 тыс.
Просмотров 996 тыс.
50% 1

Step by step instructions showing how to run Kruskal's algorithm on a graph.
Code: github.com/msa... (different than video, I added this retroactively)
Source: Algorithms by S. Dasgupta, C. H. Papadimitriou, and U. V. Vazirani [www.amazon.com...]
LinkedIn: / michael-sambol

Опубликовано:

 

30 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 424   
@AnishKaranPhotography
@AnishKaranPhotography 9 лет назад
Are you from outer space? My lecturer couldn't explain this in 2 hours and you did in 2 mins. Thanks a lot.
@peterbakke
@peterbakke 6 лет назад
Math and CS educators need to work backward from this video. Have the students obtain an intuitive understanding of what's going on, and then drone on for 2 hours. Hopefully, something sticks. Way to go, Michael!
@diwang4572
@diwang4572 3 года назад
@@Fedorahatter exactly, my professor talked about bunch of lemma and proofs first and then go on briefly touched upon the algorithm which we were all lost by the time he talked about it which was like 1 hour into the lecture.
@mavyfaby
@mavyfaby 2 года назад
Same, this video is much better than my lecturer explaining this topic in an hour still I didn't understand. I wish he'll explain like this.
@adelalmohtaseb5261
@adelalmohtaseb5261 Год назад
Fr me as well.
@danielriley3618
@danielriley3618 Год назад
😆
@Elmirgtr
@Elmirgtr 10 лет назад
you explained something in 2 minutes what my prof did in two lessons.
@MichaelSambol
@MichaelSambol 9 лет назад
Elmir Ma Glad I could help!
@Griff10poldi
@Griff10poldi 8 лет назад
+Elmir Ma Same thing here.. I've wasted my time at class lol
@Elmirgtr
@Elmirgtr 8 лет назад
Griffin Seannery and I ended up doing well in that class. Thanks again, uploader!
@school_pizza
@school_pizza 4 года назад
@@Elmirgtr Some stories have fairy tale endings.
@Elmirgtr
@Elmirgtr 4 года назад
@@school_pizza So true. When I wrote this I was in undergrad, now I am doing PhD and working on a paper to submit to Nature
@mohammedabdulrafay
@mohammedabdulrafay 5 лет назад
“If you can't explain it to a six year old, you don't understand it yourself.”
@MisterTipp
@MisterTipp 9 лет назад
Fucking legend mate!
@mikeli1123
@mikeli1123 3 года назад
this is why I don't watch lecture recording
@wade3ed
@wade3ed 3 года назад
tfw: this is actually really simple but your professor unnecessarily complicated it
@saeedbaig4249
@saeedbaig4249 6 лет назад
0:56 - "Notice the smallest edge is BE, but this node connects 2 nodes that are already in the same tree, so it will not be chosen." I think you could have picked your words better. The reason we don't choose BE is NOT because B and E are already in the same tree (I mean, so were A and C, yet you added AC), but because adding BE would create a cycle in the tree, and MSTs aren't supposed to have cycles.
@kirandhakal8601
@kirandhakal8601 5 месяцев назад
You cleared my confusion. Thank you.
@keagenmccartha7412
@keagenmccartha7412 5 месяцев назад
how is that confusing? if both points are already discovered then u arent adding a new point to the tree... its just a wasted edge
@squeesquee6
@squeesquee6 4 месяца назад
@@keagenmccartha7412because he did that with AC even though both were already in the tree. Just because you are r€t@rded doesnt mean you need to yap about it to everyone else.
@anirudhkrishna.s5397
@anirudhkrishna.s5397 4 месяца назад
@@keagenmccartha7412 because "A spanning tree of a graph consists of all nodes of the graph and some of the edges of the graph so that there is a path between any two nodes"
@keagenmccartha7412
@keagenmccartha7412 4 месяца назад
@@anirudhkrishna.s5397 congrats genius
@xbit97
@xbit97 3 года назад
It's incredible how my teacher's lessons started talking about cycles and cuts and shit formulas while the algorithm is so freaking simple... Order edges by weight, go through them in that order, if the edge connects different trees use it, if it connects the same tree discard it, was that so difficult? Thank you for this clear explanation dude, you rock
@miguelflor1600
@miguelflor1600 Год назад
ele deu gosto porque é bueda da fixe
@Zeldarulah
@Zeldarulah 11 лет назад
Seems simple enough.. but not so simple for coding :P
@MidnightBloomDev
@MidnightBloomDev 4 года назад
You could do this with 10 lines of python code
@vtvtify
@vtvtify 4 года назад
@@MidnightBloomDev Ummmm, despie it indeed being simple to code, just the union find used is not 10 lines...
@isakjacobsson867
@isakjacobsson867 3 года назад
This is a one liner ez
@Hgh38
@Hgh38 2 года назад
Nah once you implement these things, it gets easier. I lowkey love to do it.
@stefanchelbosu1
@stefanchelbosu1 6 лет назад
I hate when my university professors start by explaining abstract shit and formulas and general cases, u fall asleep, and in the and they say aaalll this just to remove all possible edges. I mean they could start with catching your attention with an example, and then expand on the subject for 3 hours. It would be so much better.
@Abdullah-cm1tn
@Abdullah-cm1tn 3 года назад
yes, they don't start with examples. they start with abstract formulas and equations, confusing the hell out of us. then give the most complicated example they can find from the book. pathetic.
@brendawilliams8062
@brendawilliams8062 Год назад
You cannot cycle it and it’s information can only go through a process of its this than it’s that.
@R1CARD049
@R1CARD049 8 лет назад
Thank you so much, we were given incomprehensible pseudo-code and confusing notation. For this to seem so simple after a
@MichaelSambol
@MichaelSambol 8 лет назад
+Richard Paul You're welcome, Richard. Glad you enjoyed.
@08a14979
@08a14979 6 лет назад
i hate discrete math with passion. making something simple look so complicated
@biblemansings
@biblemansings Год назад
@@08a14979 lmao im genuinely worried im going to fail discrete math. I swear it’s how my professor teaches. He overcomplicates everything and he will talk about one thing for like an hour so it’s too easy to get confused.
@marflage
@marflage 4 года назад
For those who are a bit confused, he did not search for 7 by skipping 4, 5, 6. He did in fact search for them but found them to be making a circuit (closed path with previously chosen nodes).
@brettsharpe7305
@brettsharpe7305 9 месяцев назад
You just said he didn’t
@JJCUBER
@JJCUBER Месяц назад
@@brettsharpe7305the second part where they say that they did search refers to the rest of the numbers. In sum, all edges were considered in increasing order, but the ones which would create a cycle were discarded.
@mrndc
@mrndc 10 месяцев назад
From what I've learned: If you are stuck between choosing multiple edges with the same weight, like in 0:40, (A, D) or (A, C), or (B, E) Choose the one that doesn't create a cycle, if none of them create a cycle: Prioritize the edge that is alphabetically first. In this case, (A, C) is the first in the alphabetical order.
@geekinthehattech
@geekinthehattech 10 лет назад
Very nice video. Straight to the point and quick.
@Joophish
@Joophish 8 лет назад
fuck yes, simple. Hopefully this will help on my data structures test, though usually what you study the most is what the instructor completely leaves out.
@Khadari2013
@Khadari2013 4 года назад
what amazes me is how I seat through 2 hour of lecture class and couldn't understand a jack thing but 2 minute video and I feel like replacing my professor so I can teach the class.
@mariestolk3794
@mariestolk3794 4 года назад
Same
@rrestoring_faith
@rrestoring_faith 4 года назад
I would still suggest staying in lectures. For instance, this videos states that you can use merge sort to sort the Edges. Which is fine and true, but why would you even bother? Why use merge? Why not a priority queue? He also doesn't explain the time complexity. You can perform Kruskal's in O(ElogV) but his is O(ElogE) because merge sort is dominating. Which is better? [Most examples show E >= V]. These videos are great for getting the point and quickly understanding how it works, but when you get into it the details may not be as good as you'd think.
@theendurance
@theendurance 4 года назад
@Rrestoring faith Exactly. This video doesnt actually teach you anything. It simply shows what Kruskal's aglorithm is. This is way too basic to be useful
@ankitb3954
@ankitb3954 2 года назад
I watched this during my bachelors, now I am watching it during my masters hopefully will be back during PhD
@MichaelSambol
@MichaelSambol 2 года назад
go get that doctorate
@henryhayes8390
@henryhayes8390 5 лет назад
You say that we must not connect 2 nodes that are already in the same tree but you then add AC into the MSP. But both of these are already in a tree, yet we cannot select BE
@smheath
@smheath 5 лет назад
You can't add an edge that connects 2 nodes that are already connected in the MSP. Before he adds AC, the only edges are AB and CE. After adding AC, he can't add BE because B and E are already connected by BA > AC > CE.
@alexmeier2705
@alexmeier2705 Год назад
​@@smheath Wrong, the only reason why he cant add b and e because he would create a closen cycle after adding b and e
@w4439
@w4439 6 лет назад
Your tutorials are the best! I learned 2 months of discrete mathematics in under 30 minutes. 5 years have passed since you posted this but it has had a larger impact on my understanding than my professor has provided all semester. Thanks.
@marcushandley3017
@marcushandley3017 8 лет назад
How do you tell if two edges are in the same tree without it being very time complex? \
@yt_chill
@yt_chill 3 года назад
I am sure there a few ways to do it, although in my class we used Disjoint sets.
@channelname9468
@channelname9468 3 месяца назад
great video bro, you explained this so much better and in like 1/30th the time of my teacher lmao
@MichaelSambol
@MichaelSambol 3 месяца назад
thanks man!
@har0111890011
@har0111890011 2 года назад
Absolute Chad ; Saving me from my algorithms exam tomorrow. My Lecturer took so much explaining these concepts but you are a genius made it easy in no time. Cheers !
@DaniaMihaela
@DaniaMihaela 5 лет назад
Why tf did i choose cs 😭
@polkadotorchidea404
@polkadotorchidea404 9 лет назад
Thanks a lot! I have a test tomorrow xx
@MichaelSambol
@MichaelSambol 9 лет назад
Polka dot Orchidea Glad I could help!
@miguelflor1600
@miguelflor1600 Год назад
@@MichaelSambol és bueda da fixe
@mitchell2719
@mitchell2719 8 лет назад
This was way easier than my prof's explanation. Thank you so much!
@MichaelSambol
@MichaelSambol 11 лет назад
u and v are vertices in the graph. {u,v} is the edge between those two vertices.
@JamesBrodski
@JamesBrodski Год назад
Great video. Thanks so much for making it!
@兴宣大院君-h4s
@兴宣大院君-h4s 7 лет назад
核心思想就是如果俩点都在一个系统里了,就没必要介绍他俩了
@Sonikkid1
@Sonikkid1 3 года назад
Even in 2021, you are still relevant. Thank you for your service
@darthrevan204
@darthrevan204 7 лет назад
4 hours of discrete mathematics lectures and seminaries ... compressed in 2 minutes. you sir, are a life saver
@Goblino
@Goblino 3 года назад
You sound like Ryan from Supermega lol
@emilyhuynh7855
@emilyhuynh7855 8 лет назад
You're a lifesaver! Got an exam tomorrow and my textbook nor my professor was making sense to me. Glad to know it was a much easier process than I initially thought!
@Dorddis
@Dorddis Год назад
he's saving lives still... been 6 years!
@JDBBB
@JDBBB 4 года назад
dude how many graphs did you draw lol?
@AwsomeAlligator
@AwsomeAlligator 7 лет назад
It would be cool if you added a short video about union and find as an addition to this video, as the intuition for Kruskal's algorithm is explained brilliantly here, but the implementation needs to use union and find for the complexity to be as good as you mention and these functions are quite interesting and not completely trivial. Thanks for all your great videos btw, they are very clear and concise :)
@seif7653
@seif7653 4 месяца назад
my prof made this look like it's the hardest thing ever after talking to women. THANK YOU.
@devilonhog7113
@devilonhog7113 10 лет назад
i dont get why you pick A-C at 0:57,but later you dont pick B-E
@_Yuurt
@_Yuurt 10 лет назад
I just figured this out. A-C doesn't create a loop, but B-E does (ABEC ABEC ABEC ...) Hope this helps!
@bionicsein3182
@bionicsein3182 9 лет назад
Yuurt thank you i was confused there too.. i tend to have an eye for mistakes when someone is explaining something and it always exposes my ignorance. thanks a million
@_Yuurt
@_Yuurt 9 лет назад
No problem!
@gongjiaji2489
@gongjiaji2489 7 лет назад
you are my time saver, I spend many hours on PPT, blog and other videos, none of them explain so clearly in this manner. they try to be professional so that they don't speak nature language. Thank you very much.
@rrrushan
@rrrushan 3 года назад
Still relevant in 2021. Thank you!
@miguelflor1600
@miguelflor1600 Год назад
ele deu gosto porque é bueda da fixe
@crossrob3126
@crossrob3126 5 лет назад
Dude you saved my ass from a F
@felixcuello
@felixcuello 5 лет назад
I wondder WHY at university they spend 20-30 minutes explaining this, and having round of questions. Your 2 minute videos explaining algorithms are simply PERFECT. Thank you very much indeed.
@samaa8904
@samaa8904 8 лет назад
شكرًا :)
@vues-xk1md
@vues-xk1md 7 лет назад
subscribe me
@30filip50
@30filip50 2 года назад
Thank you so much.
@shri9229
@shri9229 4 года назад
Epic Explaination lol
@Derbb
@Derbb 2 года назад
I never watched anything on this nor was taught in class so I’m just looking at this out of own interest, but that seems extremely easy. Can sort the edges, then take the minimum such that there is no cycle made. Cycle can easily be found, if you use a set for nodes that are connected to the MST being built, if both have been visited, then you don’t consider that one at all, skip. Alternatively for those into competitive programming, a min segment tree could be an interesting use case. O(e) to build, o(log e) for queries on min and updating edges you add in to be an int max length. Then again you’d have e queries at most, and each query/update takes log e time, so still e log e, but just preference and a different way to look at it.
@gunjansethi2896
@gunjansethi2896 8 лет назад
Saved my life on the exam morning! Thank you so much :D
@syncflipper
@syncflipper 11 лет назад
You are a life saver! Also you need a donate button!
@raular5513
@raular5513 6 лет назад
At what course are you studying this :) I'm in 1st of informatic engineering :)
@chanhien4000
@chanhien4000 6 лет назад
I'm also a freshman majoring in infosec. Not sure if this would help later on.
@capelo2148
@capelo2148 11 месяцев назад
You are a LIFE SAVIOR. Thanks!
@WhoYaCallinPinhead804
@WhoYaCallinPinhead804 2 года назад
Ok guys, it’s finals again and time to meet up with these youtubers the night before the test, to learn about a topic that we didn’t understand from professors taught weeks ago.
@DavideSmithCapone
@DavideSmithCapone 2 года назад
Actually time complexity is theta(Elog(E)) if you choose merge sort, you can have O(Elog(E)) instead if you choose heap sort. Right?
@Yammies
@Yammies Год назад
wait why did you add A->C, but not B->E, if the reason you didnt add B->E was because they were already visited? Is it because of the no-cycle rule or the "cant add two nodes previously visited rule"? Thanks for the video though :D
@bionicsein3182
@bionicsein3182 9 лет назад
the nodes A and C are in the the tree but are still added why are they added
@KabeerVohra
@KabeerVohra 9 лет назад
Bionic sein because they are two seperate trees, we want a single minimum spanning tree of the graph. A better way to think of it is we do not want to create any cycles
@tachozhelev3359
@tachozhelev3359 9 лет назад
Kabeer Vohra Isn't it better to say that they do not close any cycles. Meaning that we should mark all the N - 1 edges (where N is the number of vertices), that do NOT close cycles ?
@antarpreetsingh9038
@antarpreetsingh9038 Год назад
thank you, thank you so fucking much. You cant possibly from this planet. My fucking prof cant explain it in 2 hours and you fkin nailed it in 2 min. Glory to you sir. Mightly Michael Sambol.
@thegame619619619
@thegame619619619 9 лет назад
saving my final, i love you
@alexandrefillinger1103
@alexandrefillinger1103 4 года назад
trop bien chacal jai dead ca
@holocenesage
@holocenesage 2 года назад
I feel like this video should be titled something like "Intuitive Understanding of Kruskal's Algorithm".
@shorty235z
@shorty235z 7 лет назад
My professor took over an hour trying to explain Kruskal's algorithm. You did it in less than 2 minutes. Someone tell NASA to hire this fucking man!
@bristowxavierlm
@bristowxavierlm Год назад
Why is (A,C) chosen since it makes 2 nodes on the same tree?
@soumilssinha5010
@soumilssinha5010 7 лет назад
hi.. could you please help me with travelling sales person problem with branch and bound technique? Need help in emergency!!
@salihbalkan5083
@salihbalkan5083 8 лет назад
Perfect tutorial I have ever seen. Thanks, I got it in just 2 minutes!
@Donaukinder-u8q
@Donaukinder-u8q 4 месяца назад
The explanation is very intuitive and concise, thank you so much.
@putin_navsegda6487
@putin_navsegda6487 Год назад
sir thank you ! it's very clean and understandable explication !
@tbagin3d
@tbagin3d 5 лет назад
If you choose to connect CE then AB, then BE, then AD, then DF, then FG you'd have another MST.
@anikethjana416
@anikethjana416 9 месяцев назад
Why is the Subscribers has stopped to 95k , it should be atleast 7-8M
@ohwillyum3997
@ohwillyum3997 7 лет назад
this guy explained this god damn thing more clearer in 2 minutes, than my professor who spent a whole week. but, college is worth it right?
@Oladayo1
@Oladayo1 9 месяцев назад
long shot but is it possible to have connect B and E vertices while not connecting A and C vertices. I believe the reason for not connecting B and E vertices is because it would have formed a cycle.
@theyluvvshark
@theyluvvshark 4 года назад
i was going to write krusty crab and kruskal's algorithm appeared, now im watching this
@AbhinavSingh-zo2wo
@AbhinavSingh-zo2wo 2 года назад
You have done it wrong, minimum spanning weight is 24, you obtain 25
@Abdullah-cm1tn
@Abdullah-cm1tn 3 года назад
this ... was ... amazingly ... made ... simple ... OMG!!!
@miguelflor1600
@miguelflor1600 Год назад
ele deu gosto porque é bueda da fixe
@cozr2
@cozr2 3 месяца назад
Not all heroes wear capes
@MichaelSambol
@MichaelSambol 3 месяца назад
🫡
@flumiie
@flumiie 7 лет назад
Most university lecturers waste too much time, I've wasted mine too
@johnkim270
@johnkim270 5 лет назад
On 0:48, couldn't he have chosen BE instead of AC?
@thomaschurch1969
@thomaschurch1969 5 месяцев назад
Very succinct and to the point. Thanks for this.
@yousifsaid354
@yousifsaid354 Год назад
What was the point of adding AC if A and C were already discovered?
@jonyejin
@jonyejin Год назад
Is it proven that this is the optimal solution? Curious because it might not be optimal to pick the smallest weighted edge all the time
@alexleung842
@alexleung842 7 лет назад
I wish you had used a color other than red to highlight the added edges, as I'm red-green color blind.
@blackstreet23
@blackstreet23 7 лет назад
what is the difference of Prims and Kruskal?
@beani5355
@beani5355 2 года назад
Straight forward👏🏼nice one
@Hanabi1801
@Hanabi1801 3 года назад
the algorithm is ez to understand, but coding it is a problem
@ADAMyakoobi
@ADAMyakoobi 10 месяцев назад
then why did u chose A,C a and c were also two nodes that were already in your graph.
@hussienahmed6918
@hussienahmed6918 3 года назад
How can I thank you so simple like the video?
@czoknorris
@czoknorris 8 лет назад
Very nice! Thanks from Munich.
@adamtretera273
@adamtretera273 4 года назад
čau
@ItsYashu
@ItsYashu 8 лет назад
Thanks - From university of Wolverhampton^^^
@keshanrajen6171
@keshanrajen6171 7 лет назад
hold on how do i know which one is the smallest edge? what makes you label the numbers there in that order?
@BusinessGoose001
@BusinessGoose001 6 лет назад
if nodes a and c were already in the tree why did you add the edge between them to the tree? right after you make the point thatb and e are already in the tree so you dont add that edge. Im confused :(
@Ben-pb7ct
@Ben-pb7ct 3 года назад
Could anyone explain to me why B and E edge is not chosen?
@eznone4806
@eznone4806 Год назад
W channel. Love the videos
@fenikobutorhouse
@fenikobutorhouse 8 лет назад
i need unique kruskal method
@eunicefoo4499
@eunicefoo4499 2 года назад
You're amazing. Thank you !
@amirreza1446
@amirreza1446 10 месяцев назад
Why did you add A , C as both have been already visited.
@yann9637
@yann9637 Год назад
It is important to note that there can be many MSTs in the same graph
@ndrslmpk2634
@ndrslmpk2634 6 лет назад
So when you choose one of the 3-value edges you say, that it doesn't matter which edge I'm going to choose, but what would it be, if i had choosen the BE Edge first? I'd get to a different result or wouldn't i? How would i note a correction in the MST? That would be very helpful, thank you!
@ndrslmpk2634
@ndrslmpk2634 6 лет назад
So the only difference w'd be that the MST have a different direction, but in the end the edge sum would be the same, right? Can this different direction have a certain impact on the quality of my result? If I'd like to solve problems the most efficient way? For example I'm thinking about modelling the distance between nodes on the internet. So isn't it important, that the route the algorithm is going to return is everytime the same, so that I'm going to find always the same result(route) ?
@兴宣大院君-h4s
@兴宣大院君-h4s 7 лет назад
precise and concise
@chaz-e
@chaz-e 10 лет назад
At 0:58 why added edge AC? Vertices A and C are already visited and you gave the same reason to exclude the edge BE. Answer: It is because vertices B,E belong to the same disjoint set and their edge (BE) is excluded. Source: Minimum Spanning Tree #1: Kruskal Algorithm
@nebimertaydin3187
@nebimertaydin3187 6 лет назад
you saved my ass one more time
@KillerKillcam
@KillerKillcam 9 лет назад
because of your videos, I learned Kruskal's and Prim's algorithms in 4 minutes. My teacher took 10 minutes to do an example of Prim's and I didn't even understand it then. thanks!
@Jay-ih5se
@Jay-ih5se Год назад
Goddamn. And to think i spent a week in school on this
@sahilghuge5302
@sahilghuge5302 6 месяцев назад
Generational help done by u 😭🛐
@NaureenShaukat
@NaureenShaukat Год назад
i have a question you choose same graph in your video of prims algo , their total weight of graph was 24, but in this total weight of graph after finding minimum spanning tree is 25, shouldn't it must be same
@MichaelSambol
@MichaelSambol Год назад
They are slightly different.... ('C', 'F', 6) in Prim's vs ('D', 'F', 7) in Kruskal's. github.com/msambol/youtube/tree/master/minimum_spanning_trees
Далее
Dijkstra's algorithm in 3 minutes
2:46
Просмотров 1,4 млн
Prim's algorithm in 2 minutes
2:17
Просмотров 1,1 млн
Вопрос Ребром - Серго
43:16
Просмотров 738 тыс.
▼ КАПИТАН НАШЁЛ НЕФТЬ В 🍑
33:40
Просмотров 473 тыс.
3.5 Prims and Kruskals Algorithms - Greedy Method
20:12
Bellman-Ford in 5 minutes - Step by step example
5:10
Prim's Minimum Spanning Tree Algorithm | Graph Theory
14:53
Floyd-Warshall algorithm in 4 minutes
4:33
Просмотров 682 тыс.
Big-O notation in 5 minutes
5:13
Просмотров 1,1 млн
12. Greedy Algorithms: Minimum Spanning Tree
1:22:10
Просмотров 225 тыс.
Dijkstra's Algorithm - Computerphile
10:43
Просмотров 1,3 млн
Вопрос Ребром - Серго
43:16
Просмотров 738 тыс.