Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Similar documents
Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Chapter 23. Minimum Spanning Trees

CS 561, Lecture 9. Jared Saia University of New Mexico

Minimum Spanning Trees My T. UF

CS261: A Second Course in Algorithms Lecture #16: The Traveling Salesman Problem

Minimum Spanning Trees

Notes 4 : Approximating Maximum Parsimony

Approximation Algorithms

6.1 Minimum Spanning Trees

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

1 Variations of the Traveling Salesman Problem

Theorem 2.9: nearest addition algorithm

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Travelling Salesman Problem. Algorithms and Networks 2015/2016 Hans L. Bodlaender Johan M. M. van Rooij

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Minimum Spanning Trees

Traveling Salesman Problem. Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij

Design and Analysis of Algorithms

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

Autumn Minimum Spanning Tree Disjoint Union / Find Traveling Salesman Problem

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

Minimum spanning trees

Notes for Lecture 24

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

Introduction to Optimization

1 Better Approximation of the Traveling Salesman

The minimum spanning tree problem

Introduction to Graph Theory

Algorithms for Minimum Spanning Trees

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

We ve done. Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding

NP-Hard (A) (B) (C) (D) 3 n 2 n TSP-Min any Instance V, E Question: Hamiltonian Cycle TSP V, n 22 n E u, v V H

Introduction to Optimization

Week 11: Minimum Spanning trees

CS 6783 (Applied Algorithms) Lecture 5

Minimum Spanning Trees

Math 776 Graph Theory Lecture Note 1 Basic concepts

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

Lecture Notes for Chapter 23: Minimum Spanning Trees

CMSC 451: Lecture 22 Approximation Algorithms: Vertex Cover and TSP Tuesday, Dec 5, 2017

CS270 Combinatorial Algorithms & Data Structures Spring Lecture 19:

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Minimum Spanning Trees

Lecture 8: The Traveling Salesman Problem

Institute of Operating Systems and Computer Networks Algorithms Group. Network Algorithms. Tutorial 4: Matching and other stuff

Lecture 3: Graphs and flows

Optimal tour along pubs in the UK

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

Introduction to Graphs

Context: Weighted, connected, undirected graph, G = (V, E), with w : E R.

Graph Algorithms. Tours in Graphs. Graph Algorithms

Varying Applications (examples)

Approximation Algorithms

Outline. Graphs. Divide and Conquer.

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

Minimum Spanning Trees

(Refer Slide Time: 01:00)

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1

Notes for Recitation 9

Traveling Salesperson Problem (TSP)

2 Approximation Algorithms for Metric TSP

looking ahead to see the optimum

V1.0: Seth Gilbert, V1.1: Steven Halim August 30, Abstract. d(e), and we assume that the distance function is non-negative (i.e., d(x, y) 0).

Traveling Salesman Problem (TSP) Input: undirected graph G=(V,E), c: E R + Goal: find a tour (Hamiltonian cycle) of minimum cost

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

More NP-complete Problems. CS255 Chris Pollett May 3, 2006.

How can we lay cable at minimum cost to make every telephone reachable from every other? What is the fastest route between two given cities?

Questions? You are given the complete graph of Facebook. What questions would you ask? (What questions could we hope to answer?)

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Classic Graph Theory Problems

Module 6 NP-Complete Problems and Heuristics

Complexity of Prim s Algorithm

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

22 Elementary Graph Algorithms. There are two standard ways to represent a

Advanced Algorithms Class Notes for Monday, October 23, 2012 Min Ye, Mingfu Shao, and Bernard Moret

Best known solution time is Ω(V!) Check every permutation of vertices to see if there is a graph edge between adjacent vertices

CS6702 GRAPH THEORY AND APPLICATIONS 2 MARKS QUESTIONS AND ANSWERS

23.2 Minimum Spanning Trees

Partha Sarathi Mandal

22 Elementary Graph Algorithms. There are two standard ways to represent a

Assignment 5: Solutions

Chapter 11: Graphs and Trees. March 23, 2008

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Chapter 9 Graph Algorithms

Introduction to Algorithms

Graphs and Isomorphisms

Brief History. Graph Theory. What is a graph? Types of graphs Directed graph: a graph that has edges with specific directions

EECS 203 Lecture 20. More Graphs

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

Number Theory and Graph Theory

Chapter 3: Paths and Cycles

NP Completeness. Andreas Klappenecker [partially based on slides by Jennifer Welch]

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Announcements Problem Set 5 is out (today)!

Matching 4/21/2016. Bipartite Matching. 3330: Algorithms. First Try. Maximum Matching. Key Questions. Existence of Perfect Matching

Transcription:

Theory of Computing Lecture 10 MAS 714 Hartmut Klauck

Seven Bridges of Königsberg Can one take a walk that crosses each bridge exactly once?

Seven Bridges of Königsberg Model as a graph Is there a path that traverses each edge exactly once? Original problem allows different start and end vertex Answer is no.

Euler Tours For an undirected graph G=(V,E) an Euler tour is a path that traverses every edge exactly once, and ends at the same vertex as it starts Same definition for directed graphs Graph G is Eulerian if it has an Euler tour

