Graphs IICarnegie Mellon UniversityNovember 7, 2006Lecture 21CS 15-251 Fall 2006John LaffertyGreat Theoretical Ideas In Computer ScienceRecapTheorem: Let G be a graph with nnodes and e edges.The following are equivalent:1. G is a tree (connected, acyclic)2. Every two nodes of G are joined by a unique path3. G is connected and n = e + 14. G is acyclic and n = e + 15. G is acyclic and if any two nonadjacent points are joined by a line, the resulting graph has exactly one cycle.Cayley’s formulaThe number of labeled trees on n nodes is2nn−A graph is planarif it can be drawn in the plane without crossing edges. A plane graphis any such drawing, which breaks up the plane into a number fof facesor regionsEuler’s FormulaIf G is a connected plane graph with n vertices, e edges and f faces, then n - e + f = 2Euler’s Formula: If G is a connected plane graph with n vertices, e edges and f faces, then n - e + f = 2The beauty of Euler’s formula is that it yields a numericproperty from a purely topologicalproperty.Graph ColoringA coloring of a graph is an assignment of a color to each vertex such that no neighboring vertices have the same color.Finding Optimal Trees•Trees have many nice properties (uniqueness of paths, no cycles, etc.)•May want to compute the “best” tree approximation to a graph•If all we care about is communication, then a tree may be enough. Want tree with smallest communication link costs.Finding Optimal TreesProblem: Find a minimum spanning tree, that is, a tree that has a node for every node in the graph, such that the sum of the edge weights is minimum.Tree Approximations48796119587Finding an MST: Kruskal’s Algorithm•Create a forest where each node is a separate tree•Make a sorted list of edges S•While S is non-empty:– Remove an edge with minimal weight– If it connects two different trees, add the edge. Otherwise discard it.Applying the Algorithm18791035479Analyzing the Algorithm•The algorithm outputs a spanning tree T. Suppose that it’s not minimal. (For simplicity, assume all edge weights in graph are distinct). •Let M be a minimum spanning tree. •Let e be the first edge chosen by the algorithm that is not in M. If we add e to M, it creates a cycle. Since this cycle isn’t fully contained in T, it has an edge f not in T.•N = M+e-f is another spanning tree.Analyzing the Algorithm17, e89103547fAnalyzing the Algorithm•N = M+e-f is another spanning tree.•Claim: e < f, and therefore N < M•Suppose not: e > f•Then f would have been visited before e by the algorithm, but not added, because adding it would have formed a cycle.•But all of these cycle edges are also edges of M, since e was the first edge not in M. This contradicts the assumption M is a tree.Greed is Good (In this case…)The greedy algorithm, by adding the least costly edges in each stage, succeeds in finding an MST.But--in math and life--if pushed too far, the greedy approach can lead to bad results.The Greedy Traveling SalesmanTours from TreesWe can use an MST to derive a tour that is no more expensive than twicethe optimal tour.Idea: walk “around” the MST and take shortcuts if a node has already been visited.We assume that all pairs of nodes are connected, and edge weights satisfy the triangle inequalityd(x,y) <= d(x,z) + d(z,y)Tours from TreesShortcuts only decrease the cost, so Cost(Greedy Tour) 2 Cost(MST) 2 Cost(Optimal Tour)This is a 2-competitivealgorithmDancing PartnersA group of 100 boys and girls attend a dance. Every boy knows 5 girls, and every girl knows 5 boys. Can they be matched into dance partners so that each pair knows each other?Dancing PartnersPerfect MatchingsTheorem: If every node in a bipartite graph has the same degree d >= 1, then the graph has a perfect matching.Note: if degrees are the same then |A| = |B|, where A is the set of nodes “on the left” and B is the set of nodes “on the right”A Matter of DegreeClaim: If degrees are the same then |A| = |B|.The Marriage Theorem(or, “What’s Love Got to Do With it?”)Each woman would happily marry some subset of the men, and any man would be happy to marry any woman who would be happy with him. Is it possible to match the men and women into pairs of happy couples?The Marriage TheoremTheorem: A bipartite graph has a perfect matching if and only if |A| = |B| and for any subset of (say) k nodes of A there are at least k nodes of B that are connected to at least one of them.The Marriage TheoremThe condition fails for this graph.The Feeling is MutualThe condition of the theorem still holds if we swap the roles of A and B: If we pick any k nodes in B, they are connected to at least k nodes in A.kAt most n-kn-kAt least kProof of Marriage TheoremCall a bipartite graph “matchable” if it has the same number of nodes on left and right, and any k nodes on the left are connected to at least k on the right.Strategy: Break up the graph into two matchableparts, and recursively partition each of these into two matchable parts, etc., until each part has only two nodes.Proof of Marriage Theorem•Select two nodes a ∈ A and b ∈ B connected by an edge.•Idea: Take G1= (a,b) and G2= everything else•Problem: G2need not be matchable. There could be a set of k nodes that has only k-1 neighbors.Proof of Marriage Theoremk-1kThe only way this could fail is if one of the missing nodes is b. Add this in to form G1, and take G2 to be everything else.This is a matchablepartition!abGeneralized Marriage: Hall’s TheoremLet S = {S1, S2, …} be a set of finite subsets that satisfies: For any subset T = {Ti} of S, | UTi| >=|T|. Thus, any k subsets contain at least k elements. Then we can choose an element xi∈ Sifrom each Siso that {x1, x2, …} are all distinct.ExampleSuppose that a standard deck of cards is dealt into 13 piles of 4 cards each.Then it is possible to select a card from each pile so that the 13 chosen cards contain exactly one card of each rank.Graph SpectraFinally, we’ll discuss a different representationof graphs that is extremely powerful, and useful in many areas of computer science: AI, information retrieval, computer vision, machine learning, CS theory,…Adjacency matrixSuppose we have a graph G with n vertices and edge set E. The adjacency matrixis the nxn matrix A=[aij] withaij= 1 if (i,j) is an edgeaij= 0 if (i,j) is not an edgeExampleCounting PathsThe number of paths of length k from node i to node j is the entry in
View Full Document