Algorithms for Enumerating All Spanning Trees of Undirected and Weighted Graphs Presented by R97922102 李孟哲 R97922104 陳翰霖 R97922124 張仕明 Sanjiv Kapoor and.

Slides:



Advertisements
Similar presentations
Chapter 13. Red-Black Trees
Advertisements

Chapter 5: Tree Constructions
An Algorithm for enumerating All Spanning Trees of a Directed Graph - S. Kapoor and H. Ramesh Speakers: 李孟韓 1, 林蔚茵 2, 莊秋芸 3, 黃稚穎 4.
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Greedy Algorithms Greed is good. (Some of the time)
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
Graph Searching (Graph Traversal) Algorithm Design and Analysis Week 8 Bibliography: [CLRS] – chap 22.2 –
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
A Randomized Linear-Time Algorithm to Find Minimum Spanning Trees David R. Karger David R. Karger Philip N. Klein Philip N. Klein Robert E. Tarjan.
Discussion #36 Spanning Trees
Minimum Spanning Trees Definition Algorithms –Prim –Kruskal Proofs of correctness.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Binary Trees A binary tree is made up of a finite set of nodes that is either empty or consists of a node called the root together with two binary trees,
Dynamic Sets and Data Structures Over the course of an algorithm’s execution, an algorithm may maintain a dynamic set of objects The algorithm will perform.
Minimal Spanning Trees. Spanning Tree Assume you have an undirected graph G = (V,E) Spanning tree of graph G is tree T = (V,E T E, R) –Tree has same set.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 Chapter 8 Priority Queues. 2 Implementations Heaps Priority queues and heaps Vector based implementation of heaps Skew heaps Outline.
Important Problem Types and Fundamental Data Structures
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Heapsort Based off slides by: David Matuszek
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
I/O-Efficient Graph Algorithms Norbert Zeh Duke University EEF Summer School on Massive Data Sets Århus, Denmark June 26 – July 1, 2002.
MST Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
1 Trees A tree is a data structure used to represent different kinds of data and help solve a number of algorithmic problems Game trees (i.e., chess ),
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Priority Queues and Binary Heaps Chapter Trees Some animals are more equal than others A queue is a FIFO data structure the first element.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
 2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Union-find Algorithm Presented by Michael Cassarino.
10 Copyright © William C. Cheng Data Structures - CSCI 102 Graph Terminology A graph consists of a set of Vertices and a set of Edges C A B D a c b d e.
 2004 SDU Lectrue4-Properties of DFS Properties of DFS Classification of edges Topological sort.
1 Chapter 4 Minimum Spanning Trees Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Queues, Stacks and Heaps. Queue List structure using the FIFO process Nodes are removed form the front and added to the back ABDC FrontBack.
CS223 Advanced Data Structures and Algorithms 1 Priority Queue and Binary Heap Neil Tang 02/09/2010.
Trees Thm 2.1. (Cayley 1889) There are nn-2 different labeled trees
Graph and Digraph Sung Yong Shin TC Lab. CS Dept., KAIST.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
CSE 589 Applied Algorithms Spring 1999 Prim’s Algorithm for MST Load Balance Spanning Tree Hamiltonian Path.
CSC317 1 At the same time: Breadth-first search tree: If node v is discovered after u then edge uv is added to the tree. We say that u is a predecessor.
Chapter 5 : Trees.
Minimum Spanning Trees
Minimal Spanning Trees
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Lecture 12 Algorithm Analysis
Binary Trees, Binary Search Trees
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Minimal Spanning Trees
Enumerating Distances Using Spanners of Bounded Degree
Minimum Spanning Tree.
Data Structures – LECTURE 13 Minumum spanning trees
Basic Graph Algorithms
CS 583 Analysis of Algorithms
Lecture 12 Algorithm Analysis
Binary Trees, Binary Search Trees
Lecture 12 Algorithm Analysis
Binary Trees, Binary Search Trees
Minimum Spanning Trees
Presentation transcript:

Algorithms for Enumerating All Spanning Trees of Undirected and Weighted Graphs Presented by R 李孟哲 R 陳翰霖 R 張仕明 Sanjiv Kapoor and H.Ramesh

Index Introduction Computation Tree Algorithm 1 Algorithm 2 Algorithm 3

