Solving problems on graph algorithms

Similar documents
Graph Algorithms (part 3 of CSC 282),

CS490 Quiz 1. This is the written part of Quiz 1. The quiz is closed book; in particular, no notes, calculators and cell phones are allowed.

Graphs. Edges may be directed (from u to v) or undirected. Undirected edge eqvt to pair of directed edges

Graph Algorithms (part 3 of CSC 282),

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms

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

Chapter 9 Graph Algorithms

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

The Shortest Path Problem. The Shortest Path Problem. Mathematical Model. Integer Programming Formulation

Minimum Spanning Trees

CS261: Problem Set #1

UNIT 5 GRAPH. Application of Graph Structure in real world:- Graph Terminologies:

Matching Theory. Figure 1: Is this graph bipartite?

Single Source Shortest Path: The Bellman-Ford Algorithm. Slides based on Kevin Wayne / Pearson-Addison Wesley

Assignment 1 Introduction to Graph Theory CO342

Solutions for the Exam 6 January 2014

Jessica Su (some parts copied from CLRS / last quarter s notes)

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

Introduction to Graph Theory

CS261: Problem Set #2

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

Lecture 3: Graphs and flows

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

Classic Graph Theory Problems

Chapter 5 Graph Algorithms Algorithm Theory WS 2012/13 Fabian Kuhn

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Shortest path problems

Weighted Graph Algorithms Presented by Jason Yuan

Graph and Digraph Glossary

Exam 3 Practice Problems

Minimum Cost Edge Disjoint Paths

Part II. Graph Theory. Year

Exam problems for the course Combinatorial Optimization I (DM208)

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

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

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Artificial Intelligence

6.2. Paths and Cycles

Communication Networks I December 4, 2001 Agenda Graph theory notation Trees Shortest path algorithms Distributed, asynchronous algorithms Page 1

Index. stack-based, 400 A* algorithm, 325

Chapter 4. Relations & Graphs. 4.1 Relations. Exercises For each of the relations specified below:

CMPSCI 311: Introduction to Algorithms Practice Final Exam

Discrete mathematics II. - Graphs

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

2. CONNECTIVITY Connectivity

Matching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

Introduction to Mathematical Programming IE406. Lecture 16. Dr. Ted Ralphs

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Introduction to Algorithms I

Questions Total Points Score

5.1 Min-Max Theorem for General Matching

Tutorial for Algorithm s Theory Problem Set 5. January 17, 2013

LECTURES 3 and 4: Flows and Matchings

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

AMS /672: Graph Theory Homework Problems - Week V. Problems to be handed in on Wednesday, March 2: 6, 8, 9, 11, 12.

Graphs: Introduction. Ali Shokoufandeh, Department of Computer Science, Drexel University

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

CS521 \ Notes for the Final Exam

Introduction Single-source shortest paths All-pairs shortest paths. Shortest paths in graphs

Week 11: Minimum Spanning trees

Problem Set 2 Solutions

from notes written mostly by Dr. Carla Savage: All Rights Reserved

Graph Theory. Part of Texas Counties.

The Matrix-Tree Theorem and Its Applications to Complete and Complete Bipartite Graphs

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

6.854J / J Advanced Algorithms Fall 2008

All Shortest Paths. Questions from exercises and exams

Homework 4 Solutions

Matchings in Graphs. Definition 1 Let G = (V, E) be a graph. M E is called as a matching of G if v V we have {e M : v is incident on e E} 1.

CS 125 Section #10 Midterm 2 Review 11/5/14

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

Lecture 6 Basic Graph Algorithms

CIS 121 Data Structures and Algorithms Midterm 3 Review Solution Sketches Fall 2018

Chapter 2 Graphs. 2.1 Definition of Graphs

Theorem 2.9: nearest addition algorithm

CME 305: Discrete Mathematics and Algorithms Instructor: Reza Zadeh HW#3 Due at the beginning of class Thursday 02/26/15

CS 125 Section #5 Graph Traversal and Linear Programs October 6, 2016

Fundamental Algorithms CSCI-GA /Summer Solution to Homework 8

