10/30/2009115-251Great Theoretical Ideas in Computer ScienceGraphs IILecture 19, October 27, 2009RecapTheorem: Let G be a graph with n nodes and e edgesThe following are equivalent:1. G is a tree (connected, acyclic)3. G is connected and n = e + 14. G is acyclic and n = e + 15. G is acyclic and if any two non-adjacent points are joined by a line, the resulting graph has exactly one cycle2. Every two nodes of G are joined by a unique pathThe number of labeled trees on n nodes is nn-2Cayley’s FormulaA graph is planar ifit can be drawn in the plane without crossing edges10/30/20092http://www.planarity.netPlanar Graphs Euler’s FormulaIf G is a connected planar graph with n vertices, e edges and f faces, then n – e + f = 2A coloring of a graph is an assignment of a color to each vertex such that no neighboring vertices have the same colorGraph ColoringSpanning TreesA spanning tree of a graph G is a tree that touches every node of G and uses only edges from GEvery connected graph has a spanning treeImplementing GraphsAdjacency MatrixSuppose we have a graph G with n vertices. The adjacency matrix is the n x n matrix A=[aij] with:aij= 1 if (i,j) is an edgeaij= 0 if (i,j) is not an edgeGood for dense graphs!10/30/20093ExampleA =0 1 1 11 0 1 11 1 0 11 1 1 0Counting PathsThe number of paths of length k from node i to node j is the entry in position (i,j) in the matrix AkA2=0 1 1 11 0 1 11 1 0 11 1 1 00 1 1 11 0 1 11 1 0 11 1 1 03 2 2 22 3 2 22 2 3 22 2 2 3=Adjacency ListSuppose we have a graph G with n vertices. The adjacency list is the list that contains all the nodes that each node is adjacent toGood for sparse graphs!Example12341: 2,32: 1,3,43: 1,2,44: 2,3http://www.math.ucsd.edu/~fan/hear/“Can you hear the shape of a graph?”Graphical MuzakFinding Optimal TreesTrees have many nice properties (uniqueness of paths, no cycles, etc.)We may want to compute the “best” tree approximation to a graphIf all we care about is communication, then a tree may be enough. We want a tree with smallest communication link costs10/30/20094Finding 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 minimum48796119587Tree ApproximationsKruskal’s AlgorithmA simple algorithm for finding a minimum spanning treeFinding an MST: Kruskal’s AlgorithmCreate a forest where each node is a separate treeMake a sorted list of edges SWhile S is non-empty:Remove an edge with minimal weightIf it connects two different trees, add the edge. Otherwise discard it.18791035479Applying the AlgorithmAnalyzing the AlgorithmThe algorithm outputs a spanning tree T. Let M be a minimum spanning tree.Let e be the first edge chosen by the algorithm that is not in M. N = M+e-f is another spanning tree.Suppose that it’s not minimal. (For simplicity, assume all edge weights in graph are distinct)If we add e to M, it creates a cycle. Since this cycle isn’t fully contained in T, it has an edge fnot in T.10/30/20095Analyzing the AlgorithmN = M+e-f is another spanning tree.Claim: e < f, and therefore N < MSuppose not: e > fThen 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 MSTBut — in math and life — if pushed too far, the greedy approach can lead to bad results. TSP: Traveling Salesman ProblemGiven a number of cities and the costs of traveling from any city to any other city, what is the cheapest round-trip route that visits each city exactly once and then returns to the starting city? TSP from TreesWe can use an MST to derive a TSP tour that is no more expensive than twice the 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 inequality d(x,y) ≤ d(x,z) + d(z,y)Tours from TreesThis is a 2-competitive algorithmShortcuts only decrease the cost, so Cost(Greedy Tour) ≤ 2 Cost(MST) ≤ 2 Cost(Optimal Tour)Bipartite GraphA graph is bipartite if the nodes can be partitioned into two sets V1and V2such that all edges go only between V1and V2(no edges go from V1to V1or from V2to V2)10/30/20096Dancing 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 matching is a set of edges, no two of which share a vertex. The matching is perfect if it includes every vertex.If there are m boys, there are md edgesIf there are n girls, there are nd edgesProof:Claim: If degrees are the same then |A| = |B|A Matter of DegreeWe’ll now prove a stronger result...The Marriage TheoremTheorem: A bipartite graph has a perfect matching if and only if |A| = |B| = n and for all k ∈ [1,n]: for any subset of k nodes of Athere are at least k nodes of B that are connected to at least one of them.The condition fails for this graphThe Marriage TheoremFor any subset of (say) k nodes of A there are at least k nodes of B that are connected to at least one of them10/30/20097kAt most n-kn-kAt least kThe 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 AThe Feeling is MutualProof 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 rightStrategy: Break up the graph into two matchable parts, and recursively partition each of these into two matchable parts, etc., until each part has only two nodesProof of Marriage TheoremSelect two nodes a ∈ A and b ∈ B connected by an edgeIdea: Take G1= (a,b) and G2= everything elseProblem: G2need not be matchable. There could be a set of k nodes that has only k-1 neighbors. k-1kabThe only way this could fail is if one of the
View Full Document