Introduction Spanning tree enumeration in undirected graphs is an important issue in network and circuit analysis In this paper, author enumerate spanning trees by the computation tree Every node in the computation tree represent a spanning tree

Algorithms Introduction We use this way to enumerate all the spanning tree on undirected and weighted graphs. Algorithm 1 –O(N+V+E) time –O(V 2 E) space Algorithm 2 –O(N+V+E) time –O(VE) space Algorithm 3 (with sorting) –O(NlogV+VE) time –O(N+VE) space

Spanning Tree The original graph G

Spanning Tree A Spanning tree of G

Spanning Tree add a edge to the tree

Spanning Tree get a cycle (fundamental cycle)

Spanning Tree remove a edge on the cycle

Spanning Tree get a new spanning tree of G

Spanning Tree From this cycle, we can obtain several spanning trees.

Computation Tree

Computation tree First, we start off with a spanning tree T, and generate all other spanning trees form T by replacing edges in T by edges outside T For every node x, S x is the spanning tree corresponding to this node To ensure that each spanning tree is generated exactly once, we use 2 edge set IN x and OUT x for every node x

IN and OUT The set IN x consist of edges which are always included in node x and it’s descendants The set OUT x consist of edges which are always not included in node x and it’s descendants The IN and OUT set of the root are both empty

Computation tree In =[ ] Out=[ ] S =[ ],, 1,2,4 Arbitrary choose a spanning tree

Computation tree In =[ ] Out=[ ] S =[ ],, 1,2,4

Computation tree In =[ ] Out=[ ] S =[ ],, 1,2,4 In =[ ] Out=[ ] S =[ ],,,,,,,,,,,,

Computation tree In =[ ] Out=[ ] S =[ ],, 1,2,4 In =[ ] Out=[ ] S =[ ],, 2,4,5 In =[ ] Out=[ ] S =[ ],, 1,2,5 In =[ ] Out=[ ] S =[ ],, 1,2,4 In =[ ] Out=[ ] S =[ ],, 1,4, (-2,+5)(-1,+5)(-4,+5)

Computation tree In =[ ] Out=[ ] S =[ ],, 1,2,4 In =[ ] Out=[ ] S =[ ], 1, 2,4,5 In =[ ] Out=[ ] S =[ ], 4, 1,2,5 In =[ ] Out=[ ] S =[ ], 5, 1,2,4 In =[ ] Out=[ ] S =[ ], 2, 1,4, (-2,+5)(-1,+5)(-4,+5)

Computation tree In =[ ] Out=[ ] S =[ ],, 1,2,4 In =[ ] Out=[ ] S =[ ] 5, 1, 2,4,5 In =[ ] Out=[ ] S =[ ] 5, 4, 1,2,5 In =[ ] Out=[ ] S =[ ], 5, 1,2,4 In =[ ] Out=[ ] S =[ ] 5, 2, 1,4, (-2,+5)(-1,+5)(-4,+5)

Computation tree In =[ ] Out=[ ] S =[ ],, 1,2,4 In =[ ] Out=[ ] S =[ ] 5,2, 1, 2,4,5 In =[ ] Out=[ ] S =[ ] 5,2,1, 4, 1,2,5 In =[ ] Out=[ ] S =[ ], 5, 1,2,4 In =[ ] Out=[ ] S =[ ] 5, 2, 1,4, (-2,+5)(-1,+5)(-4,+5)

Computation tree In =[ ] Out=[ ] S =[ ], 5, 1,2,4

Computation tree In =[ ] Out=[ ] S =[ ], 5, 1,2,4 In =[ ] Out=[ ] S =[ ], 5, 1,3,4 In =[ ] Out=[ ] S =[ ], 5,3 1,2,4 In =[ ] Out=[ ] S =[ ], 5, 2,3, (-1,+3) (-2,+3)

Computation tree In =[ ] Out=[ ] S =[ ], 5, 1,2,4 In =[ ] Out=[ ] S =[ ] 1,3, 5,2 1,3,4 In =[ ] Out=[ ] S =[ ], 5,3 1,2,4 In =[ ] Out=[ ] S =[ ] 3, 5,1 2,3, (-1,+3) (-2,+3)

Computation tree

Computation tree C’(G)

Appear not only once The last son and its parent are the same

Another Computation tree C’(G) G C(G) C’(G)

Another Computation tree C’(G)

