Docsity

Minimum Spanning Trees, Exercises of Algorithms and Programming

Partial preview of the text

Download Minimum Spanning Trees and more Exercises Algorithms and Programming in PDF only on Docsity!

Minimum Spanning Trees

6 1 5 4 8 7 6 7 12 2 1 9 3

6 1 5 4 8 7 6 7 12 2 1 9 3 There is a cycle in this graph. It can’t be the cheapest way to link everything. There is a cycle in this graph. It can’t be the cheapest way to link everything.

A spanning tree in an undirected

graph is a set of edges with

no cycles that connects all nodes.

A minimum spanning tree (or MST ) is a

spanning tree with the least total cost.

Applications ●

Electric Grids

● Given a collection of houses, where do you lay wires to

connect all houses with the least total cost?

● This was the initial motivation for studying minimum

spanning trees in the early 1920's. (work done by Czech

mathematician Otakar Borůvka )

●

Data Clustering

●

More on that later...

●

Maze Generation

● More on that later…

● Computational Biology

●

More on that later...

Shortest-Path Trees and MSTs ● Last time, we saw how Dijkstra's algorithm and A* search can be used to find shortest path trees in a graph. ● Note that a shortest-path tree might not be an MST and vice-versa. 5 3 2 1

Minimum
spanning tree
in the graph.
Minimum
spanning tree
in the graph.

★

Finding an MST

Kruskal’s Algorithm:

Remove all edges from the graph.

Repeatedly find the cheapest edge that

doesn’t create a cycle and add it back.

The result is an MST of the overall graph.

Maintaining Connectivity ●

The key step in Kruskal's algorithm is

determining whether the two endpoints

of an edge are already connected to one

another.

●

Typical approach: break the nodes apart

into clusters.

● Initially, each node is in its own cluster. ● Whenever an edge is added, the clusters for the endpoints are merged together into a new cluster.

Time-Out for Announcements!

Final Exam Logistics ●

Final: Monday, March 20

th

, 8:30AM – 11:30AM, location TBA.
● Format is same as the midterm: closed-book, closed-
computer, limited-note. You get a single, double-sided sheet
of 8.5” × 11” notes decorated however you’d like.
● Cumulative exam, slightly focused on the post-midterm
topics.
● Covers topics from all assignments from this quarter.
● Covers topics from lectures up through and including today.

●

We will be holding a practice exam tonight in Hewlett 200
from 7PM – 10PM. The format of the practice final is similar
to the format of the actual final exam.
● Have OAE accommodations? We’ll reach out to you soon to
coordinate alternate exams.

Back to CS106B!

Applications of Kruskal's Algorithm