0.0.1 Network Analysis

Graph Algorithms Matching

PERFECT MATCHING THE CENTRALIZED DEPLOYMENT MOBILE SENSORS THE PROBLEM SECOND PART: WIRELESS NETWORKS 2.B. SENSOR NETWORKS OF MOBILE SENSORS

CSE Winter 2015 Quiz 1 Solutions

Math 776 Graph Theory Lecture Note 1 Basic concepts

Jörgen Bang-Jensen and Gregory Gutin. Digraphs. Theory, Algorithms and Applications. Springer

An Introduction to Graph Theory

Analysis of Algorithms, I

Lecture 10,11: General Matching Polytope, Maximum Flow. 1 Perfect Matching and Matching Polytope on General Graphs

Algorithm Design (8) Graph Algorithms 1/2

Solution for Homework set 3

Assignment 5: Solutions

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

1 Digraphs. Definition 1

Network Flows. 1. Flows deal with network models where edges have capacity constraints. 2. Shortest paths deal with edge costs.

Homework 5: Graphs, Minimum Spanning Trees, and Dijkstra Shortest-Path

Number Theory and Graph Theory

Graphs and Algorithms 2016

Transcription:

Solving problems on graph algorithms Workshop Organized by: ACM Unit, Indian Statistical Institute, Kolkata. Tutorial-3 Date: 06.07.2017 Let G = (V, E) be an undirected graph. For a vertex v V, G {v} is the subgraph of G induced by V \{v}. For an edge e E, G e is the graph obtained by removing e from G. The diameter of a graph G is defined as max u,v V (G) δ(u, v) where δ(u, v) is the shortest path length between u and v. (*) marked problems will be discussed in this session. Problems on shortest path algorithms Q1 Suppose Dijkstras algorithm is run on the following graph, starting at node A. Show the final shortest-path tree. Q2 Suppose Bellman-Ford Algorithm is run on the following graph, starting at node A. Show the final shortest-path tree. Q3 Run the Floyd-Warshall algorithm on the weighted, directed graph in the following figure. Show the distance matrix D (k) that results for each iteration 1

of the outer loop. The distance matrix is defined as follows: D (0) weight of edge(i, j), if edge(i, j) exists [i, j] =, otherwise weight of the shortest path from vertex D (k) [i, j] = v i to v j using vertices {v 1, v 2,..., v k }, if a path exists, otherwise Q4 Give a O(n) time algorithm to compute the diameter of a tree with n vertices. Hint: Use BFS twice. Can you use same trick for general graphs? Q5 Let T be tree with n vertices. Desing an O(n 2 ) time algorithm to compute the shortest path length between all pairs of vertices in T. Hint: Use BFS using each vertex as root. Q6 Let G = (V, E) be a vertex-weighted undirected graph and u, v V (G) be two vertices. The length of any path P in G is the sum of the weights of the vertices in P. If all the weights are positive, can you modify Dijkstra s algorithm to find the shortest path between u, v in G? Compare the time complexity of your algorithm with that of Dijkstra s algorithm. Hint: Number the vertices as 1, 2,..., n. For each edge e = (i, j) with i < j, define weight of e as the weight of the vertex j. Q7 Let G = (V, E) be an edge-weighted graph where all edges have distinct positive weights, and u, v V be two vertices. Let P be a shortest path between u, v. Now suppose we replace the edge weight c e by c 2 e for each edge e E. Is it true that P will still be a shortest path between u and v in the new scenario? Hint: Consider the case when weights are distinct positive but less than 1. Q8 Let G = (V, E) be an edge-weighted undirected graph with m edges and u, v V be two vertices. Suppose all edge-weights in G are negative. Give an algorithm to compute the longest path between u and v. Hint: Make all weights positive and use shortest path algorithm. Argue that this algorithm is correct. 2

