Lecture 3

Greedy Algorithms

Minimum spanning tree (MST)

Given a connected, undirected graph, the minimum spanning tree is a fully connected tree where there are the minimum number of edges (weights should be considered too).


Applications of MST

General properties of MSTs

Cut Property: We have a set of $S$ vertices. We look at an edge $e$ as the minimum cost edge from $S$ to another set of vertices.

Cycle Property: If we have a cycle, then there is always an edge with the longest weight, which we can remove.

Cutset Intersection: The edges in the cycle that are also in the cutset.

Prim’s Algorithm (Dijkstra)

Initialise $S = $ any node. Apply the cut property to $S$. Add a minimum cost edge to the cutset and add one new explored node to $S$. Every time there’s a cutset intersection, we remove the most expensive edge



Example trace of the previously given graph


Analysis of Prim’s Algorithm

Runtime is $O(m \log n)$ with a binary heap. It is more likely $O(n^2)$ if using the basic array structure

Kruskal’s Algorithm

Consider edges in ascending order of weight

Case 1: If adding $e$ to $T$ creates a cycle, discard $e$.

Case 2: Otherwise, insert $e = (u,v)$ into $T$ according to the cut property.

Importantly, Kruskal’s algorithm will create disconnected components. Once there are no more available edges that don’t create a cycle, we are done



In this case, we use an efficient merge algorithm to merge sort the set.