Acessibilidade / Reportar erro

A compact code for k-trees

Abstracts

In this paper, we propose a new representation for k-trees - the compact code, which reduces the required memory space from O(nk) to O(n). The encoding and decoding algorithms, based on a simplification of a priority queue, are linear and very simple. As long as the k-tree is represented by its compact code, the exact vertex coloring problem can be solved in time O(n).

k-trees; Prüfer code; compact code


Neste artigo, propomos uma nova representação para k-árvores - o código compacto, que reduz o espaço de memória de armazenamento de O(nk) para O(n). Os algoritmos de codificação e decodificação, baseados em uma simplificação de uma lista de prioridades, são lineares e muito simples. Uma vez que a k-árvore esteja representada pelo seu código compacto, o problema da coloração exata de vértices pode ser resolvido em tempo O(n).

k-árvores; código de Prüfer; código compacto


A compact code for k-trees

Lilian MarkenzonI,* * Corresponding author / autor para quem as correspondências devem ser encaminhadas ; Oswaldo VernetII; Paulo Renato da Costa PereiraIII

INúcleo de Computação Eletrônica Universidade Federal do Rio de Janeiro (UFRJ) Rio de janeiro – RJ, Brazil markenzon@nce.ufrj.br

IINúcleo de Computação Eletrônica Universidade Federal do Rio de Janeiro (UFRJ) Rio de Janeiro – RJ, Brazil oswaldo@nce.ufrj.br

IIIInstituto Militar de Engenharia (IME) Rio de Janeiro – RJ, Brazil prenato@ime.eb.br

ABSTRACT

In this paper, we propose a new representation for k-trees – the compact code, which reduces the required memory space from O(nk) to O(n). The encoding and decoding algorithms, based on a simplification of a priority queue, are linear and very simple. As long as the k-tree is represented by its compact code, the exact vertex coloring problem can be solved in time O(n).

Keywords: k-trees; Prüfer code; compact code.

RESUMO

Neste artigo, propomos uma nova representação para k-árvores – o código compacto, que reduz o espaço de memória de armazenamento de O(nk) para O(n). Os algoritmos de codificação e decodificação, baseados em uma simplificação de uma lista de prioridades, são lineares e muito simples. Uma vez que a k-árvore esteja representada pelo seu código compacto, o problema da coloração exata de vértices pode ser resolvido em tempo O(n).

Palavras-chave:k-árvores; código de Prüfer; código compacto.

1. Introduction

The family of k-trees, introduced by Harary & Palmer (1968) and revisited somewhat later by Rose (1974), has an inductive definition which naturally extends the definition of a tree. As an important subclass of chordal graphs, k-trees have deserved careful attention of many researchers, either related to algorithmic (Markenzon et al., 2006; Proskurowski, 1984) or theoretical aspects (Cai & Maffray, 1993; Lotker et al., 2006; Rose, 1974; among several others). In Justel & Markenzon (2000), further properties of the Lexicographic Breadth-First Search were analyzed, introducing an efficient algorithm for recognizing k-trees.

The idea of associating codewords to the labelled graphs of a specific family is not recent: in Prüfer (1918), a one-to-one correspondence between the set of (n- 2)-tuples of the integers {1, 2, ..., n} and the set of all labelled 1-trees on n vertices was already proved to hold. A codeword must of course univocally represent a certain graph belonging to the family and, conversely, each graph of the family must be assigned a unique codeword. Besides sparing computer storage significantly, a well designed encoding scheme may lead to more efficient algorithms for solving algorithmic problems for the family.

Rényi & Rényi (1970) extended Prüfer's original codification to a broader family: the labelled rooted k-trees. Initially, the authors defined an immediate extension, the primitive Prüfer code, which applied only if the k-tree had the k highest numbered vertices as its root-clique. This constraint was finally eliminated, yielding the redundant Prüfer code. Later, Chen (1993) proposed a smaller code for k-trees, based on an intermediate representation using doubly labelled trees. We proposed, in Pereira et al. (2005), an O(n)-space representation, called the reduced Prüfer code, which is equivalent in size to Chen's code and, in Pereira et al. (2005a), we provided the first attempts to develop linear time algorithms for this code. Recently, Caminiti et al. (2007) presented a new approach for the same problem, using an intermediate code to obtain their results.