Q9 (*) In a connected undirected graph, shortest path between two vertices may not be unique. Given any positive intger n, construct a graph G n = (V n, E n ) such that V n = O(n) and there are two vertices u, v V n such that the number of different shortest paths beween u and v is Ω(2 n ). Given a connected undirected unweighted graph G = (V, E) and two vertices u, v V, devise an algorithm to count the number of uv shortest paths. Hint: For the second question use BFS. Q10 (*) Give an algorithm to find the shortest cycle in a graph. Hint: Use BFS with each vertex as root. This takes O(n 3 ) time. Can you find an algorithm that runs in O(n 2 ) time? Problems on minimum spanning tree (In all the following questions, assume G to be a connected undirected edge-weighted graph, V = n, E = m and the edge weight c e > 0 for all edge e E. MST stands for minimum weight spanning tree.) Q11 Let e be an edge of minimum-weight in E. Show that e is in some MST of G. Q12 Let e be an edge of G. Design an algorithm to test if there is a MST of G which contains e. Q13 Prove that if all edge-weights are distinct in G then G has a unique MST. Q14 Let T be any MST of a graph G, v be any vertex of G and e be edge incident on v with minimum weight. Prove that, e is an edge of T. Q15 (*) Let T be a MST of G. Suppose a new edge with positive weight is added between the vertices v, w of G to get a graph G. Design and analyze an algorithm to test if T is still an MST of G. Q16 Let the vertices of G are colored with either red or blue. Now compute a MST T of G such that there is no edge of T whose endpoints are of same color. Hint: Just delete the edges whose endpoints are of same color. Q17 A graph is hamiltonian if it has a path that visits each vertex exactly once. Let the edges of G are colored either red or blue. Suppose G has a spanning tree where no two edge of the same color share an endpoint. Prove that G is hamiltonian. Hint: Analyse the degree of any vertex in the spanning tree of G whose no two edge of the same color share an endpoint. 3

Q18 Let T, T be two different spanning trees of G. We say T and T are neighbours if T contains exactly one edge that is not in T, and T contains axactly one edge that is not in T. Now construct another undirected graph H G as follows. The vertices of H G are the spanning trees of G and there is an edge between two vertices of H G if the corresponding spanning trees are neighbours. Prove that H G is connected. Give an upper bound on the diameter and number of vertices of H G. Hint: Connectivity can be proved by showing that one spanning tree T can be transformed to another spanning tree T by a series of edge exchange (if e is an edge of T which is not present in T, then include e in T and delete some edge from T ). Diameter is at most n 1. The number of vertex in H G is the total number of spanning tree which is at most n n 2. See the book on Graph Theory by Douglas West. Q19 (*) Let G be a graph such that all the weights in the edges are either 0 or 1. Let there be two spanning trees of G, having costs i and j, i < j. Prove that for any k [i, j], there is a spanning tree of G with cost k. Give an algorithm to find a spanning tree of G with cost k. Your algorithm should output NO if no such tree exists. Hint: USe similar idea as previous question. Q20 For a spanning tree T, the bottleneck of T is the weight of the edge in T with maximum weight. A spanning tree T of G is a minimum-bottleneck spanning tree (MBST) if there is no spanning tree T of G with smaller bottleneck. Show that every MST is MBST but converse may not be true. Given a positive intger b, desing an O(m+n) algorithm to decide whether G has a spanning tree with bottleneck edge weight less than b. Modify the above algorithm to compute a MBST in O(m + n) time. Hint: For second question: delete all edge with weight greater than equal to b to get G. The graph G has a spanning tree with bottleneck edge weight less than b if and only if G is connected. For third question: Use linear time median finding algorithm to find the edge e with median weight. Then use previous hint and binary search. At each step of your algorithm the number of edges that you need to consider should get halved. Problems on network flows (Unless otherwise stated, a graph G = (V, E) is a directed graph with positive integer capacity c e on each edge e E, a pair of designated vertices s, t V, called source and sink. ) 4

