Network Algorithms Tutorial 2: Trees Christian Rieck—May 03, 2018 Minimum Spanning Tree
Total Page:16
File Type:pdf, Size:1020Kb
Institute of Operating Systems and Computer Networks Algorithms Group Network Algorithms Tutorial 2: Trees Christian Rieck—May 03, 2018 Minimum Spanning Tree Network Algorithms—Tutorial 2: Trees 2 May 03, 2018 Minimum Spanning Tree if there is more than one possible edge, choose the one with the v0,v2 =9 { } smallest concatenated index… v0,v5 =11 { } v2 v0,v8 =9 { } v v v1,v2 =5 1 3 { } v1,v6 =3 { } v1,v9 =7 { } v ,v =5 v9 v 2 3 v 4 { } 0 v3,v4 =5 { } v3,v7 =3 { } v4,v5 =13 v8 v5 { } v4,v9 =5 { } v5,v6 =17 { } v v v6,v7 =2 7 6 { } v7,v8 =9 { } v8,v9 =7 { } Network Algorithms—Tutorial 2: Trees 3 May 03, 2018 Kruskal v0,v2 =9 { } v0,v5 =11 { } v2 v0,v8 =9 4 { } v 5 v v1,v2 =5 1 3 { } 10 v1,v6 =3 8 3 { } 6 v1,v9 =7 { } v ,v =5 v9 v 2 3 v 7 4 { } 0 v3,v4 =5 { } 9 v3,v7 =3 13 { } 11 v4,v5 =13 v8 v5 { } 2 v4,v9 =5 { } 12 v5,v6 =17 { } v7 1 v6 v6,v7 =2 { } v7,v8 =9 { } v8,v9 =7 { } Network Algorithms—Tutorial 2: Trees 4 May 03, 2018 Path compression …after finding the root r of the tree containing x, change the parent pointer of all nodes along the path to point directly to r… r r z x z y T0 y T3 T1 x T1 T2 T2 before path-compression after path-compression With path compression, the union-find data structure provides near- constant-time operations bounded by the inverse Ackermann function. Network Algorithms—Tutorial 2: Trees 5 May 03, 2018 Prim v0,v2 =9 { } v0,v5 =11 { } v2 v0,v8 =9 2 6 { } v v v1,v2 =5 1 3 { } v1,v6 =3 9 7 { } 1 v1,v9 =7 5 { } v ,v =5 v9 v 2 3 v 8 4 { } 3 0 v3,v4 =5 { } 10 v3,v7 =3 11 { } 13 v4,v5 =13 v8 v5 { } v4,v9 =5 { } 12 v5,v6 =17 { } v 4 v v6,v7 =2 7 6 { } v7,v8 =9 { } v8,v9 =7 { } Network Algorithms—Tutorial 2: Trees 6 May 03, 2018 Special graphs Network Algorithms—Tutorial 2: Trees 7 May 03, 2018 Petersen graph Donald Knuth: „[..] a remarkable configuration that serves as a counterexample to many optimistic predictions about what might be true for graphs in general.“ Network Algorithms—Tutorial 2: Trees 8 May 03, 2018 Unit-distance graph … is a graph which can be drawn in the plane such that the length of each edge is exactly 1. Two embeddings of the Petersen graph showing that it is a unit distance graph. It is NP-hard to decide whether a given graph is a unit distance graph or not. Network Algorithms—Tutorial 2: Trees 9 May 03, 2018 Matchstick graph A unit distance graph with the additional property that it can be drawn in the plane without crossings. smallest cubic matchstick graph smallest 4-regular matchstick graph “Harborth graph“ Network Algorithms—Tutorial 2: Trees 10 May 03, 2018 Other tree problems Network Algorithms—Tutorial 2: Trees 11 May 03, 2018 Maximum Spanning Tree Given: A weighted graph G=(V,E) Wanted: A maximum spanning tree T By multiplying the edge weights by -1, one can solve this problem by applying Kruskal’s algorithm on this modified graph. So, this problem is quite easy. Network Algorithms—Tutorial 2: Trees 12 May 03, 2018 Bottleneck Spanning Tree Given: A weighted graph G=(V,E) Wanted: A spanning tree in which all edges have weight at most b 4 4 9 9 5 1 4 5 1 4 2 9 2 9 6 7 3 6 7 3 8 8 4 2 9 10 4 2 9 10 3 9 3 9 9 9 18 9 9 18 8 8 G BST with b = 8 Network Algorithms—Tutorial 2: Trees 13 May 03, 2018 Bottleneck Spanning Tree Theorem: An MST is a MBST. We show this by contradiction. Assume that T is not an MBST in G, then T is not an MST in G as well. Therefor, let e be the most expensive edge in T. There are two trees T1 and T2 such that e connects them in T. Since T is no MBST, there must be an edge e’ with weight w(e’) < w(e) and e’ connects T1 and T2 as well; let this tree be T’. Then w(T) - w(T’) = w(e) - w(e’) > 0. So, T is no MST in G. Network Algorithms—Tutorial 2: Trees 14 May 03, 2018 Bottleneck Spanning Tree And vice versa? Is an MBST in G also an MST in G? No, not necessarily. The following graph is a counterexample: 1 2 1 2 2 2 2 G MST BST Network Algorithms—Tutorial 2: Trees 15 May 03, 2018 Bottleneck Spanning Tree Question: Is there a Bottleneck Spanning Tree with a bottleneck of weight b? This is a decision problem! ‣ delete all edges with weight greater than b ‣ if the remaining graph is connected ‣ yes, there is such a bottleneck spanning tree ‣ else ‣ nope, no such spanning tree exists Network Algorithms—Tutorial 2: Trees 16 May 03, 2018 Minimum Bottleneck Spanning Tree Given: A weighted graph G=(V,E) Wanted: A bottleneck spanning tree T in which the most expensive edge is as cheap as possible This is an optimization problem. One can use Camerini’s algorithm to compute the MBST of a graph G in O(E) time. Network Algorithms—Tutorial 2: Trees 17 May 03, 2018 Minimum Degree Spanning Tree Given: A weighted graph G=(V,E) Wanted: A spanning tree T which has the least max degree This problem is NP-hard. ‣ reduction from the Hamiltonian path problem ‣ G has HP iff G has MDST with degree at most two ‣ generalizable to arbitrary k by adding k-2 vertices per vertex The problem is in NP. ‣ guess a solution and verify it in polynomial time Network Algorithms—Tutorial 2: Trees 18 May 03, 2018 Minimum Degree Spanning Tree Since the problem is NP-hard and in NP, it is NP-complete. So, on the negative side, we know that we cannot solve the problem to optimality. On the positive one, there is an approximation algorithm which gives a solution to the problem with max-degree = OPT+1, where OPT is the maximum degree in an optimal solution. Martin Fürer and Balaji Raghavachari (SODA’92) — Approximating the minimum degree spanning tree to within one from the optimal degree. Network Algorithms—Tutorial 2: Trees 19 May 03, 2018 Minimum Degree Spanning Tree Since the problem is NP-hard and in NP, it is NP-complete. So, on the negative side, we know that we cannot solve the problem to optimality. On the positive one, there is an approximation algorithm which gives a To see much more algorithms like this, please participate in solutionthe lecture to the on problem approximation with algorithmsmax-degree given = byOPT+1 Prof. ,Fekete! where OPT is the maximum degree in an optimal solution. Martin Fürer and Balaji Raghavachari (SODA’92) — Approximating the minimum degree spanning tree to within one from the optimal degree. Network Algorithms—Tutorial 2: Trees 19 May 03, 2018 Minimum Steiner Tree Given: A weighted graph G=(V,E) and T V(G) ✓ Wanted: A Steiner tree S for T with T✓ V(S) ✓ V(G) and E(S) ✓ E(G) of minimum weight. The elements of T are called the terminals and the elements of V(S)\T are called Steiner vertices of S. The minimum Steiner tree problem is NP-complete! Special cases: ‣ |T| = 2, we want to know the shortest path ‣ |T| = |V|, we want to know the MST Network Algorithms—Tutorial 2: Trees 20 May 03, 2018 Minimum Steiner Tree The blue vertices are terminals, the Steiner vertices are orange, and the red edges induce the Steiner tree. 2 1 1 1 1 1 1 1 1 1 1 2 1 Network Algorithms—Tutorial 2: Trees 21 May 03, 2018 Minimum Steiner Tree What happens in the plane? Given: n points in the plane Wanted: A minimum Steiner tree 120 1 1 1 MST optimal? MinSteiner tree! It is an NP-hard problem! Network Algorithms—Tutorial 2: Trees 22 May 03, 2018 Minimum Steiner Tree What do we know about Steiner vertices in the plane? ‣ there are exactly three edges incident to every Steiner vertex and they form three 120 degree angles ‣ there are no angles with less than 120 degree in an optimal Steiner tree Network Algorithms—Tutorial 2: Trees 23 May 03, 2018 Minimum Steiner Tree There are probably infinitely many different variants of Steiner tree problems. And there are many surveys on this topic. Almost all variants are NP-hard, but often we can compute a good approximation! For example, there is a PTAS (polynomial-time approximation scheme) for the Euclidean Steiner tree problem, i.e., there is an algorithm which computes a solution within (1+e)*OPT for any e greater than zero. Network Algorithms—Tutorial 2: Trees 24 May 03, 2018 Minimum Steiner Tree There are probably infinitely many different variants of Steiner tree problems. And there are many surveys on this topic. Almost all variants are NP-hard, but often we can computeGuillotine a Subdivisions good approximation! Approximate Polygonal Subdivisions: A simple polynomial-time approximation scheme for geometric TSP, k-MST, and related problems — Joe Mitchell (SODA’96) For example, there is a PTAS (polynomial-time approximation Again, to see much more algorithms like this, please participate in scheme) forthe thelecture Euclidean on approximation Steiner algorithms tree given problem, by Prof.