Generation of random chordal graphs using subtrees of a tree

Chordal graphs form one of the most studied graph classes. Several graph problems that are NP-hard in general become solvable in polynomial time on chordal graphs, whereas many others remain NP-hard. For a large group of problems among the latter, approximation algorithms, parameterized algorithms, and algorithms with moderately exponential or sub-exponential running time have been designed. Chordal graphs have also gained increasing interest during the recent years in the area of enumeration algorithms. Being able to test these algorithms on instances of chordal graphs is crucial for understanding the concepts of tractability of hard problems on graph classes. Unfortunately, only few studies give algorithms for generating chordal graphs. Even in these papers, only very few methods aim for generating a large variety of chordal graphs. Surprisingly, none of these methods is directly based on the"intersection of subtrees of a tree"characterization of chordal graphs. In this paper, we give an algorithm for generating chordal graphs, based on the characterization that a graph is chordal if and only if it is the intersection graph of subtrees of a tree. Upon generating a random host tree, we give and test various methods that generate subtrees of the host tree. We compare our methods to one another and to existing ones for generating chordal graphs. Our experiments show that one of our methods is able to generate the largest variety of chordal graphs in terms of maximal clique sizes. Moreover, two of our subtree generation methods result in an overall complexity of our generation algorithm that is the best possible time complexity for a method generating the entire node set of subtrees in a"intersection of subtrees of a tree"representation. The instances corresponding to the results presented in this paper, and also a set of relatively small-sized instances are made available online.


Introduction
Algorithms particularly tailored to exploit properties of various graph classes have formed an increasingly important area of graph algorithms during the last five decades.With the introduction of relatively new theories for coping with NP-hard problems, like parameterized algorithms, algorithmic research on graph classes has become even more popular recently, and the number of results in this area appearing at international conferences and journals is now higher than ever.One of the most studied graph classes in this context is the class of chordal graphs, i.e., graphs that contain no induced cycle of length 4 or more.Chordal graphs arise in practical applications from a wide variety of unrelated fields, like sparse matrix computations, database management, perfect phylogeny, VLSI, computer vision, knowledge based systems, and Bayesian networks [6,13,22,25,27].This graph class that first appeared in the literature as early as 1958 [14], has steadily increased its popularity, and there are now more than 20 thousand references on chordal graphs according to Google Scholar.
With a large number of existing algorithms specially tailored for chordal graphs, it is interesting to note that not much has been done to test these algorithms in practice.Very few such tests are available as published articles [2,19,23].In particular, there seems to be no efficient chordal graph generator available that is capable of producing every chordal graph.Most of the work in this direction involves generating chordal graphs tailored to test a particular algorithm or result [2,23].This is a clear shortcoming for the field, and it was even mentioned as an important open task at a Dagstuhl Seminar [17].Until some years ago, most of the algorithms tailored for chordal graphs had polynomial running time, and testing was perhaps not crucial.Now, however, many parameterized and exponential-time algorithms exist for chordal graphs, for problems that remain hard on this graph class, see e.g., [4,12,20,21].The proven running times of such algorithms might often be too high compared to the practical running time.Just to give some examples from the field of enumeration, there are now several algorithms and upper bounds on the maximum number of various objects in chordal graphs [1,11,12].However, the lower bound examples at hand usually do not match these upper bounds.Tests on random chordal graphs is a good way of getting better insight about whether the known upper bounds are too high or tight.
In this paper, we present an algorithm for generating random chordal graphs.Our algorithm is based on the characterization that a graph is chordal if and only if it is the intersection graph of subtrees of a tree.Surprisingly, this characterization does not seem to have been directly used for random chordal graph generation earlier.Starting from a random host tree, we propose three different methods for generating subtrees of the host tree to give different neighborhood and density properties.Our algorithm, with two of these methods, can be implemented in such a way that the overall running time is best possible for an algorithm producing the entire node set of subtrees in a "intersection of subtrees " representation of a chordal graph.One of these fast subtree generation methods, which we call GrowingSubtree, is also the method that turns out to generate the largest variety of chordal graphs.We measure the variety using the characteristics of the maximal cliques of the generated graph, as it has been done in previous work [23].After proving the correctness,we give extensive computational tests to demonstrate the kind of chordal graphs that our algorithm generates using each of the different subtree generation methods.We compare our methods with one another and with existing test results; we also implement one of the earlier proposed methods and include this in our tests.Note that Graph Isomorphism is as hard on chordal graphs as on general graphs [18], which adds to the difficulty of producing chordal graphs uniformly at random.Our algorithm is able to generate every chordal graph with positive probability.