The usual representation of k-trees through adjacency lists requires O(nk) memory space. In this paper, an O(n)-space representation is proposed, called the compact code, which is equivalent in size to Chen's code but much easier to compute. Its applicability is illustrated in Section 7, were the exact vertex coloring problem is solved. The solution presented can be implemented by an algorithm with worst-case time complexity of O(n), in contrast to the O(m) traditional one.

2. Basic Concepts on Chordal Graphs

Let G = (V, E) be a graph, where | E | = m and | V | = n > 0. The set of neighbors of a vertex vV is denoted as AdjG(v) = {wV | {v, w} ∈ E}. A vertex v is said to be simplicial in G when AdjG(v) is a clique in G, i.e., a subset of V that induces a complete subgraph of G.

A perfect elimination ordering (peo) of G = (V, E) is a bijective function σ:{1, ..., n} → V such that, for 1 < i < n, σ(i) is a simplicial vertex in the induced subgraph Gi = G[{σ(i), ..., σ(n)}]. A peo is ultimately an arrangement of V in a sequence σ(V) = [σ(1), ..., σ(n)], which will be shortly denoted as σ(V) = [v1, ..., vn]. The position of vertex v in σ is given by σ-1(v). It is well known that a graph admits a peo if, and only if, it is chordal, i.e., has no chordless cycle with length greater than 3. Moveover, a given chordal graph G may admit several peos (Chandran et al., 2003; Golumbic, 2004).

The following lemma establishes basic properties concerning chordal graphs and simplicial vertices.

Lemma 1. (Blair & Peyton, 1993) In a graph G = (V, E), vV is simplicial if, and only if, v belongs to exactly one maximal clique.

Once a peo σ (V) = [σ (i), ..., σ (n)] is established for a chordal graph G = (V, E), it is possible to define, for each vertex vV, the set Xσ (v) = {wAdjG(v) | σ -1(w) > σ -1(v)}, called the monotone adjacency set of v. In Theorem 2, an interesting result is shown concerning these sets, which will be important to the further development of this paper.

Theorem 2. Let G = (V, E), n > 0, be a connected chordal graph and σ, a peo of G. For each i such that 1 < i < n, there exists a unique j satisfying: i < j < n, vjXσ (vi) and Xσ (vi) ⊆ {vj} ∪ Xσ (vj).

Proof. The set Ii = {σ -1(w) | wXσ (vi)} contains all feasible values for j, since the condition vjXσ (vi) must be satisfied. Take j = min Ii and let w Xσ(vi). We must prove that w ∈ {vj} ∪ Xσ(vj).

– If w = vj, the conclusion is trivial;

– If wvj, as Xσ(vi) is a clique and vjXσ(vi), wAdjG(vj). Since j = min Ii, σ-1(w) > j = σ-1(vj). Hence, wXσ(vj).

For any other value of j belonging to Ii the condition Xσ(vi) ⊆ {vj} ∪ Xσ(vj) does not hold. Thus, j is unique.

3. Redundant Prüfer Code for k-Trees

In Rényi & Rényi (1970), the redundant Prüfer code for k-trees was defined and used by the authors in the counting of labelled k-trees. In this section, we summarize some results about k-trees that allow us to present later an efficient code for this family.

A well known subclass of chordal graphs, the k-trees, k > 0, can be inductively defined as follows:

– Every complete graph with k vertices is a k-tree;

– If G = (V, E) is a k-tree, v V and QV is a k-clique of G, then G' = (V ∪ {v}, E ∪ {{v, w} | wQ}) is also a k-tree;

– Nothing else is a k-tree.

A k-tree G with n > k vertices have exactly n- k maximal cliques, each of them with k+1 vertices. Moreover, simplicial vertices in k-trees with n > k have degree k and are so called k-leaves. It can be proved that any maximal clique of G has at most one k-leaf. The number of simplicial vertices in a k-tree has an interesting behavior: if n = k or n = k+1, every vertex is simplicial; for n > k+1, there are at least 2 (as in every chordal graph) and at most n- k simplicial vertices. k-trees can be recognized through the lexicographic breadth-first search in time O(m), by examining the sizes of the labels associated to the vertices during the search (Justel & Markenzon, 2000).

