text
stringlengths 1
21.4k
|
---|
Kruskal's gonna just throw out the desire to have a connected subgraph at each step of the iteration. |
Kruskal's algorithm will be totally content to grow a tree in parallel with lots of simultaneous little pieces, only having them coalesce at the very end of the algorithm. |
So in Prim's algorithm, while we were only allowed to pick the cheapest edge subject to this constraint of spanning some new vertex. |
In |
Kruskal's algorithm we're just going to pick the cheapest edge that we haven't |
looked at yet. |
Now, there is an issue, of course, we wanna construct a spanning tree at the end. |
So, we certainly don't wanna create any cycles, so we'll skip over edges that will create cycles. |
But other than that constraint, we'll just look at the cheapest edge next in Kruskal's algorithm and pick it if there is no cycles. |
So let's look at this five vertex example. |
Again, there is no starting point. |
We're just gonna look at the cheapest edge overall. |
So that's obviously this unit cost edge and we're gonna include that in our tree. |
Right? |
Why not? |
Why not pick the cheapest edge? |
It's a greedy algorithm. |
So what do we do next? |
Well, now we have this edge of cost two, that looks good, so let's go ahead and pick that one. |
Cool. |
Notice these two edges are totally disjoint. |
Kay.' So we are not maintaining a connectivity of our subgraph at each iteration of Kruskal's algorithm. |
Now, it just so happens that when we look at the next edge, the edge of cost three, we will fuse together the two disjoint pieces that we had previously. |
Now, we happen to have one connected piece. |
Now, here's where it gets interesting. |
When we look at the next edge, the edge of cost four, we notice that we're not allowed to pick the edge of cost four. |
Why? |
Well, that would create a triangle with the edges of costs two and three, and that of course is a no-no. |
We want to span the tree at the end of the day, so we can't have any cycles. |
So we skip over the four because we have no choice, we can't pick it, we move on to the five and the five is fine. |
So when we pick the edge of cost five, there's no cycles, we go ahead and include it. |
And now we have a spanning tree and we stop or if you prefer, you could think of it that we do, we do consider the edge of cost six. |
That would create a triangle with the edges of costs three and five, so we skip the six. |
And then, for completeness, we think about considering the seven, but that would form a triangle with the edges of costs one and five, so we skip that. |
So after this single scan through the edges in assorted order, we find ourselves with these four pink edges. |
In this case, it's a spanning tree and as we'll see, not just in this graph but in every graph it's actually the minimum cost spanning tree. |
So, with the intuition hopefully solidly in place, I don't think the following pseudocode will surprise you. |
We want to get away with a single scan through the edges in short order. |
So, obviously in the preprocessing step, we want to take the unsorted array of edges and sort them by edge cost. |
To keep the notation and the pseudocode simple, let me just, for the purposes of the algorithm, description only, rename the edges one, two, three, four, all the way up to m conforming to this sorted order, right? |
So, the algorithm's just gonna scan through the edges in this newly found sorted order. |
So we're gonna call the tree in progress capital T, like we did in Prim's algorithm. |
And now, we're just gonna zip through the edges once in sorted order. |
And we take an edge, unless it's obviously a bad idea. |
And here a bad idea means it creates a cycle, that's a no-no, but as long as there's no cycle, we go ahead and include the edge. |
And that's it, after you finish up the for loop you just return the tree capital T. It's easy to imagine various optimizations that you could do. |
So for example, once you've added enough edges to have a spanning tree. |
So n - one edges, where n is the number of vertices, you can get ahead, go ahead and abort this for loop and terminate the algorithm. |
But let's just keep things simple and analyze this three line ver sion of Kruskal's algorithm in this lecture. |
So just like in our discussion of Primm's algorithm, what I wanna do is first just focus on why is Kruskal's algorithm correct? |
Why does it output a spanning tree at all? |
And then, the spanning tree that it outputs? |
Why on earth should it have the minimum cost amongst all spanning trees? |
That's when we're, once we're convinced of the correctness, we'll move on to a naive running time implementation and then finally, a fast implementation using suitable data structures. |
[sound]. |
Stanford University. >> [foreign] >> We have one of the most unique charter school contexts in California. |
In that, we serve one of the highest indices of |
language learners which is upwards of 80% of our student population coupled with students in poverty who are 95% of our students qualify for our free or reduced lunch. >> [foreign] >> Two months ago an e-mail came to me from the |
Assistant to the Secretary of Education Arne Duncan asking, do any of us knows any teachers who are true heroes, who would during teacher appreciation week deserve a call directly from the Secretary commending them on the amazing work they do on behalf of America's children. >> [foreign] >> In my eleven years working in high-need urban areas I have never encountered an educator who exhibits the type of dedication and passion and commitment that Misla Barco brings to our school on a daily basis. |
She is a true hero in every sense of the word. >> I love teaching. |
I think I was born to be a teacher. |
[foreign] |
[laugh] |
I'm happy for the school because it's a great recognition for the program. |
It's a great recognition for the work that stands for the students supporting the high school so I'm very happy. |
[foreign] |
For our students to graduate from high school is a huge step because their parents, they didn't even go to elementary school. |
We are changing people's lives. >> She is one of a kind. |
She is a really great teacher. |
She is like what we call our big mama. >> I think this class is very helpful because I just came from Mexico few years ago. >> Her teaching methods are |
like unique. |
She could teach us anything in a fun way and we'll get it faster than other classes. |
[clapping] >> Teaching in a intense charter school setting can almost be like dog years for a teacher. |
So spending four years here can be like spending ten years at uh, you know school that exhibits less challenges and it's not quite as intense. >> [foreign]. >> So, Misla being the longest of any veteran in our school having spent nine years here, I think that alone kind of encapsulates her dedication to our school's mission as well as our young people. >> [foreign] >> For more please visit us at stanford.edu. |
The President: |
Hello, Buckeyes! |
(applause) |
Yes. |
It is good to be back at The Ohio State University. |
(applause) |
I want to thank -- |
Audience Member: |
I love you! |
The President: |
I love you back. |
(applause) |
I am thrilled to be here. |
I want to thank a couple of people. |
First of all, the outstanding Mayor of Columbus, |
Michael Coleman, is here. |
(applause) |
I want to thank OSU Provost Joe Alutto. |
(applause) |
And I just got this extraordinary tour from |
Giorgio Rizzoni, who's the director of the Center for |
Automotive Research. |
So give him a big round of applause. |
(applause) |
Now, let's face it, a presidential visit isn't even close to being the biggest thing this weekend on campus. |
(laughter) |