Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

An Optimal Algorithm for Prufer Codes*

VIEWS: 102 PAGES: 6

This paper studies the algorithms for coding and decoding Prufer codes of a labeled tree. The algorithms for coding and decoding Prufer codes of a labeled tree in the literatures require O(nlogn) time usually. Although there exist linear time algorithms for Prufer-like codes, the algorithms utilize the integer sorting algorithms. The special range of the integers to be sorted is utilized to obtain a linear time integer sorting algorithm. The Prufer code problem is reduced to integer sorting. In this paper we consider the Prufer code problem in a different angle and a more direct manner. We start from a nave algorithm, then improved it gradually and finally we obtain a very practical linear time algorithm. The techniques we used in this paper are of interest in their own right. [PUBLICATION ABSTRACT]

More Info
									J. Software Engineering & Applications, 2009, 2: 111-115
doi:10.4236/jsea.2009.22016 Published Online July 2009 (www.SciRP.org/journal/jsea)



An Optimal Algorithm for Prufer Codes*
Xiaodong Wang1, 2, Lei Wang3, Yingjie Wu1
1
 Department of Computer Science, Fuzhou University, Fuzhou, China; 2Department of Computer Science, Quanzhou Normal Uni-
versity, Quanzhou, China; 3College of Computing, Georgia Institute of Technology, Atlanta GA 30332, USA.
Email: wangxd@fzu.edu.cn

Received February 19th, 2009; revised February 23rd, 2009; accepted February 24th, 2009.

ABSTRACT
This paper studies the algorithms for coding and decoding Prufer codes of a labeled tree. The algorithms for coding
and decoding Prufer codes of a labeled tree in the literatures require O(nlogn) time usually. Although there exist
linear time algorithms for Prufer-like codes [1,2,3], the algorithms utilize the integer sorting algorithms. The special
range of the integers to be sorted is utilized to obtain a linear time integer sorting algorithm. The Prufer code problem
is reduced to integer sorting. In this paper we consider the Prufer code problem in a different angle and a more direct
manner. We start from a naïve algorithm, then improved it gradually and finally we obtain a very practical linear time
algorithm. The techniques we used in this paper are of interest in their own right.

Keywords: Design of Algorithm, Labeled Trees, Prufer Codes, Integer Sorting

1. Introduction
Labeled trees are of interest in practical and theoretical          est volumes of graphs.
areas of computer science. For example, Ethernet has a                 Let T be a labeled tree whose nodes are numbered
unique path between terminal devices, thus being a tree:            from 0 to n-1. For some vertex v in T, the degree of v,
labeling the tree nodes is necessary to uniquely identify           denoted by d[v], is the number of edges incident to v. If
each device in the network. An interesting alternative to           d[v]=1, then v is called a leaf. According to Prufer’s
the usual representations of tree data structures in com-           proof, any sequence of n-2 numbers, each number in
puter memories is based on coding labeled trees by                  {0,1,…,n-1} can determine a unique labeled tree of n
means of strings of node labels. This representation was            nodes. Such a number sequence is the Prufer code of a
first used in the proof of Cayley’s theorem [4] to show             labeled tree. Algorithm A is the straightforward imple-
a one-to-one correspondence between free labeled trees              mentation of Prufer’s proof.
on n nodes and strings of length n-2. In addition to this
purely mathematical use, string-based coding of trees                  Algorithm A
has many practical applications. For instance, they                    Input: A labeled tree T of n nodes as a list of n-1
make it possible to generate random uniformly distrib-              edges.
uted trees and random connected graphs: the generation                 Output: c, the Prufer code of T.
of a random string followed by the use of a fast decod-                Method:
ing algorithm is typically more efficient than random                  Step 1. B {0,1,…,n-1}.
tree generation by the addition of edges, since in the                 Step 2. For i 0 to n-3 do
latter case one must pay attention not to introduce cy-                Step 2.1. x min{k B: k is a leaf }.
cles. In addition, tree codes are employed in genetic
                                                                       Step 2.2. B B-{x}.
algorithms, where chromosomes in the population are
represented as strings of integers, and in heuristics for              Step 2.3. Remove x and its incident edge (x, y) from T.
computing minimum spanning trees with additional                       Step 2.4. c[i] y.
constraints, e.g., on the number of leaves or on the di-               Step 3. Return c.
ameter of the tree itself. Not last, tree codes are used for           End of Algorithm
data compression and for computing the tree and for-                   For example, let the input labeled tree T be the graph
*
 Supported by Natural Science Foundation of China under Grant No.   depicted in Figure 1. After the Algorithm A terminates,
60172017 and Natural Science Foundation of Fujian under Grant No.
A0510008.                                                        
								
To top