From the aforementioned concepts, it is straightforward to derive a procedure for constructing a peo for a k-tree G: starting with the empty sequence, at each step, choose a simplicial vertex of G, append it to the sequence and remove it from G (along with its incident edges). When V = {1, ..., n}, n > 0, (or any other totally ordered set), it is possible to particularize this procedure in order to obtain a unique peo: at each step, the least simplicial vertex is chosen. Since this process of successively removing the least simplicial vertex is essentially the same one employed in Prüfer's algorithm for coding labelled trees, the obtained peo will be called the Prüfer peo (ppeo) of G.

Being σ the ppeo of a k-tree G = ({1, ..., n}, E), we define the redundant Prüfer code of G the sequence of pairs

PC(G) = [(vi, X(vi)) | i = 1, ..., n].

The redundant Prüfer code of k-trees has several peculiarities, summarized in Lemma 3, whose proof is straightforward.

Lemma 3. Let G = ({1, ..., n}, E) be a k-tree, n > k, and PC(G) = [(vi, X(vi)) | i = 1, ..., n] its redundant Prüfer code. The following properties hold:

1. | X(vi) | = k, i = 1, ..., n- k;

2. | X(vi) | = n- i, i = n- k+1, ..., n;

3. {vi} ∪ X(vi), i = 1, ..., n- k, are the maximal cliques of G;

4. {vi} ∪ X(vi) = X(vi-1), i = n- k+1, ..., n.

The set {vn- k} ∪ X(vn- k) is a maximal clique of G (hence, with size k+1) called the residual clique of G. It will be denoted ξ (G).

Consider, for example, the 3-tree with 10 vertices depicted in Fig.1. Its redundant Prüfer code is

PC = [(3, {5,6,9}), (4, {2,9,10}), (5, {6,9,10}), (7, {2,9,10}), (8, {1,2,6}),

(1, {2,6,10}), (2, {6,9,10}), (6,{9,10}), (9, {10}), (10, &Oslash )].


The residual clique ξ (G) = {2, 6, 9, 10} has size k+1 = 4.

The properties stated in Lemma 3 allow us to particularize Theorem 2, from the previous section, to k-trees.

Theorem 4. Let G = ({1, ..., n}, E), n > k, be a k-tree and PC(G) = [(vi, X(vi)) | i = 1, ..., n] its redundant Prüfer code. For each i such that 1 < i < n- k, there exists a unique j satisfying i < j < n- k+1, vjX(vi) and X(vi) ⊆ {vj} ∪ X(vj).

Corollary 5. Let i and j be indices related to each other according to Theorem 4. Thus,

4. The Compact Code for k-trees

The redundant Prüfer code of a k-tree demands half of the number of symbols required by the traditional representation through adjacency sets. However, the occupied space is O(m) in both cases, which means ultimately O(nk). In this section we show how an O(n)-space representation can be obtained for this family of graphs, no matter the value of k.

The compact code of a k-tree G = ({1, ..., n}, E), n > k, is the ordered pair CC(G) = (ξ (G), S), where ξ (G) is the residual clique of G and S = [(α1, β1), (α2, β2), ..., (αn-k-1, βn-k-1)] is a sequence of pairs of vertices determined as follows:

For i = 1, 2, ..., n- k- 1:

Let j be the index corresponding to i, according to Theorem 4;

– αi = vj;

- βi = vX(vj) - X(vi), if j < n- k, or βi = 0, if j = n- k+1.

From Corollary 5, if j < n- k, | X(vj) - X(vi) | = 1 and βi is the unique vertex belonging to X(vj) - X(vi); if j = n- k+1, the result of the set difference is empty and βiis set to 0 (a value that does not correspond to any valid vertex).

Since | ξ (G) | = k+1 and | S | = n- k+1, the values of n and k can be deduced from | ξ (G) | and | S | and do not need to appear explicitly in the compact code. Notice that CC(G) is not defined for k-trees with n = k and, if n = k+1, CC(G) = (V, [ ]).

Applying the definition, the compact code of the 3-tree in Fig. 1 is:

CC(G) = ({2,6,9,10}, [(5,10), (2,6), (6,0), (2,6), (1,10), (2,9)]).

5. The Encoding Algorithm

The process of obtaining the compact code CC(G) for a given k-tree G = ({1, ..., n}, E) is called encoding and can be accomplished in two steps:

