Constant Time Generation of Free Trees

Similar documents
GRAPH THEORY LECTURE 4: TREES

Connectivity and cuts

8.1 Min Degree Spanning Tree

THE ENUMERATION OF ROOTED TREES BY TOTAL HEIGHT

Graph Theory Problems and Solutions

Enumerating possible Sudoku grids

COMBINATORIAL PROPERTIES OF THE HIGMAN-SIMS GRAPH. 1. Introduction

On the k-path cover problem for cacti

Data Structure [Question Bank]

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child


Product irregularity strength of certain graphs

Class One: Degree Sequences

Full and Complete Binary Trees

Binary Search Trees CMPSC 122

Lecture 16 : Relations and Functions DRAFT

Symbol Tables. Introduction

ENUMERATION OF INTEGRAL TETRAHEDRA

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Frans J.C.T. de Ruiter, Norman L. Biggs Applications of integer programming methods to cages

Mathematics for Algorithm and System Analysis

A NOTE ON OFF-DIAGONAL SMALL ON-LINE RAMSEY NUMBERS FOR PATHS

COUNTING INDEPENDENT SETS IN SOME CLASSES OF (ALMOST) REGULAR GRAPHS

Euler Paths and Euler Circuits

The Goldberg Rao Algorithm for the Maximum Flow Problem

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

CMPSCI611: Approximating MAX-CUT Lecture 20

Reading 13 : Finite State Automata and Regular Expressions

Bargaining Solutions in a Social Network

P. Jeyanthi and N. Angel Benseera

Approximation Algorithms

An algorithmic classification of open surfaces

Converting a Number from Decimal to Binary

The Open University s repository of research publications and other research outputs

Triangulation by Ear Clipping

Data Structures Fibonacci Heaps, Amortized Analysis

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

Lecture 1: Course overview, circuits, and formulas

most 4 Mirka Miller 1,2, Guillermo Pineda-Villavicencio 3, The University of Newcastle Callaghan, NSW 2308, Australia University of West Bohemia

Discrete Applied Mathematics. The firefighter problem with more than one firefighter on trees

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Finding and counting given length cycles

Rotation Operation for Binary Search Trees Idea:

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification)

6.3 Conditional Probability and Independence

Chapter 6: Graph Theory

Un survol de la domination de puissance dans les graphes

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Graphical degree sequences and realizations

Random Map Generator v1.0 User s Guide

DEGREES OF CATEGORICITY AND THE HYPERARITHMETIC HIERARCHY

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Lesson 1: Positive and Negative Numbers on the Number Line Opposite Direction and Value

Ordered Lists and Binary Trees

Any two nodes which are connected by an edge in a graph are called adjacent node.

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Classification/Decision Trees (II)

Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013

Cycles in a Graph Whose Lengths Differ by One or Two

Applied Algorithm Design Lecture 5

A REMARK ON ALMOST MOORE DIGRAPHS OF DEGREE THREE. 1. Introduction and Preliminaries

Social Media Mining. Graph Essentials

MATROIDS AND MYSQL WHAT TO DO

A Study of Sufficient Conditions for Hamiltonian Cycles

A Catalogue of the Steiner Triple Systems of Order 19

UPPER BOUNDS ON THE L(2, 1)-LABELING NUMBER OF GRAPHS WITH MAXIMUM DEGREE

An Evaluation of Self-adjusting Binary Search Tree Techniques

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

A simple criterion on degree sequences of graphs

Lecture 17 : Equivalence and Order Relations DRAFT

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

Class notes Program Analysis course given by Prof. Mooly Sagiv Computer Science Department, Tel Aviv University second lecture 8/3/2007

The positive minimum degree game on sparse graphs

Binary Search Trees (BST)

Mathematical Induction. Lecture 10-11

Polytope Examples (PolyComp Fukuda) Matching Polytope 1

Extremal Wiener Index of Trees with All Degrees Odd

Small independent edge dominating sets in graphs of maximum degree three

136 CHAPTER 4. INDUCTION, GRAPHS AND TREES

Odd induced subgraphs in graphs of maximum degree three

Why? A central concept in Computer Science. Algorithms are ubiquitous.

SPERNER S LEMMA AND BROUWER S FIXED POINT THEOREM

Analysis of Algorithms I: Binary Search Trees


Network File Storage with Graceful Performance Degradation

Analysis of Algorithms I: Optimal Binary Search Trees

Cluster Editing And Search Tree Algorithms

Max Flow, Min Cut, and Matchings (Solution)