Computation tree C(G)’s property The son has zero or one edge differ from its parent. The number of sons equals to the length of the fundamental cycle

Computation tree C’(G)’s property The son has one edge differ from its parent. The number of sons equals to the sum of the length of all fundamental cycles

Lemma 1 The computation tree has at its internal nodes and leaves all the spanning trees of G [Proof] Following from induction and inclusion/exclusion principle Let A be a node of computation tree C(G), B 1,...,B k+1 be the son of A

All spanning trees in B 1,…, B k contain edge f All spanning trees in B k+1 don’t contain edge f The spanning trees as B j ‘s descendants contain edges e 1,…,e j-1, but the edge e j e 1,…,e k and f form a cycle A B1B1 B2B2 BkBk B k+1 … … ……… computation tree f e1e1 e2e2 ekek

Algorithm 1

The Algorithm 1 … Generate a random spanning tree and initialize some data structures. Prepare and modify the data structures. Recursively call the algorithm.

Possible problem in algorithm How to maintain the IN, OUT, S ? How to find the fundamental cycles?

Possible problem in algorithm How to maintain the IN, OUT, S ? –S is easy, just add a edge and delete another one. –We use a data structure AG to maintain IN, OUT. –We would choose edges from AG –Initial: AG is the graph itself.

Possible problem in algorithm –Modify AG –Adding a edge into IN –Contract the edge

Possible problem in algorithm –Modify AG –Add a edge into OUT –Delete the edge

Modify the fundamental cycle After we exchange the edges, the fundamental cycles of this tree would change We need to modify the fundamental cycles f e1e1 e2e2 e3e3 f e1e1 e3e3 e2e2 f e1e1 e3e3 e2e2

Modify the fundamental cycle Author uses the data structure C to maintain the fundamental cycles C maintains the fundamental cycles corresponding to the current tree There are 3 operations to construct computation tree: 1.After deleting edge e i in AG, merge the fundamental cycles contain e i 2.After contracting edge e in AG, contract edge e in C 3.Delete the nontree edge for the last son

Merge the fundamental cycles Use 4 pointer to modify the cycles This operation takes time proportional to the size of resulting cycle

Contract edge in C This operation takes time proportional to fundamental cycles containing the contracted edge

Delete the nontree edge in C If the nontree edge is a part of a multiedge, then do nothing else delete the fundamental cycle containing the nontree edge This operation takes time proportional to the size of its fundamental cycle

AG and C When some edge e is added to set IN: –Contract e in AG and C When some edge e is added to set OUT: –Delete e in AG and C –Merge the fundamental cycles containing e

Lemma 1.2 The algorithm done at each node A of C(G) is O(|s(A)|+|g(A)|) Where s(A) is the set of sons of A in C(G), g(A) is the set of sons in C’(G) of nodes in s(A)

Proof When replace tree edge e i by f, We need to –Contract f in AG: constant time –merge fundamental cycles in C containing e i : it takes time proportional to the sum size of resulting cycle ( O(|g(A)|) ) –Contract e i in C: it takes time proportional to the number of cycles contain e i ( O(|g(A)|) ) –Contract e i in AG : it takes time proportional to the number of multiedges incident to the endpoints of e i ( O(|g(A)|) )

Proof Before operating the node is the last son, then –Delete f in AG: constant time –Delete f in C: time proportional to the size of its fundamental cycle ( O(s(A)) ) Every node takes O(|s(A)|+|g(A)|) time

Theorem 1.3 All spanning trees can be correctly generated in O( N + V + E ) time by Algorithm 1 [Proof] –First, construct a spanning tree and setup it’s data structure require O( V + E ) time –Every node in computation tree C(G) takes O(|s(A)|+|g(A)|) time –Summing overall nodes of C(G) is O(N)

Theorem 1.4 The space requirement of the spanning tree enumeration Algorithm 1 is O( V 2 E ) [Proof] –At each node of C(G), take O( VE ) space –The height of C’(G) is at most V … ……

Algorithm 2

We play two tricks to reduce the space complexity from O(V 2 E) to O(VE) –DFS tree –Biconnected components

DFS tree The first spanning tree is generated by depth first search. –Nontree edges are back edges It is easy to find the fundamental cycle of the depth first search tree

Why it’s easier at DFS tree To find a fundamental cycle, we just need to trace the back edge We can reduce the space requirement since we don’t have to maintain the fundamental cycle set