Background, terminology and existing algorithms
In this section we give the necessary background on chordal graphs, as well as a short review of the existing algorithms for chordal graph generation.We work with simple and undirected graphs, and we use standard graph terminology.In particular, for a given graph G, we denote its vertex set by V (G), and edge set by E(G).We let n = |V (G)| and m = |E(G)|.The set of neighbors, or the neighborhood, of a vertex is the set of vertices adjacent to it.The size of the neighborhood of a vertex x is the degree of x, denoted by d(x).The neighborhood of a set X of vertices is the union of the neighborhoods of the vertices in X, excluding X itself.
Let F = {S 1 , S 2 , . . ., S n } be a family of sets from the same universe.A graph G is called an intersection graph of F if there is a bijection between the set of vertices {v 1 , v 2 , . . ., v n } of G and the sets in F such that v i and v j are adjacent if and only if S i ∩ S j = ∅, for 1 ≤ i, j ≤ n.In the special case where there is a tree T such that each set in F corresponds to the vertex set of a subtree of T , then G is called the intersection graph of subtrees of a tree.
A clique is a set of vertices that are pairwise adjacent.An ordering (v 1 , v 2 , . . ., v n ) of the vertices of a graph is a perfect elimination order (peo) if the set of higher numbered neighbors of each vertex forms a clique.A maximal clique is a clique C such that no set of vertices properly containing C is a clique.Let K be the set of maximal cliques of a graph G.A tree T with a bijection between its vertex set and the cliques in K is called a clique tree of G if for every vertex v of G, the set of vertices of T that correspond to the cliques containing v induce a connected subtree of T .
A graph is chordal if it contains no induced cycle of length 4 or more.A chordal graph on n vertices has at most n maximal cliques [7].Chordal graphs have many different characterizations.For our purposes, the following will be sufficient.
-G has a perfect elimination order.
-G is the intersection graph of subtrees of a tree.
-G has a clique tree.
Especially the last two points of Theorem 1 are crucial for our algorithm and its implementation.To make sure that there is no confusion between the vertices of G and the vertices of a tree or a clique tree, we will from now on refer to vertices of a tree as nodes.
Rose, Tarjan, and Lueker [26] gave an algorithm called Maximal Cardinality Search (MSC) that creates a perfect elimination order of a chordal graph in time O(n + m).Blair and Peyton [3] gave a modification of MCS to list all the maximal cliques of a chordal graph in time O(n + m).Implicit in their proofs is the following well-known fact, which can be characterized as folklore.
Lemma 1 ( [3,26]).The sum of the sizes of the maximal cliques of a chordal graph is O(n + m).
Next, we briefly mention the algorithms for generating chordal graphs from the works of Andreou, Papadopoulou, Spirakis, Theodorides, and Xeros [2]; Pemmaraju, Penumatcha, and Raman [23]; and Markenzon, Vernet, and Araujo [19].Some of these algorithms create very limited chordal graphs, which is either mentioned by the authors or clear from the algorithm.Thus, in the following we only mention the algorithms that are general enough to be interesting in our context.
It should also be noted that the purpose of Andreou et al. [2] is not to obtain general chordal graphs, but rather chordal graphs with a known bound on some parameter.One of the algorithms that they propose starts from an arbitrary graph and adds edges to obtain a chordal graph.How the edges are added is not given in detail, however it should be noted that there are many algorithms for generating a chordal graph from a given graph by adding a minimal set of edges and their running time is usually O(nm) [15].Andreou et al. [2] do not report on the quality of chordal graphs obtained by this method.
We highlight below the algorithms that are the most promising with respect to generating random chordal graphs.In addition to these, there is an O(n 2 )-time algorithm by Markenzon et al. [19] that generates a random tree and adds edges to this tree until a chordal graph with desired edge density is obtained.However, no test results about the quality of the generated graphs is given.
Alg 1 [2].The algorithm constructs a chordal graph by using a peo.At every iteration, a new vertex is added and made adjacent to a random selection of already existing vertices.Then necessary edges are added to turn the neighborhood of the new vertex into a clique such that a given maximum degree is not exceeded.No test results are given in the paper about the quality of the chordal graphs this algorithm produces.As we found the algorithm interesting, we have implemented it, and we compare the resulting graphs to those generated by our algorithm in Section 4.
Alg 2 [19,23].The algorithm starts from a single vertex.At each subsequent step, a clique C in the existing graph is chosen at random, and a new vertex is added adjacent to exactly the vertices of C. The inverse of the order in which the vertices are added is a peo of the final graph.It is observed by the authors of both papers that this procedure results in chordal graphs with approximately 2n edges experimentally.They propose the following changes: Alg 2a [19] modifies the above generated graph by randomly choosing maximal cliques that are adjacent according to the clique tree and merging these until desired edge density is obtained.Some test results about graphs generated by Alg 2a are provided in [19].Although these tests are not as comprehensive as the ones we give on our algorithms in Section 4, we compare our results to those of [19] as best we can.The running time of Alg 2a is O(m + nα(2n, n)).
Alg 2b [23] is a modification of Alg 2 in a different way: instead of randomly choosing a clique, a maximum clique is chosen and a random subset of it is made adjacent to the new vertex.Although test results for Alg 2b are provided in [23], the authors acknowledge that the produced graphs are still very particular with very few large maximal cliques and many very small maximal cliques.For this reason, we do not include Alg 2b in our comparisons.