(a) (b) Figure 1: (a) Question 21, (b) Question 22. Q21 Figure 1 shows a flow network on which an s t flow has been computed. The capacity of each edge appears as a label next to the edge, and the numbers in the boxes give the amount of flow sent on each edge. What is the value of this flow? graph? Is this a maximum (s, t) flow in this Find a minimum s-t cut in the flow network pictured in Figure 1(a), and also mention its capacity. Q22 Which of the cuts, shown in Figure 1(b), is a valid cut? List all of the valid cuts and their values. Q23 (*) Let G be a undirected bipartite graph. A matching M of G is a subset of the edges M E such that each node appears in at most one edge in M. The size of a matching M is the number of edges in M. The Bipartite Matching Problem is that of finding a matching in G of largest possible size. Formulate the bipartite matching problem using network flow problem. Hint: Let G(A B, E) be the graph. Add two vertices s and t. Now give directed edges from s to every vertex of A and from every vertex of B to t. Now try giving these edge capacities and see. Q24 A set of paths in a graph is said to be edge-disjoint if their edge sets are different. Given a directed graph G = (V, E) with two distinguised node s, t V, the Directed Edge-Disjoint Paths Problem is to find the maximum number of edge-disjoint s t paths in G. Formulate the Directed Edge-Disjoint Paths Problem using network flow problem. Hint: Give all the edges edge capacity 1 and run any maxflow algorithm. All the paths having the flow will be edge disjoint. Q25 For a graph G = (V, E), you are given an integer indicating the maximum s t flow in G. Suppose we pick a specific edge e E and increase its capacity by 1 unit. Give an algorithm to find the new maximum flow in O(m + n) time. 5

Hint: Find an augmenting path in the residual graph R. Now if there is an augmenting path, then there is a flow possible. Now push that flow and make the required changes in the graphs. Q26 Give a polynomial time algorithm to decide whether G has a unique minimum s t cut. Hint:Find a mincut. Now iteratively increase the weight of every edge in that cut set by 1, one by one and compute the mincut in every iteration. Now try finding out the condition when the graph will have a unique mincut. Q27 Let M be an n n matrix with each entry equal to either 0 or 1. Let m ij denote the entry in row i and column j. The diagonal entries are of the form m ii for i = 1, 2..., n. Swapping of rows i and j in the matrix M denotes the following action: swap the values of m ik and m jk for k = 1, 2,..., n. Swapping two columns is defined analogously. We say that M is re-arrangeable if it is possible to swap some pairs of rows and some pairs of columns (in any sequence) such that the diagonal entries of the resulting matrix M are all equal to 1. Give an example of a matrix M with at least one entry having value 1 in each row and each column, and which is not re-arrangeable. Give a polynomial-time algorithm to determine whether a matrix M with 0-1 entries is re-arrangeable. Hint: Relate the problem with bipartite matching. Q28 (*) Consider assigning interns to hospitals in the following situation. There are n interns and m hospitals. Hospital i has a requirement for d(i) interns, i = 1, 2, 3,..., m. A compatability graph is set up with edges (u, v) if intern u is compatible with hospital v. Suppose the graph has the following two properties: for a given integer k, (i) each intern is compatible with exactly k hospitals and (ii) hospital i is compatible with exactly k d(i) interns. Prove that it is always possible to assign each intern to a compatible hospital (use network flow). Illustrate for the case with n = 7, m = 3, d(1) = 3, d(2) = 2, d(3) = 2 and k = 2. Hint:We have a compatibility graph G. Let interns are in vertex set N and hospitals are in M. Now add two nodes s and t. Add directed edges from s to every vertex in N and assign each edge capacity 1. Now direct each edge from N to M and give them capacity 1. Now add a directed edge from each vertex of M to t and give them capacity 1. 6

Q29 Let G = (V, E) be a directed graph, and suppose that for each vertex v, the indegree of v is equal to the outdegree of v. In other words, for all v, {(u, v) : (u, v) E} = {(v, w) : (v, w) E} Let x, y be two vertices of G, and suppose that there exist k mutually edgedisjoint paths from x to y. Under these conditions, does it follow that there exist k mutually edge-disjoint paths from y to x? Give a proof, or a counterexample with explanation. Hint: Remove the edges of the k mutually edge-disjoint paths from v 1 to v 2 from the graph. Analyse the degree of the vertices in the resulting graph. 7