ER E P M A S S I CONSTRUCTING A BINARY TREE EFFICIENTLYFROM ITS TRAVERSALS DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A

Handout #Ch7 San Skulrattanakulchai Gustavus Adolphus College Dec 6, Chapter 7: Digraphs

Chapter 14 The Binary Search Tree

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

Shortest Inspection-Path. Queries in Simple Polygons

Just the Factors, Ma am

CS 598CSC: Combinatorial Optimization Lecture date: 2/4/2010

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

Generating models of a matched formula with a polynomial delay

Mining Social Network Graphs

Transcription:

Constant Time Generation of Free Trees Michael J. Dinneen Department of Computer Science University of Auckland Class: Combinatorial Algorithms CompSci 7

Introduction This is a combinatorial algorithms report on generating unlabeled free trees in constant amortized time and O(n) space. A CAT (Constant Amortized Time) algorithm given by Wright, Richmond, Odlyzko and McKay [WROM] is presented. (See also the nice presentation given in [Wi].) This algorithm uses a modified successor function that Beyer and Hedetniemi used for constant-time generation of rooted trees [BH]. In both of the these algorithms, the idea of using integer sequences to represent objects being generated was introduced by Ruskey and Hu for generating binary trees lexicographically (see [RH] and [Ru]). Some graph theory definitions are now reviewed. A tree or free tree is a connected graph T = (V, E) such that the number of edges (size) of T, denoted by E, is exactly one less then the number of vertices (order) of T, denoted by T or V. If the context is clear we will use n to denote the order. Note that we are excluding multiple edges and loops in our implicit definition of graph. A rooted tree (T, z) is free tree T with a designated root z chosen from V (T). We assign an unique layout of a rooted tree (T, z) as the lexicographically greatest distance sequence L(T, z) = [l, l, l,..., l n ] resulting over all preorder traversals (depth-first searches) of tree T starting from vertex z. Three such examples are shown below in Figure. (The roots in these examples are the ones labeled with distance.) 4 [,,,, 4, ] [,,,,,, ] [,,,,,,, ] Figure : How to assign integer sequences to rooted trees.

The center of a free tree T = (V, E) is the set of vertices whose maximum distance from the other vertices is least. The center of a tree will contain either one or two vertices. In the bicentral case the two centers will be adjacent in the graph. (A simple algorithm that deletes all leaves of a tree and repeats on the resulting tree until at most one edge remains can be can be used to find centers.) The primary root of a free tree is defined by two cases. If a tree T = (V, E) has a single center then it is the primary root. Otherwise one of the centers r or r of T will be chosen. Let T = (V, r ) and T = (V, r ) be the resulting two rooted trees when the edge (r, r ) of T is deleted. The primary root of T will be r if and only if T < T, or T = T and L(T, r ) < L(T, r ). Asside: One can do isomorphism testing for free trees with an isomorphism algorthm for rooted trees by using the primary root as their roots (since they are uniquely defined). Thus, if two root trees have the same lexicographically greatest distance sequences then they are isomorphic. Algorithm We first present a successor function that generates nonisomorphic rooted trees, [BH]. Let L = [l, l,...,l n ] be a layout of a rooted tree of order n. Let p be the largest integer (subscript) such that l p and let q be the largest integer such that q < p and l q = l p. (Note that the vertex indexed by q is the parent of the vertex indexed by p.) The successor s(l) = [s, s,...,s n ] of L is given by: l i, for i < p, s i = s i (p q), for p i n To generate all rooted trees of order n we start with the first rooted tree with layout L = [,,,..., n ] and repeatedly apply the seccessor function until the last rooted tree [,,,..., ] appears in the enumeration.

We now present an algorithm that generates free trees based on the enumeration procedure for rooted trees. If at least two ones occur in the layout L, then define L = [l, l,...,l m ] and L = [l, l m, l m+,..., l n ] where m is the index of the second in L. Wright, Richmond, Odlyzko and McKay use the following necessary and sufficient test to determine when L represents a free tree rooted at its primary root: (a) index m exists, (b) max(l ) max(l ), (c) if equality holds in (b), then L L, (d) if equality holds in (c), then L L lexicographically. The free tree that this algorithm starts with is the integer sequence of an n- path rooted at its primary root. Starting at this tree guarantees that condition (a) never fails. The other cases may fail and the detection can be made before the successor function is applied. Figure shows some examples and the modifications needed to keep the algorithm generating only primary rooted free trees. Note that in the figure, the indicated condition fails for the successor of the trees listed on the left side of the arrows (not the valid free trees displayed). There is a general procedure for doing these jumps down the list of rooted trees when a failure condition is detected. First, we set the parameter p for the successor fuction to the last node p of L and apply the succesor function on L to get s(l). Second, if l p was greater than in L then we replace the final elements of s(l) with,,..., height(l ) +, where L is the new left subtree of s(l). The intuitive reason for using the successor funcion in this way is to find the next lexicographically greatest sequence that is a primary rooted free tree. The second step guarantees that the tree is rooted at a center vertex. 4