Generating chordal graphs using subtrees of a tree
We find it surprising that the intersection graph of subtrees of a tree characterization of chordal graphs has not been used directly for their generation.Of course, since all characterizations of a chordal graph are equivalent, even the existing algorithms mentioned above could be interpreted as based on any of these characterization.Especially the algorithms based on clique trees can easily be translated to generate subtrees of a tree.However, none of these algorithms generate random subtrees of a randomly generated tree to produce the resulting chordal graph.One reason could be that this does not give a direct way to decide the number of edges in the generated graph.We will see that edge density can be regulated by adjusting the sizes of the generated subtrees.Let us first observe the following.
Lemma 2. For every chordal graph G on n vertices, there is a tree T on n nodes, and a set of n subtrees of T , such that G is the intersection graph of these subtrees.
Proof.Let G be a chordal graph on n vertices and let T be a clique tree of G. Let us call the vertices of G: v 1 , v 2 , . . ., v n .Define subtree T i to be the subtree of T that corresponds to the nodes (maximal cliques) that contain vertex v i , for 1 ≤ i ≤ n.By the definition of a clique tree, T has at most n nodes and each T i is a connected subgraph of T .If T has fewer than n nodes, we can add new nodes adjacent to arbitrary nodes of T until we get a new tree T with n nodes.The subtrees stay the same.As two vertices are adjacent in G if and only if they appear together in a clique, G is the intersection graph of subtrees T 1 , . . ., T n of T .
Based on Lemma 2, we are ready to present our main algorithm for generating chordal graphs on n vertices:

Algorithm ChordalGen
Input: n and one or two other numbers to guide the number of resulting edges.Output: A chordal graph G on n vertices and m edges.
1. Generate a tree T on n nodes uniformly at random.2. Generate n non-empty subtrees of T : {T 1 , . . ., T n }.

