

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Algorithm Design and Analysis 4/1/
Instructor: Mike Kowalczyk
A set is a collection of elements. You can think of it as an array, except the elements are not ordered. If A is a set with the element b in it, we can denote this by b ā A. If every element of A is in the set B, A is said to be a subset of B, denoted by A ā B or B ā A.
A graph is a pair: (V, E), where V is the set of vertices, and E is the set of edges. Usually youāll see āLet G = (V, E) be a graph...ā. When someone says āgraphā they usually mean āsimple graphā, meaning no self-loops, undirected edges, and no multiple edges between a single pair of vertices.
A path on a simple graph G = (V, E) is a sequence of vertices (v 0 , v 1 , v 2 , Ā· Ā· Ā· , vk) where each vi ā V and each (vi, vi+1) ā E. A cycle is a path that starts and ends at the same vertex (v 0 = vk). A simple path is a path where no vertex is repeated (vi 6 = vj if i 6 = j). A simple cycle is a cycle where only the start and end vertices are identical, and k ā„ 3 (this avoids an edge getting used twice).
Trees have many equivalent definitions. For example:
Suppose we are given a connected graph G = (V, E) and each edge e ā E has an associated weight we ā R. We would like to find a tree T = (V, Eā²) where Eā²^ ā E (called a spanning tree), of minimum weight (meaning we are minimizing the sum of all the weights of the constituent edgesā
eāEā²^ we). We will use a greedy approach. The algorithm will be to sort the edges increasing by weight, and add the lowest cost remaining edge, if it doesnāt introduce a cycle.
Letās prove correctness. First, letās convince ourselves we actually get a tree. By definition, the algorithm never introduces a cycle (it checks each time it adds an edge). Now how do we know that T is connected? If thereās a vertex v ā V with no edge is āgoing to itā, then introducing an edge āgoing to itā will not create a cycle, hence the algorithm will add that edge (we know thereās an edge going to it because G is connected). Note: this part of the argument isnāt entirely correct or complete. Fix it as a homework exercise. Now, letās see if itās a minimum cost tree that we construct. Let T = (V, Eā²) be the tree constructed by the algorithm. Let OP T = (V, Eā²ā²) be an optimal spanning tree. Assume that OP T 6 = T and let e ā Eā²^ be the first edge added to T which is not in the edge set of OP T (i.e. e /ā Eā²ā²). Since OP T is a tree, it has a path P from one vertex of e to the other, and e is not traversed by this path. This path P contains some edge eā²^ ā/ Eā²^ (otherwise T would have a simple cycle). Now, if we modify OP T by removing eā²^ and adding e, and we still have a tree (any vertex still has a path to any other, and we have the same number of edges). Furthermore, we ⤠weā² because our algorithm would have choosen eā²^ first otherwise. This modification to OP T maintains optimality, and therefore every step of the algorithm leads to an optimal spanning tree. The runtime is straightforward to analyze, and depends on the selection of data structures used to implement the algorithm.