Maintaining the d.f.s invariant For a node A of C(G), S A is a d.f.s tree of G A Assume the vertices of S A are numbered by a post-order traversal root

Maintaining the d.f.s invariant Select the nontree edge whose upper endpoint has the smallest number (upper is the endpoint closer to the root) This edge is the replacement edge root

Maintaining the d.f.s invariant Replace the tree in order of the post-order number The new graph’s spanning tree is still a d.f.s tree

Biconnected components

The red edges (bridges) must be chosen in each spanning tree of G. Let nST(G) be the number of spanning trees in G. Then nST(G) = nST(G 1 )*nST(G 2 )*…..nST(G n ) G1 G2 G3 G4 G5

Biconnected components No change in time and space complexity in analysis, but make the algorithm efficiency in most cases.

Bridge When exchange edges, there may be some tree edges which is not contained by any fundamental cycles –We call those edges bridges –A bridge must be in this spanning tree

How to detect bridge Bridge only occurs on a fundamental cycle when we exchange 2 edges Since x 4 has a branch in current graph G A,e 4 is a bridge when we delete e 3 e1e1 e2e2 e4e4 e5e5 e3e3 x4x4

Lemma 2.1 The work done at each node A of C(G) is O(|s(A)|+|g(A)|) Proof : –Removing bridges spends time in O(|s(A)|) –Exchanging and contracting edges spend O(g|A|)

Theorem 2.2 All spanning tree can be correctly generated in O( N + V + E ) time by Algorithm 2 [Proof] –First, we construct a spanning and setup it’s data structure require O( V + E ) time –Every node in computation tree C(G) takes O(|s(A)|+|g(A)|) time –Summing overall nodes of C(G) takes O(N) time

Theorem 2.3 The space requirement in Algorithm 2 is O( VE ) [Proof] –At each node of C(G), takes O( E ) space –The height of C’(G) is at most V … ……

Algorithm 3

If we want to show all the spanning trees in increasing order. –Generate all the trees O(N+V+E) –Sorting all the trees O(NlogN) Algorithm 3 generates sorted order in O(NlogV+VE)time

Algorithm 3 We create M queues, M = (V-1)(E-V+1)=O(VE) and indexed by “exchange” …

Algorithm 3 We create a priority queue (heap) whose size is equal to M=O(VE), and height is O(logVE) This heap maintains the first element of each queue. … ….

Algorithm 3 … We sort all the nontree edges by increasing order.

Algorithm 3 … Minimum spanning tree Output this one

Algorithm 3 … Add the smallest nontree edge and delete a tree edge. We can generate the sons

Algorithm 3 … Insert these nodes into queue corresponding to “exchange”

Algorithm 3 … Get the minimum cost tree from the heap. Output this tree. Do the algorithm again ….

Algorithm 3 … Insert these nodes into queues corresponding to “exchange”

Algorithm 3 … We choose the minimum cost tree from the heap again, These blue vertices are possible to be chosen.

Analysis of algorithm 3 [Lemma 3.1] Any child’s cost is larger than parent’s. … Tree edges = {e1,e2….en} Nontree edges = {f1,f2…..fm} This node’s cost must be larger than( or equal to) parent’s.

Analysis of algorithm 3 [Lemma 3.1] Any child’s cost is larger than parent’s. … Tree edges = {e1,e2….en}U{f1} Nontree edges = {f2…..fm} This node’s cost must be larger than( or equal to) parent’s.

Analysis of algorithm 3 [Lemma 3.2] The spanning trees enter the queue for each of the exchanges in sorted order. Blue one is smaller than red one. …

Analysis of algorithm 3 Those two nodes are in queue, which implies their parents have been output. Blue one is in front, because its parent outputs earlier than dark red one. Because they have same “exchange”, so blue one < red one. …

Analysis of algorithm 3 Time complexity –Sorting edges: O(ElogE) time –Generation: O(N+V+E) time –O(VE) queues, N trees –Create a heap: O(VE) time. –One operation in heap: O(logVE) time –N operation in heap: O(NlogVE) time – O(N logVE) + O(ElogE) + O(N+V+E) + O(VE) =O(N logV 3 + ElogE + N + V + E + VE) =O( N logV + VE)

Analysis of algorithm 3 Space complexity –O(N) trees –O(VE) queues –O(N+VE) space