Step 1. Compute PC(G) = [(vi, X(vi)) | i = 1, ..., n];

Step 2. Compute CC(G) = (ξ (G), S), using the definition.

In order to develop an algorithm to perform the encoding process, we must give a special attention to Step 1, since Step 2 consists simply in the application of the definition. Given a k-tree G = ({1, ..., n}, E), the algorithm for obtaining its redundant Prüfer code removes successively from G the least k-leaf and appends to the code the vertex and the clique formed by its neighbors.

Some implementation issues must be addressed in order to obtain an efficient algorithm. The main difficult is the determination of the ppeo, i.e., the computation, at each step, of the least k-leaf. A traditional priority queue can be used to store the k-leaves of graph G and the vertices that become simplicial during the process, providing a way to identify the least numbered one. However, the time complexity of employing this data structure is O(n log n).

Based on the specificity of the problem, we are able to define a particular case of priority queue, which is similar but even simpler than the (L,U)-bounded priority queue presented in Markenzon et al. (2006) as the elements and their priorities coincide.

Since the k-leaves are recognized by their degree (a vertex v is a k-leaf if degree(v) = k), the only data structure needed to implement the priority queue is the array that stores this information. At the first iteration, the algorithm searches this array sequentially looking for the least k-leaf of the current graph G1 = G, which is then stored in the variable last. Vertex vi, i = 1, is determined. At the end of the i-th iteration, vi is removed from Gi, yielding Gi+1. The array degree must be updated (this updating is equivalent to an Insert operation). The maximal clique {vi} ∪ X(vi) disappears from Gi and any vertex of X(vi) may become a simplicial vertex. However, as we know that any maximal clique of a k-tree G has at most one simplicial vertex, only one new k-leaf w can appear in Gi+1. Two cases can happen:

case 1: w > last, that is, w is not the least simplicial vertex of Gi+1;

case 2: w < last. In this case, w must be the next simplicial vertex chosen.

Differently than for case 1, for the second case a new variable must be defined, completing the implementation of the priority queue. The variable pend stores w which will be the next mandatory simplicial vertex chosen. If there is a pending element, it is simply removed; otherwise, the next element with lowest priority is sought and removed. This computation is repeated until it remains only the residual clique in the graph. At this point, a simple ordering of its elements completes the ppeo.

Graph G, represented by its adjacency lists, is the input of the algorithm.

Procedure DeleteMin(v);

if pend > 0 then

vpend; pend ← 0;

else

while degree[last] ≠ k do lastlast + 1;

vlast;

degree(v) ← 0;

Procedure Encode-Step1;

for u ← 1, ..., n do degree(u) ← | AdjG(u) |;

pend ← 0; last ← 1;

for i ← 1, ..., n- k- 1 do

DeleteMin(vi);

X(vi) ← {wAdjG(vi) | degree(w) ≠ 0};

for all wX(vi) do

degree(w) ← degree(w) - 1;

if (degree(w) = k) and (w < last) then pendw;

pend ← 0; last ← 1;

for in- k, ..., n do

DeleteMin(vi);

X(vi) ← {wAdjG(vi) | degree(w) ≠ 0};

Procedure Encode-Step2;

for i ← 1, ..., n do σ-1(vi) = i; S ← [ ];

for i ← 1, ..., n - k - 1 do

j ← min{σ-1(u) | uX(vi)};

αivj; βi ← 0;

if jn- k+1 then βiX(vj) - X(vi);

SS || (αi, βi);

CC(G) ← ({vn- k, ..., vn}, S);

The encoding algorithm is linear, as shown below.

Procedure Encode-Step1 is linear. The initialization of the array degree takes O(m). At each iteration the least simplicial vertex is chosen. During the DeleteMin operation two situations may arise: if there is a pending element, it is simply removed; otherwise, the next element with lowest priority is sought and removed. The first one takes O(1); the second, an overall complexity of O(n). The deletion of a simplicial vertex v is O(1); the vertices of Adj(v) that do not appeared yet at the ppeo constitute the monotone adjacency set X(v). So, the overall complexity is O(m). Procedure Encode-Step2 is also linear. In the proof of Theorem 2, we show that j is the first vertex of X(vi) that appears in the ppeo. At each iteration, min is determined. So, it takes .