Condition (b) fails: (The height of L is reduced too much.) [,,,,,,,,, ] [,,,,,,,,, ] Condition (c) but not (b) fails: (Successor causes L < L in bicentral case.) [,,,,,,,,, ] [,,,,,,,,, ] Condition (d) alone is violated: (Only happens when L L.) [,,,,,,,,, ] [,,,,,,,,, ] Figure : Corrections when the rooted tree successor function fails. 5

Results Let t n and T n denote the number of free and rooted unlabeled trees of order n, respectively. Wright, Richmond, Odlyzko and McKay use the following result of Pólya [Po] and Otter [Ot] to prove their algorithm runs in constant amortized time. Theorem : T n C n / p n and t n C n 5/ p n as n, where C.499, C.549 and p.8. I have implemented the constant time free tree algorithm by Wright, Richmond, Odlyzko and B.D. McKay and did some benchmarks to determine, at least empirically, if it runs in constant amortized time. An affirmative indication resulted! Also I have checked the correctness of the output for free trees with and fewer vertices. This check entailed a comparison of the trees generated by the algorithm in [WROM] and the trees contained in Read s catalog of all non-isomorphic graphs on vertices, [CCRW]. The following table and figure summarizes my experiments. The start-up CPU time was included in the times indicated. So it is reasonable to expect (as shown by my crude /usr/bin/time technique) for the amount of CPU per tree to slightly decrease when generating larger trees. 6

Order No. of Trees CPU Time CPU per Tree 4 5 6 6 7 8 9 47 6 5 55 4 59.µ.45µ 5 774.µ.88e-5µ 6 9.7µ.6e-5µ 7 4869.8µ.7e-5µ 8 867 4.7µ.79e-5µ 9 7955.7µ.7e-5µ 865.4µ.69e-5µ 4455 78.µ.65e-5µ 56756.4µ.6e-5µ 48874 5.4µ.59e-5µ 4 999897 4.8µ.57e-5µ 5 46689 756.8µ.59e-5µ 6 797945 96.7µ.7e-5µ Figure : CPU time needed to count free trees on a Sparc-. 7

Sparc CPU per Tree x 6 4. 9. 8. 7. 6. 5. 4..... 6 8 4 6 Tree order Figure : Scaled plot of average time per tree per tree order. The subsequent pages of this report contain the following items:. Listings of all rooted trees of order 5 through 8 generated by the algorithm by Beyer and Hedetniemi.. Listings of all free trees of order 5 through generated by the algorithm by Wright, Richmond, Odlyzko and B.D. McKay.. Program listings of the above two implementations. (Slightly altered code was used for the CPU timings.) 8

References [BH] T. Beyer and S.M. Hedetniemi, Constant time generation of rooted trees, SIAM Journal of Computing, 9 (98), pp. 76 7 [CCRW] R.D. Cameron, C.J. Colbourn, R.C. Read, N.C. Wormald, Cataloguing the Graphs on Vertices, Journal of Graph Theory, 9 (985) pp. 55 56. [Tape announcement, Discrete Math. (98) p. 4.] [Ot] R. Otter, The number of trees, Ann. Math., 49 (948), pp. 58 599. [Po] G. Pólya, Kombinatorische Anzahlbestimmungen für Gruppen, Graphen und chemische Verbindungen, Acta Math., 68 (97), pp. 45 54. [RH] F. Ruskey and T.C. Hu, Generating binary trees lexicographically, SIAM Journal of Computing, 6 (977), pp. 745 758. [Ru] F. Ruskey, Generating t-ary trees lexicographically, SIAM Journal of Computing, 7 (978), pp. 44-49. [WROM] R.A. Wright, B. Richmond, A. Odlyzko and B.D. McKay, Constant time generation of free trees, SIAM Journal of Computing, 5 (986), pp. 54 548. [Wi] H.S. Wilf, Listing Free Trees, in Combinatorial Algorithms (An Update), pp. -6. 9