Output as G the intersection graph of {V
By Theorem 1, the graph generated by Algorithm ChordalGen is chordal.By Lemma 2, our algorithm can create any chordal graph.Later in this section we will describe three different methods for generating the n subtrees in Step 2. Each method will take one or two parameters to guide the average size of the generated subtrees, with the purpose of controlling the resulting number of edges in G. Our algorithm is flexible in the sense that additional ways to generate the subtrees can be suggested and tested later.
We need to evaluate the order of n i=1 |V (T i )| to analyze the running time of Algorithm Chordal-Gen.Let us explain at this point that in the preliminary version of this paper [28], was mistakenly claimed to be linear in the size of the generated chordal graph, that is O(n + m).However, it turns out that n i=1 |V (T i )| is Ω(mn 1/4 ) as shown in what follows.
Lemma 3. Let T be a tree on n nodes, and let T 1 , . . ., T n be n subtrees of T whose intersection graph is a chordal graph on n vertices and m edges.Then n i=1 |V (T i )|is Ω(mn 1/4 ).
Proof.Let G be a chordal graph that is the intersection graph of {V (T 1 ), . . ., V (T n )}, such that every subtree T i is associated with a vertex v i of G. Choose an integer p ≥ 2. Let n = p 4 , n = p 2 + 1, s = p 2 − p, and s n = p 3 .Note that n > n .Let T be a path on n nodes x 1 , . . .x n .Let T i be the subtree of T consisting of the single node x i , for i = 1, . . ., n − 1.Let T n be the subpath of T consisting of the nodes from n to n.The representation contains s copies of T i for every i = 1, . . ., n − 1 and also s n copies of T n .Therefore, the number of subtrees is The corresponding graph is the disjoint union of a K s n and n − 1 copies of K s .The number m of edges of this graph is On the other hand, the total size of the subtrees is Therefore, Since the inequality holds for infinitely many values of p, we conclude the proof.
We are now ready to state our main result about Algorithm ChordalGen.Step 1.For the generation of a random host tree T on n vertices, we use the following method by Rodionov and Choo [24], which can easily be implemented in O(n) time: start with a tree T that contains only one node.Then repeat n − 1 times the following: pick a random vertex x of T and add a new vertex adjacent to it.
Step 2. We generate n subtrees T 1 , . . ., T n of T using a subtree generator.According to the premises of the theorem, this adds O(S) to the overall time.
Step 3. The sum of the sizes of the generated subtrees is Let us now explain how we can obtain in time O(n + m) the chordal graph which is the intersection graph of these subtrees.For every node x of T , let us define the following list: Observe that every set in C is a clique of G, and C contains all maximal cliques of G.However, some of the cliques in C may not be maximal.If we blow up every node x of T to the set C x , we get a tree which is almost a clique-tree of G; this procedure can clearly be done in O(n + m) time.In the resulting tree, non-maximal cliques simply need to be deleted or merged into the maximal ones.By the methods described by Blair and Peyton [3] it is possible to turn T into a proper clique tree for G in time O(n + m).Thus, in total O( n i=1 |V (T i )| + n + m) time we both have a representation of our output graph G and a list of maximal cliques of it.It could, however, be desirable to output an adjacency list representation for G. Markenzon et al. [19], using the methods of Blair and Peyton [3], explain how this can be done in O(n + m) time.By Lemma 3, the overall running time of this step is O( Now we are ready to give the details of how the subtrees of Step 2 are generated.In the subsections below, we present three methods for generating n subtrees of T .Then, in Section 4, we will test our algorithm with each of these methods and compare the results with each other, as well as with Alg 1 and Alg 2a.

Algorithm GrowingSubtree
This algorithm takes as input a tree T on n nodes, and an integer k, and generates n subtrees of T of average size k+1 2 .In our test results, we give both k and the resulting number of edges, m, to give an indication of how k affects the density of the generated graph.
For each subtree T i , the algorithm picks a size k i randomly from [1, k].Then a random node of T is chosen as the single node of T i to start with.In each of the subsequent k i − 1 iterations, we pick a random node of T in the neighborhood of T i and add it to T i .

Algorithm GrowingSubtree
Input: A tree T on n nodes and a positive integer k ≤ n Output: A set of n non-empty subtrees of T of average size k+1 2 for i = 1 to n do Select a random node x of T and set T i = {x} Select a random integer k i between 1 and k for j = 1 to k i − 1 do Select a random node y of T i that has neighbors in T outside of T i Select a random neighbor z of y outside of T i and add z to Proof.Observe first that each subtree T i can be represented simply a list of nodes of T .We show that after an initial O(n) preprocessing time, each subtree T i can be generated in time O(|V (T i )|).For this, we need to be able to add a new node to T i in constant time, at each of the k i − 1 steps.
As selecting random elements in constant time is easier when accessing the elements of an array directly by indices, we start with copying the nodes of T into an array A of size n, and copying the adjacency list of each node x into an array A x of size d(x).This can clearly be done in total time O(n) since T is a tree.
In general, selecting an unselected element of a set at random can be done easily in constant time if the set is represented with an array.Let us say we have an array S of t elements.We keep a separation index s that separates the selected elements from the not selected ones.At the beginning s is 1.At each step, we generate a random integer r between s and t.S[r] is our randomly selected element.Then we swap the elements S[s] and S[r] and increase s by 1.
We can use this method both for selecting a node y of T i that still has neighbors outside and for selecting a neighbor z of y that has not yet been selected.For the latter, whenever we select a neighbor z of y, we move z to the first part of the array A x using swap.When the separation index reaches the degree of y then we know that y should not be selected to grow the subtree T i at later steps.Representing T i with an array of size k i , we can use the same trick to move y to a part of the array that we will not select from.Also, when z is added, we can check whether it is a leaf in T in constant time, and immediately move it to the irrelevant part of the array for T i if so, since z can then not be used for growing T i at later steps.It is sufficient to check that z is a leaf of T , because otherwise it must have neighbors outside of T i , since T is a tree and we cannot have cycles.When the generation of T i is finished, the separation indices of each of its nodes should be reset before we start generating T i+1 .The adjacency arrays need not be reorganized, as we will anyway be selecting neighbors at random.
Note that we do not need this trick to select an initial node x of each subtree T i , because we should indeed be able to select the same node several times (and grow another subtree from it perhaps in a different way).
With the described method, each step of Algorithm GrowingSubtree takes O(1) time, in addition to initial O(n) time to copy the information into appropriate arrays.Thus the total running time is O( Lemma 4 together with Theorem 2 gives the following.
Corollary 1. Algorithm ChordalGen, using the GrowingSubtree method, runs in time O( We will see in Section 4 that this method generates chordal graphs with the most even distribution of maximal clique sizes.

Algorithm ConnectingNodes
This algorithm takes as input a tree T on n nodes, and a positive real number λ.The purpose of the parameter λ is to guide the desired number of resulting edges in the graph.To generate each subtree T i , we first select k i nodes of T , where k i is a random integer generated by making use of λ.T i is then generated to be the minimal subtree that contains the selected k i nodes.This implies that a subtree will most likely have many more nodes than those selected initially, and this must be taken into consideration when choosing λ.In our test results, we give both λ and the resulting number of edges, m, to give an indication of how λ affects the density of the generated graph.
In the following algorithm, we will make use of the standard Breadth First Search (BFS) algorithm from an arbitrary node r of T .We will then treat T as a rooted tree with root r, and speak about parent-child relation in the standard way, with respect to root r.The BFS level of a vertex is simply the distance of that vertex from r.

Algorithm ConnectingNodes
Input: A tree T on n nodes and a positive real number λ Output: A set of n subtrees of T Let r be an arbitrary node of T Perform BFS from r, and identify the parent P (x) and the BFS level l(x) of each node x L ← ∅ for i = 1 to n do For each subtree T i , we first generate a random integer k i by making use of Poisson distribution with mean λ.Poisson distribution is a discrete probability distribution widely used to model number of occurrences of an event over a specified domain such as time, space etc.In our case, the domain is the host tree, and an event is selection of a node from the host tree.The parameter of this distribution is λ and it is the average rate of event occurrences, which implies that the initial k i values will tend to increase on the average as λ increases.The set of possible values a Poisson random variable can take is nonnegative integers, regardless of the value of λ.However, the minimum and maximum number of nodes that a subtree of an n-node host tree can contain are 1 and n respectively.Therefore, we equate k i to 1 if it is zero, and to n if it is greater than n.In this method, the only reason why we use Poisson distribution is that we were not able to achieve a good precision for edge density by picking a random integer uniformly at random from a given interval.To generate the minimal subtree that contains the k i selected nodes, we make use of the nodes' parent and level information retrieved during BFS.Our key observation is that the minimal subtree must contain the parents of all selected nodes at some level d if there are other selected nodes at levels less than or equal to d.Using this idea, we add a node to T i only when an edge incident to it has to be in T i to join a node to the others.We start from the highest level (highest distance from r) and proceed by moving toward the root until all nodes in the selection become connected.The set L keeps the unprocessed nodes yet to be connected to form the subtree T i .At each step, we consider the nodes in L that are at the same level, which are going to be joined as we move through the levels.Once the parents of those nodes are identified, we are done with level d and there is no need to reconsider nodes at level d any further.Therefore, we replace those nodes with their parents in L, which are to be considered at the next step.Parent nodes are also added to T i because they lie on the paths that connect the node selection.Afterwards, we move to the next level and apply the same procedure.This process continues until a single node is left in L, which simply means that we have a node set that has been linked at a single node already and that T i includes all nodes of the subtree that minimally connects the randomly selected node set.

Lemma 5. The running time of Algorithm ConnectingNodes is O(
Proof.Rooting T from an arbitrary node, and determining the parent P (x) of each node x in T as well as its level l(x) with respect to the root node, takes O(n) time in total for all nodes using BFS.The set L is represented by an array of lists with length equal to max x∈T l(x).Each index d of L represents a list of unprocessed nodes having l(x) = d.The lists in L will be empty initially.If a node x at level d is selected, we add x to the list at index d of L in constant time.We also need to keep an n-dimensional boolean array B, which will be comprised of zeros at first, in order to check whether a node already exists in L. If a node x is chosen, the element at index x of B will be set to one in constant time.Note that B is a different representation of the set of nodes in L. Both L and B are initialized only once at the start of the algorithm after performing the BFS.Since the number of levels is at most n, initialization of L and B can be done in time O(n).We represent T i as a list of nodes, which can be initialized in O(1).For each subtree, we generate a random integer k i by making use of Poisson distribution with mean λ.Generation of some random integer x from Poisson distribution normally takes O(x) time; starting from zero, the value of x is incremented one by one until the stopping condition is met [16].However, since we need k i , which is the number nodes to be selected, to lie between 1 and n, we terminate the process if we reach n before stopping condition is met, and we set k i to 1 if the process returns a zero value.This way, we only spend O(k i ) time to generate k i .Then, at each iteration, k i random nodes are chosen.To do this in time O(k i ), we can copy the nodes of T into an array, which is done at the beginning only once and hence takes O(n) time in total, and keep a separation index s that separates the selected elements from the ones that have not been selected yet, as explained in the proof of Lemma 4. Adding a chosen node to T i , L and B can be done in O (1).At the end of n such iterations, a total of n i=1 k i random choices are made and this is clearly less than or equal to n i=1 |V (T i )|.Now, it remains to show that generation of n subtrees can also be done in time O( n i=1 |V (T i )|) once T i , L and B are populated with initial randomly selected nodes.Our aim is to construct the minimal subtree of T connecting all the nodes in {x 1 , . . ., x ki }.To this end, at every iteration, we add the parents of all nodes of highest level to subtree T i and replace these nodes by their parents in L. The way we store the nodes in L enables us to access unprocessed nodes at a given level in constant time.However, to be able to start with the highest level in constant time initially, we need to know the highest level of the randomly selected k i nodes, which can be found in O(k i ).While processing some node x at level d, we first investigate whether its parent node P (x) has already been included in L by checking index P (x) of B in constant time.If it is one, it means that the parent node has already been included in L and T i , and we do not do anything.Otherwise, we append P (x) to the list at index (d − 1) of L and set the corresponding index of B to one.When done with x, we remove it from L in O(1) since x is an element of a list, and set index x of B to zero, which is again O(1).Recall that since T i is represented as a list, adding an element to T i can be done in O (1).Thus, we perform constant-time operations for each node under consideration in the inner for loop.
At the beginning of the while loop L has k i isolated nodes.Whenever two nodes in L have a common parent, the cardinality of L decreases by one at the next step.Noting that |L| indicates the number of currently existing connected components, which are to be attached together to reveal the subtree, the while loop to add new nodes to T i terminates when |L| = 1; that is, as soon as the minimal subtree has been found.Now, it is enough to notice that during the generation of each subtree T i using this method, we only consider and add the nodes of T which are in T i , and iterate only through the levels that are contained in T i .In other words, |L| becomes 1 and the while loop stops after exactly when |V (T i )| nodes are considered.Because we spend constant time for each of the |V (T i )| nodes, the overall complexity of the operations within the while loop becomes O(|V (T i )|) for each subtree T i .In order to obtain O(|V (T i )|) for the entire loop, we need to ensure that termination condition of the while loop can be checked in constant time.For this purpose, we keep the number of nodes in L as a variable, incrementing whenever a new node is added and decrementing upon removal of a node, which takes at most O(|V (T i )|) time.Finally, the arrays L and B should be reset before being passed to the next subtree.We know that L will contain a single node at the end of the while loop, and equivalently a single nonzero element will exist in B. When the loop terminates, we will know at which index (level) of L we were finally at.So, we can simply access the final node, set the element in B corresponding to that node to zero, and delete it from L, all in constant time.This way, the algorithm from while loop on to the next subtree completes in time O(|V (T i )|).In total, these operations add to the running time of Algorithm ConnectingNodes a term of O( We have thus presented two different methods for generating subtrees of a given tree, both of which result in an algorithm for generating random chordal graphs in timeO( In the next subsection we present yet another subtree generation method, having running time O(n 2 + n i=1 |V (T i )|).We include this algorithm for the sake of completeness and better comparison basis in our tests in the next section.This algorithm can for example be used when one is interested in generating chordal graphs with predominantly large maximal cliques as the density grows.

Algorithm PrunedTree
The input to this algorithm consists of a tree T on n nodes, an edge deletion fraction f , which is a rational number between 0 and 1, and a selection barrier s, which is a real number between 0 and 1.To generate subtree T i , we randomly select a fraction f of the edges on the tree and remove them.The number of edges to delete, say l, is calculated as (n − 1)f , which will leave l + 1 subtrees in total.We then determine the sizes of the l + 1 subtrees and store the distinct values.We pick a random size k i from the set of largest 100(1 − s)% of distinct values, and randomly choose a subtree with size k i .We repeat this n times to generate all the subtrees.One should note that we could simply select one connected component (subtree) at random without any preferential treatment; however, parameter s makes it easier to increase the density of the chordal graph by favoring larger components as the value of s advises.So, parameter s is an additional means to tune the edge density of the chordal graph; as its value increases, the size of the subtree to be selected tends to increase too.Increasing the edge deletion fraction f , however, tends to decrease the average size of subtrees emerging from deletion of edges.

Algorithm PrunedTree
Input: A tree T on n nodes, edge deletion fraction f , and selection barrier s Output: A set of n non-empty subtrees of T for i = 1 to n do Create a copy T of T Select randomly (n − 1)f edges of T and delete them from T Determine connected components of T and their sizes Select randomly a subtree size k i from the highest 100(1 − s)% subtree sizes.Select a random component of size k i and choose it as T i Output {T 1 , T 2 , . . ., T n } Lemma 6.The running time of Algorithm PrunedTree is O(n 2 ).
Proof.Creating a copy of T , deleting a subset of its edges, and computing the resulting connected components takes O(n) time by standard BFS.Now, we create an array A of size n, where each element in A is a linked list.For each connected component of T of size t, we add this component at the end of the list in A[t].Clearly, initializing A, and adding all subtrees to appropriate lists takes O(n) time.We also make an additional array B which simply stores the sizes of all subtrees, in sorted order.B can be created in time O(n), using A. We use B to find the highest 100(1 − s)% subtree sizes, by simply using the corresponding last portion of B. Random selection of a subtree of size k i is simply done by picking a subtree from the list A[k i ] in O(1) time.Thus every subtree requires O(n) time to generate.
Repeating this n times, the overall complexity of PrunedTree algorithm amounts to O(n 2 ).
We now obtain the following result using Theorem 2 together with Lemma 6.
Corollary 3. Algorithm ChordalGen, using the PrunedTree method, runs in time ).Let us conclude this section with a remark which applies to all of the three subtree generation methods.Algorithm ChordalGen does not guarantee the connectedness of its output graphs, as also revealed by our experimental results in Section 4. If connectedness is of particular importance and must be achieved, a possible modification to our algorithms can guarantee it without increasing the overall time complexity.To this end, we randomly choose one vertex from each connected component of the resulting graph.From each subtree corresponding to the set of vertices selected from the components, we pick one arbitrary node, and we form the last subtree with the union of paths on the host tree that connect these nodes.This way, lastly added vertex v is guaranteed to be linked to at least one vertex from each connected component of G − v, and so we ensure the connectedness of the output graph.This process is very similar to a single iteration of ConnectingNodes subroutine, thus by the proof of Lemma 5, it takes O( n i=1 |V (T i )|) time and does not affect the overall complexity of Algorithm ChordalGen.

Experimental Results
In this section, we give extensive test results to show what kind of chordal graphs are generated by Algorithm ChordalGen.In Tables 1-3 we give the experimental results of our presented methods GrowingSubtree, ConnectingNodes and PrunedTree, respectively.We show how the selection of the input parameters affects the number of resulting edges m and connected components ("# conn.comp.s").We also present the number of maximal cliques ("# maximal cliques"), and the minimum, maximum, and mean size for the maximal cliques ("min clique size", "max clique size", "mean clique size"), along with their standard deviation ("sd of clique sizes").For each parameter combination, we performed ten independent runs and report the average values across those ten runs.For each n, we tuned the parameter values in order to approximately achieve some selected average edge density values of 0.01, 0.1, 0.5, and 0.8, where edge density is defined as m n(n−1)/2 .We made all instances that we present here available at http://www.ie.boun.edu.tr/∼taskin/data/chordal/where we also offer a broad collection of relatively small-sized chordal graphs on 50 to 500 vertices with varying edge densities.
Algorithm ChordalGen together with GrowingSubtree is able to output connected chordal graphs unless density is too low, as the results in Table 1 show.In fact, for average edge density of 0.01, as n increases, the average number of connected components converge to one.If we examine the "min clique size" column, we see that it is usually one for cases where the average number of connected components is greater than one, suggesting that the reason for obtaining disconnected chordal graphs is largely due to a few isolated vertices and that the dominating rest of the graph is comprised of a connected body.The fact that the starting point of the subtrees is selected uniformly at random and we can directly control the maximum size of them leaves little chance for a set of subtrees not to intersect with any other and so lead to a separate connected component, unless the maximum subtree size k is very small.Table 2 reports the outputs of Algorithm ChordalGen using ConnectingNodes for generating subtrees.As the experimental results given in Table 2 reveal, Algorithm ConnectingNodes should be input very small λ values in order to achieve even quite dense graphs.Since even few number of selected nodes may result in large subtrees, which increases the chances of potential intersections with other subtrees and hence the number of edges in the output graph, the number of selected nodes has to be restricted via low values for λ, which is the main ingredient in setting the cardinality of node selection.Because of this, the selected node set, and hence the subtree, commonly be comprised of a single node, especially in graphs with low density.Therefore, when there are many single-node subtrees, intersections are not very likely.Thus, we observe many isolated vertices in the generated chordal graphs, as implied by the high number of connected components and minimum size of one in maximal cliques (see "min clique size" column) in ConnectingNodes method.consistency in this measure may be an indication of the lack of potential to produce a diverse range of maximal clique sizes.In our next set of experimental results we investigate how the sizes of the maximal cliques are distributed.Figures 1-4 show the average number of maximal cliques across ten independent runs in intervals of width five, for 1000, 2500, 5000, and 10000 vertices and varying edge densities.These figures consist of four subfigures, except Figure 4 which contains only the first three, and each subfigure is comprised of four histograms corresponding to four different average edge density values.The first three sub-figures on the top row show the results from Algorithm ChordalGen combined with each one of the three subtree generation methods presented, and the bottom row shows results of our implementation of Alg 1 [2].For a given n and average density value, the ranges of x-axes are kept the same in order to render the histograms comparable.The y-axes, however, have different ranges because maximum frequencies in histograms may vary drastically.The sizes of maximal cliques of graphs produced by GrowingSubtree method are dispersed fairly over the range, which becomes more noticeable with the increase in edge densities (as we proceed to the right).Frequencies do not show any obvious bias toward some portion of its domain, which may be considered as an indicator of the diversity of the chordal graphs produced, which is a desired characteristic of a random chordal graph generator.In ConnectingNodes method, however, the vast majority of cliques have size ten or less.The frequencies of larger cliques are barely noticeable compared to the dominant small-sized set.As the graphs become denser, frequencies of relatively larger cliques start to become visible too, but general behaviour remains the same.So, if chordal graphs with predominantly very small clique sizes are sought, ConnectingNodes method can be preferred.In PrunedTree method, the mode of the distribution shifts with the increase in edge densities and the sizes of cliques become clustered around some moderate value over the given range.As for Alg 1, the vast majority of maximal cliques of its output graphs have sizes of 2 to 15 for graphs with low densities of 0.01 and 0.1.With the increase in edge densities, frequencies of large-size maximal cliques become visible relative to the dominant small clique frequencies; however, all but the extremes of the range is barely used regardless of selection of n and edge density.

Conclusion
To the best of our knowledge, Algorithm ChordalGen is the first algorithm for random chordal graph generation based directly on subtree intersection characterization.It is very general and flexible in the sense that many different methods for subtree generation can be plugged in.
The three different subtree generation methods presented here each offer output graphs of different structures.As far as the distribution of maximal clique sizes are concerned, ConnectingNodes and PrunedTree methods yield graphs of somewhat more specific structure in the sense that the sizes of maximal cliques are always clustered in the very initial portion in ConnectingNodes method, and in PrunedTree method in the initial part of the range for low densities, in middle portions for moderate to high densities.GrowingSubtree method, though, in addition to its advantageous time complexity, generates the most varied chordal graphs compared to both existing methods and to other two of our suggested methods.Depending on the context and structural needs for the output graph, Algorithm ChordalGen can be used with one of the three subroutines chosen suitably in order to produce chordal graphs of varying size and density.For those who prefer to test various algorithms on chordal graphs without focusing on the generation procedure, we offer all instances used in this paper as well as a broad collection of relatively small-sized chordal graphs on 50 to 500 vertices with varying edge densities at http://www.ie.boun.edu.tr/∼taskin/data/chordal/.
Last but not least, our work gives rise to an open question about chordal graphs which has not been addressed to date to the best of our knowledge: what is the worst case time complexity of a chordal graph generation algorithm which produces the entire set of nodes of all subtrees in a subtree intersection model?In the current paper, we give a lower bound, namely Ω(mn 1/4 ), on the time complexity.However, the exact worst case time complexity remains unknown.

Theorem 2 .
Algorithm ChordalGen generates a chordal graph with n vertices in time O(S + n i=1 |V (T i )|), where O(S) is the time required to generate n subtrees of a host tree on n nodes.Proof.By Theorem 1, graph G generated by Algorithm ChordalGen is chordal.Clearly G has n vertices.Let m be the number of edges of G. Let us go through the steps of the algorithm to argue for the running time.
(a) Results from Algorithm ChordalGen with GrowingSubtree method (b) Results from Algorithm ChordalGen with ConnectingNodes method (c) Results from Algorithm ChordalGen with PrunedTree method (d) Results from our implementation of Alg 1 [2]

Fig. 1 :
Fig. 1: Histograms of maximal clique sizes for n = 1000 and average edge densities 0.01, 0.1, 0.5, and 0.8 (from left to right) (a) Results from Algorithm ChordalGen with GrowingSubtree method (b) Results from Algorithm ChordalGen with ConnectingNodes method (c) Results from Algorithm ChordalGen with PrunedTree method (d) Results from our implementation of Alg 1 [2]

Fig. 2 :
Fig. 2: Histograms of maximal clique sizes for n = 2500 and average edge densities 0.01, 0.1, 0.5, and 0.8 (from left to right) (a) Results from Algorithm ChordalGen with GrowingSubtree method (b) Results from Algorithm ChordalGen with ConnectingNodes method (c) Results from Algorithm ChordalGen with PrunedTree method (d) Results from our implementation of Alg 1 [2]

Table 1 :
Experimental results of Algorithm ChordalGen with GrowingSubtree method

Table 2 :
Experimental results of Algorithm ChordalGen with ConnectingNodes method