Euler tours Theorem: an undirected graph is Eulerian, iff all vertices have even degree and all vertices of nonzero degree are in the same connected component. Proof: Clearly the condition is necessary. To see that it is sufficient we will give an algorithm that will find an Euler tour in linear time.

Finding an Euler tour Start at some vertex v 1, follow any edge {v i,v i+1 } until v 1 is reached again (initial tour) On the way mark edges as used and vertices as visited At this time some edges may be unused Find any vertex on the tour with unused edges and start a path from it until a cycle is formed Join the new cycle with the tour Continue until no vertex on the tour has any unused edges By assumption there are no unvisited vertices with degree>0 Why don t we get stuck? Every vertex has even degree

Implementation Store the tour as a (doubly) linked list T initially empty, linked forward and backward Augment the adjacency list A to store also pointers from the vertices to an occurrence in T and their degree (if nonzero) For visited vertices Delete a vertex if degree is 0 Create the initial tour while traversing the graph from some vertex Delete used edges from the adjacency list and update degrees Continue with a vertex v with nonzero degree and find a cycle, and insert the cycle from v to v into T

Time An Euler tour can be found in time O(n+m)

Minimum spanning trees Definition A spanning tree of an undirected connected graph is a set of edges E µ E: E forms a tree every vertex is in at least one edge in E When the edges of G have weights, then a minimum spanning tree is a spanning tree with the smallest sum of edge weights

MST Motivation: measure costs to establish connections between vertices Basic procedure in many graph algorithms Problem first studied by Boruvka in 1926 Other algorithms: Kruskal, Prim Inputs: adjacency list with weights

Application Example Traveling Salesman Problem [TSP] Input: matrix of edge weights and number K Decision: is there a path through the graph that visits each vertex once and has cost at most K? Problem is believed to be hard i.e., not solvable in polynomial time

Application Example Metric TSP (Traveling Salesman Problem) weights form a metric (symmetric, triangle inequality) Still believed to be hard Approximation algorithm: Find an MST T Replace each edge of T by two edges Traverse T in an Euler tour of these 2(n-1) edges Make shortcuts to generate a cycle that goes through all vertices once Euler tour cost is twice the MST cost, hence at most twice the TSP cost, shortcuts cannot increase cost

MST Generic algorithm: Start with an empty set of edges Add edges, such that current edge set is always subset of a minimum spanning tree Edges that can be added are called safe

Generic Algorithm Set A=; As long as A is not (yet) a spanning tree add a safe edge e Output A

Safe Edges How can we find safe edges? Definition: A cut C=(S, V-S) is a partition of V A set of edges repects the cut, if no edge crosses An edge is light for a cut, if it is the edge with smallest weight that crosses the cut Example: red edges respect the cut

Safe Edges Theorem: Let G be an undirected connected weighted graph. A a subset of a minimum spanning tree. C=(S, V-S) a cut that A respects. Then the lightest edge of C is safe. Proof: T is an MST containing A Suppose e is not in T (otherwise we are done) Construct another MST that contains e

Safe Edges Inserting e={u,v} into T creates a cycle p in T[{e} u and v are on different sides of the cut Another edge e in T crosses the cut e is not in A (A respects the cut) Remove e from T (T is now disconnected into 2 trees) Add e to T (the two trees reconnect into one) W(e)=W(e ), so T is also minimal Hence A[{e} subset of T e is safe for A.

Which edges are not in a min. ST? Theorem: G a graph with weights W. All edge weights distinct. C a cycle in G and e={u,v} the largest edge in C. Then e is in no minimum spanning tree. Proof: Assume e is in a min. ST T Remove e from T Result is two trees (containing all vertices) The vertices of the two trees form a cut Follow C-{e} from u to v Some edge e crosses the cut T-{e}[{e } is a spanning tree with smaller weight T

Algorithms We complete the algorithm skeleton in two ways Prim: A is always a tree Kruskal: A starts as a forest that joins into a single tree initially every vertex its own tree join trees until all are joined up

Data structures: Union-Find We need to store a set of disjoint sets with the following operations: Make-Set(v): generate a set {v}. Name of the set is v Find-Set(v): Find the name of the set that contains v Union(u,v): Join the sets named u and v. Name of the new set is either u or v As with Dijkstra/priority queues the running time will depend on the implementation of the data structure

Kruskal 1. Input: graph G, weights W:E R 2. A=; 3. For each vertex v: a) Make-Set(v) 4. Sort edges in E (increasing) by weight 5. For all edges {u,v} (order increasing by weight): a) a=findset(u), b=findset(v) b) If a b then A:=A[ {{u,v}} Union(a,b) 6. Output A

Running time Kruskal We will have: until 3: O(n) times Time for Make-Set 4: O(m log n) 5: O(m) time Time for Find/Union Total will be O(n+m log n)

Correctness We only have to show that all edges inserted are safe Choose a cut respected by A, which is crossed by the new edge e e has minimum weight under all edges forming no cycle, hence e has minimum weight among all edges crossing the cut Hence e must be safe for A