6. The Decoding Algorithm

The inverse task is called decoding: given the pair (ξ , S), being | S | > 0, the redundant code of G, PC(G) = [(vi, X(vi)) | i = 1, ..., n], must be determined. We present three lemmas that support the decoding algorithm.

Lemma 6. Let G be a k-tree, n > k+1, CC(G) its compact code and σ = [v1, ..., vn] its ppeo. For i = n- k- 1, ..., 1, if βi = 0 then X(vi) = ξ - {vn- k} else X(vi) = {αi} ∪ X(αi) - {βi}.

Proof. By definition, if j = n- k+1 then βi = 0. From Theorem 4, X(vi) = {vn-k+1} ∪ X(vn-k+1) = X(vn-k). Also by definition, if βi ≠ 0, αi = vj and {βi} = X(αi) - X(vi). Since αiX(αi), then X(vi) = {αi} ∪; X(αi) - {βi}.

Lemma 7. Let G be a k-tree, n > k+1 and CC(G) its compact code. For i = 1, ..., n- k- 1:

Proof. By induction on the size of S.

- Let t = n- k- 1. By Lemma 3, X(vn- k- 1) ⊂ {vn-k} ∪ X(vn-k). By definition, αn-k-1 = vn-k or αn-k-1 = vn-k+1, i.e., αn-k-1ξ . Then S has one pair and

- Suppose that the lemma is valid for i+1, 1 < i < n- k- 1. Then

- From Lemma 6, (i) X(vi) = {αi} ∪; X(αi) - {βi} or (ii) X(vi) = X(vn- k) and αi = vn-k+1X(vn-k+2). Then

By (1),

Lemma 8. The vertices vi, i = 1, ..., n - k- 1 are determined as follows:

Proof. By definition, vi is the least simplicial vertex in the induced subgraph Gi = G[{vi, vi+1, ..., vn}]. Then and

The decoding algorithm consists of the following steps:

Step 1. Set k = |ξ| - 1 and n = |S| + |ξ|;

Step 2. Sort set ξ ascendingly obtaining the pairs (vn-k, X(vn-k)), ..., (vn, O );

Step 3. Compute [v1, ..., vn- k- 1], subsequence of σ;

Step 4. Compute X(vi), for i = n- k- 1, ..., 1.

Step 1 is trivial. Step 2 computes the pairs originated from the residual clique.

The third step computes [v1, ..., vn- k- 1], based on Lemma 8. The set of feasible vertices must be determined (and updated) for the choice of the minimum. The terms ξ and are well known. The set is actually a multiset and its composition is settled by the number of times that a vertex appears as a label in the sequence S. So, the frequency of each vertex must be stored and updated at each iteration of the algorithm. The implementation of Step 3 uses the same simplified priority queue mentioned in Section 5.

After having obtained the ppeo, the monotone adjacency sets X(vi), i = n- k- 1, ..., 1, must be determined (Step 4). Lemma 6 shows how to compute these sets. Notice that the ppeo is explored in the reverse ordering.

The decoding algorithm is also linear; the proof is similar to the one presented for the encoding algorithm.

7. An Application

Besides providing a more concise representation for a k-tree, the compact code can support better solutions for some problems. A straightforward example is the determination of the ppeo, whose solution can be achieved in time O(n), according to the results presented in Section 6. Another example is provided in this section.

Exact vertex coloring is a very important problem in algorithmic graph theory, which can be solved through polynomial algorithms only for some particular families of graphs. The problem consists in associating colors to the vertices of a graph, so that the endpoints of each edge receive distinct colors, using the minimum number of colors.

In particular, every chordal graph G can be exactly colored in time O(m) using ω(G) distinct colors, where ω(G) is the size of the largest clique in the graph. Due to this strong result, no further efforts are usually made to solve the problem for its subclasses. We show here a solution for a k-tree represented by its compact code in time O(n).

If a k-tree G = ({1, ..., n}, E), n > k, is represented by its compact code, the residual clique ξ (G) has size k+1 and demands exactly (k+1) colors. The remaining vertices can be colored following Lemma 9.

Lemma 9. Let G = ({1, ..., n}, E), n > k, be a k-tree, CC(G) = (ξ (G), S) its compact code and σ = [v1, ..., vn] its ppeo. Assume that the vertices vn- k, ..., vn are already colored with k+1 distinct colors. Thus, for i = n- k- 1, ..., 1:

An O(n)-time procedure can easily implement the solution, in contrast to the corresponding O(m)-time algorithm for chordal graphs.

Acknowledgement

This work was supported by grants 306893/2006-1 and 473603/2007-1, CNPq, Brazil.

Recebido em 11/2008; aceito em 04/2009

Received November 2008; accepted April 2009

  • (1) Blair, J.R.S. & Peyton, B. (1993). An Introduction to Chordal Graphs and Clique Trees. Graph Theory and Sparse Matrix Computation, IMA 56, 1-29.
  • (2) Chen, W.Y.C. (1993). A Coding Algorithm for Rényi Trees. Journal of Combinatorial Theory, series A, 63, 11-25.
  • (3) Chandran, L.S.; Ibarra, L.; Ruskey, F. & Sawada, J. (2003). Generating and Characterizing the Perfect Elimination Orderings of a Chordal Graph. Theoretical Computer Science, 307, 303-317.
  • (4) Cai, L. & Maffray, F. (1993). On the Spanning k-Tree Problem. Discrete Applied Mathematics, 44, 139-156.
  • (5) Caminiti, S., Fusco, E.G. & Petreschi, R. (2007). A Bijective Code for k-Trees with Linear Time Encoding and Decoding. LNCS, 4614, 408-420.
  • (6) Golumbic, M.C. (2004). Algorithmic Graph Theory and Perfect Graphs 2nd edition. Academic Press, New York.
  • (7) Harary, F. & Palmer, E.M. (1968). On Acyclic Complexes. Mathematika, 15, 115-122.
  • (8) Justel. C.M. & Markenzon, L. (2000). Lexicographic Breadth First Search and k-trees. Proc. of JIM'2000 Secondes Journées de l'Informatique Messine, 23-28, Metz, France.
  • (9) Lotker, Z.; Majumdar, D.; Narayanaswamy, N.S. & Weber, I. (2006). Sequences Characterizing k-trees. Proc. of COCOON'06, LNCS, 4112, 216-225.
  • (10) Markenzon, L.; Justel, C.M. & Paciornik, N. (2006). Subclasses of k-trees: Characterization and Recognition. Discrete Applied Mathematics, 154, 818-825.
  • (11) Markenzon, L.; Vernet, O. & Pereira, P.R.C. (2006). (L,U)-Bounded Priority Queues. Proc. of CLAIO'06
  • (12) Proskurowski, A. (1984). Separating Subgraphs in k-trees: Cables and Caterpillars. Discrete Mathematics, 49, 275-285.
  • (13) Prüfer, A. (1918). Neuer Beweis eines Satzes über Permutationen. Archiv der Mathematik und Physik, 27, 142-144.
  • (14) Pereira, P.R.C.; Markenzon, L. & Vernet, O. (2005). The Reduced Prüfer Code for Rooted Labelled k-trees. Electronic Notes in Discrete Mathematics, 22, 135-139.
  • (15) Pereira, P.R.C.; Markenzon, L. & Vernet, O. (2005a). Código Reduzido de Prüfer para k-Árvores Rotuladas. Anais do XXXVI Simpósio Brasileiro de Pesquisa Operacional, 2335-2342 (in portuguese).
  • (16) Rose, D.J. (1974). On Simple Characterizations of k-trees. Discrete Mathematics, 7, 317-322.
  • (17) Rényi, C. & Rényi, A. (1970). Prüfer Code for k-trees. In: Combinatorial Theory and its Applications [edited by P. Erdös et al.], 945-971.
  • *
    Corresponding author / autor para quem as correspondências devem ser encaminhadas
  • Publication Dates

    • Publication in this collection
      03 Feb 2010
    • Date of issue
      Dec 2009

    History

    • Received
      Nov 2008
    • Accepted
      Apr 2009
    Sociedade Brasileira de Pesquisa Operacional Rua Mayrink Veiga, 32 - sala 601 - Centro, 20090-050 Rio de Janeiro RJ - Brasil, Tel.: +55 21 2263-0499, Fax: +55 21 2263-0501 - Rio de Janeiro - RJ - Brazil
    E-mail: sobrapo@sobrapo.org.br