Gray Codes for Reflectable Languages

Similar documents
1. The collection of the vowels in the word probability. 2. The collection of real numbers that satisfy the equation x 9 = 0.

A DYNAMIC ACCESS CONTROL WITH BINARY KEY-PAIR

Learning Convention Propagation in BeerAdvocate Reviews from a etwork Perspective. Abstract

Extracting Partition Statistics from Semistructured Data

Data Structures in Java

1 The Knuth-Morris-Pratt Algorithm

Drawing lines. Naïve line drawing algorithm. drawpixel(x, round(y)); double dy = y1 - y0; double dx = x1 - x0; double m = dy / dx; double y = y0;

Approximate logic synthesis for error tolerant applications

The Happy Ending Problem

System-Level Parallelism and Throughput Optimization in Designing Reconfigurable Computing Applications

A Novel Validity Index for Determination of the Optimal Number of Clusters

A Novel Bit Level Time Series Representation with Implication of Similarity Search and Clustering

Algorithms for External Memory Lecture 6 Graph Algorithms - Weighted List Ranking

Automatic Physical Design Tuning: Workload as a Sequence Sanjay Agrawal Microsoft Research One Microsoft Way Redmond, WA, USA +1-(425)

Parallelizing Frequent Web Access Pattern Mining with Partial Enumeration for High Speedup

Lecture Notes of Möbuis Transformation in Hyperbolic Plane

Pipelined Multipliers for Reconfigurable Hardware

An Optimized Approach on Applying Genetic Algorithm to Adaptive Cluster Validity Index

A {k, n}-secret Sharing Scheme for Color Images

Analysis of input and output configurations for use in four-valued CCD programmable logic arrays

Calculation of typical running time of a branch-and-bound algorithm for the vertex-cover problem

On - Line Path Delay Fault Testing of Omega MINs M. Bellos 1, E. Kalligeros 1, D. Nikolos 1,2 & H. T. Vergos 1,2

HEXA: Compact Data Structures for Faster Packet Processing

Colouring contact graphs of squares and rectilinear polygons de Berg, M.T.; Markovic, A.; Woeginger, G.

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Test I Solutions

SAND Unlimited Release Printed November 1995 Updated November 29, :26 PM EXODUS II: A Finite Element Data Model

Abstract. Key Words: Image Filters, Fuzzy Filters, Order Statistics Filters, Rank Ordered Mean Filters, Channel Noise. 1.

Outline: Software Design

A Load-Balanced Clustering Protocol for Hierarchical Wireless Sensor Networks

Boosted Random Forest

C 2 C 3 C 1 M S. f e. e f (3,0) (0,1) (2,0) (-1,1) (1,0) (-1,0) (1,-1) (0,-1) (-2,0) (-3,0) (0,-2)

Unsupervised Stereoscopic Video Object Segmentation Based on Active Contours and Retrainable Neural Networks

Z Combinatorial Filters: Sensor Beams, Obstacles, and Possible Paths

Divide-and-conquer algorithms 1

An Efficient Ranking Algorithm of t-ary Trees in Gray-code Order

Implementing Load-Balanced Switches With Fat-Tree Networks

Dynamic Algorithms Multiple Choice Test

A radiometric analysis of projected sinusoidal illumination for opaque surfaces

Particle Swarm Optimization for the Design of High Diffraction Efficient Holographic Grating

Algorithms, Mechanisms and Procedures for the Computer-aided Project Generation System

Detection and Recognition of Non-Occluded Objects using Signature Map

EXODUS II: A Finite Element Data Model

特集 Road Border Recognition Using FIR Images and LIDAR Signal Processing

Chromaticity-matched Superimposition of Foreground Objects in Different Environments

Naïve Bayesian Rough Sets Under Fuzziness

A Partial Sorting Algorithm in Multi-Hop Wireless Sensor Networks

Performance of Histogram-Based Skin Colour Segmentation for Arms Detection in Human Motion Analysis Application

Accommodations of QoS DiffServ Over IP and MPLS Networks

Adaptive Implicit Surface Polygonization using Marching Triangles

Incremental Mining of Partial Periodic Patterns in Time-series Databases

Sequential Incremental-Value Auctions

A Unified Subdivision Scheme for Polygonal Modeling

Trajectory Tracking Control for A Wheeled Mobile Robot Using Fuzzy Logic Controller

Z Combinatorial Filters: Sensor Beams, Obstacles, and Possible Paths

Improved Circuit-to-CNF Transformation for SAT-based ATPG

Multi-Piece Mold Design Based on Linear Mixed-Integer Program Toward Guaranteed Optimality

Diffusion Kernels on Graphs and Other Discrete Structures

The Minimum Redundancy Maximum Relevance Approach to Building Sparse Support Vector Machines

Sparse Certificates for 2-Connectivity in Directed Graphs

3-D IMAGE MODELS AND COMPRESSION - SYNTHETIC HYBRID OR NATURAL FIT?

A Unique Common Fixed Point Theorem in Cone Metric Type Spaces

arxiv: v1 [cs.db] 13 Sep 2017

Query Evaluation Overview. Query Optimization: Chap. 15. Evaluation Example. Cost Estimation. Query Blocks. Query Blocks

Measurement of the stereoscopic rangefinder beam angular velocity using the digital image processing method

Vertex Unfoldings of Orthogonal Polyhedra: Positive, Negative, and Inconclusive Results

Flow Demands Oriented Node Placement in Multi-Hop Wireless Networks

Dr.Hazeem Al-Khafaji Dept. of Computer Science, Thi-Qar University, College of Science, Iraq

Improved flooding of broadcast messages using extended multipoint relaying

MATH STUDENT BOOK. 12th Grade Unit 6

Recommendation Subgraphs for Web Discovery

Using Augmented Measurements to Improve the Convergence of ICP

Contents Contents...I List of Tables...VIII List of Figures...IX 1. Introduction Information Retrieval... 8

PERSISTENT NAMING FOR PARAMETRIC MODELS

NONLINEAR BACK PROJECTION FOR TOMOGRAPHIC IMAGE RECONSTRUCTION. Ken Sauer and Charles A. Bouman

Partial Character Decoding for Improved Regular Expression Matching in FPGAs

CleanUp: Improving Quadrilateral Finite Element Meshes

the data. Structured Principal Component Analysis (SPCA)

Video Data and Sonar Data: Real World Data Fusion Example

arxiv: v1 [cs.gr] 10 Apr 2015

A Dual-Hamiltonian-Path-Based Multicasting Strategy for Wormhole-Routed Star Graph Interconnection Networks

Optimization of Two-Stage Cylindrical Gear Reducer with Adaptive Boundary Constraints

Facility Location: Distributed Approximation

Capturing Large Intra-class Variations of Biometric Data by Template Co-updating

An Efficient and Scalable Approach to CNN Queries in a Road Network

What are Cycle-Stealing Systems Good For? A Detailed Performance Model Case Study

COST PERFORMANCE ASPECTS OF CCD FAST AUXILIARY MEMORY

\A CENTRAL FACILITIES LOCATION PROBLEM INVOLVING TRAVELING SALESMAN TOURS AND EXPECTED DISTANCES/ MASTER OF SCIENCE

Volume 3, Issue 9, September 2013 International Journal of Advanced Research in Computer Science and Software Engineering

Australian Journal of Basic and Applied Sciences. A new Divide and Shuffle Based algorithm of Encryption for Text Message

1. Introduction. 2. The Probable Stope Algorithm

TOWARD HYBRID VARIANT/GENERATIVE PROCESS PLANNING

Multiple-Criteria Decision Analysis: A Novel Rank Aggregation Method

Optimizing Correlated Path Queries in XML Languages. Technical Report CS November 2002

On Optimal Total Cost and Optimal Order Quantity for Fuzzy Inventory Model without Shortage

Exploring the Commonality in Feature Modeling Notations

INTERPOLATED AND WARPED 2-D DIGITAL WAVEGUIDE MESH ALGORITHMS

Smooth Trajectory Planning Along Bezier Curve for Mobile Robots with Velocity Constraints

Cross-layer Resource Allocation on Broadband Power Line Based on Novel QoS-priority Scheduling Function in MAC Layer

2017 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media,

Intra- and Inter-Stream Synchronisation for Stored Multimedia Streams

Transcription:

Gray Codes for Refletable Languages Yue Li Joe Sawada Marh 8, 2008 Abstrat We lassify a type of language alled a refletable language. We then develop a generi algorithm that an be used to list all strings of length n for any refletable language in Gray ode order. The algorithm generalizes Gray ode algorithms developed independently for k-ary strings, restrited growth strings, and k-ary trees, as eah of these objets an be represented by a refletable language. Finally, we apply the algorithm to open meanderi systems whih an also be represented by a refletable language. Introdution The term Gray ode originally referred to a speifi ordering of length n binary strings, patented by Frank Gray [4], where onseutive bitstrings differ by a single bit. The following is an example of this listing for n = 3 where the bit that differs with the previous element is underlined: 000, 00, 0, 00, 0,, 0, 00. Today, the term Gray ode refers more generally to an exhaustive listing of any ombinatorial objet where eah suessive objet differs by some onstant amount. In 997, Savage [9] surveyed many of these Gray ode algorithms and sine then many more have been developed for various ombinatorial objets. For a signifiant number of these algorithms, a ommon strategy of refleting subtrees is applied - a tehnique that is similar in spirit to the original binary refleted Gray ode [4]. To illustrate this notion of refleting subtrees we onsider the set S 3 of all length 3 strings over the alphabet {a, b, } with no bb substring. A straight forward reursive algorithm an be used to generate suh strings in lexiographi order by following a omputation tree like the one in Figure. In the omputation tree, eah leaf represents a unique string that is Computing and Information Siene, University of Guelph, Canada. email: yli04@uoguelph.a Computing and Information Siene, University of Guelph, Canada. Researh supported by NSERC. email: jsawada@uoguelph.a

a b a b a a b a b a a b a b a b a b a a b Figure : Computation tree to generate S 3 in lexiographi order. a b a b a a b a b a a b b a a b b a a b a Figure 2: Computation tree to generate S 3 in Gray ode order. obtained by traing the path from the root to the leaf. Observe that the resulting listing is not a Gray ode sine in some ases suessive strings may differ in all positions. However, by refleting (reversing) the order of the hildren at partiular nodes, as illustrated in Figure 2, we an obtain an ordering of S 3 that is a Gray ode. Some objets for whih this strategy has been applied to inlude: binary [4] and k-ary strings [5, 3], restrited growth funtions [3, 7] and tails [8], and binary [] and k-ary trees [2, 4]. In this paper we generalize what various representations for these objets have in ommon by introduing the notion of refletable languages. We then provide a generi algorithm that an generate all length n words for any refletable language in Gray ode order. As a new appliation, we apply the algorithm to open meandri systems. 2

2 Refletable Languages Definition 2.. A language L over the alphabet Σ is said to be refletable if for every i > there exists two haraters x i and y i in Σ suh that if w w 2 w i is a prefix of a word in L then both w w 2 w i x i and w w i y i are also prefixes of words in L. Reall the language S 3 defined in the previous setion as the set of all length 3 strings over {a, b, } with no bb substring. It is refletable by onsidering x i = a and y i =. As another example, onsider the language L = {a, aa, a, aaa, aab, aa, aa, ab, ad} over Σ = {a, b,, d}. Observe that this language is also refletable by onsidering x 2 = a, y 2 = and x 3 = a, y 3 = b. On the other hand, the language L = {a, aa, a, aaa, aab, aa, ab, aa, ab} is not refletable sine ab L, but no matter what we use for x 3 and y 3 the strings abx 3 and aby 3 an not both be in L. It turns out that many ommon ombinatorial objets an be represented by refletable languages. In the following subsetions we give examples of suh refletable languages by demonstrating their x i and y i values. 2. Binary strings, k-ary strings, and variants Letting Σ = {0,, 2,..., k }, the set of all k-ary strings for k 2 trivially form a refletable language by onsidering x i = 0 and y i =. A generalization of k-ary strings is to onsider elements of the produt spae S = S S 2 S n where eah S i = {0,,..., r i } for i =, 2,..., n. If eah r i 2, then suh a spae will again orrespond to a refletable language by onsidering x i = 0 and y i =. Strings with a forbidden substring α are a variation on k-ary strings that have been studied in [0]. If the forbidden substring α is omposed from a subset of k 2 haraters in the alphabet, then the language of strings with forbidden substring α is refletable. This follows from the definition by assigning any two haraters from the alphabet that do not appear in α to x i and y i respetively. As an example, reall that S 3 orresponds to a refletable language. 2.2 Restrited growth strings Restrited growth strings are strings of non-negative integers w w n satisfying w = 0 and w i + max{w, w 2,..., w i }. There is a well known bijetion between restrited growth strings and set partitions [9]. By letting x i = 0 and y i = for eah i, observe that restrited growth strings of length n are refletable. A slight generalization of restrited growth strings are restrited growth tails [8], whih are strings of non-negative integers w w n satisfying w k and w i + max{w, w 2,..., w i, k }. Observe that this generalization also orresponds to a refletable language by letting x i = 0 and y i =. 3

0 4 2 0 2 4 2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 8 2 6 0 2 4 2 0 2 4 (a) (b) () Figure 3: (a) Zaks representation n = 6, k = 3. (b) Right distane sequene n = 6, k = 3. () Weight sequene for a binary tree with n = 6. 2.3 Binary and k-ary trees A k-ary tree is a tree where eah internal node has k ordered subtrees. A ommon bitsequene representation for k-ary trees is obtained by visiting a tree in pre-order where a is assigned to eah internal node and a 0 is assigned to eah leaf. This representation is often attributed to Zaks [5]. Using this pre-order traversal, a unique bit-sequene of length kn+ is obtained for eah k-ary tree with n internal nodes. Sine there are so many zeros in the bit sequene representation, it is often useful to use an alternate representation where only the positions of the ones are reorded. For example, a tree and its bit sequene representation is given in Figure 3(a). Using this representation a sequene a a 2 a n will orrespond to a k-ary tree if a = and for eah i > 0 we have a i < a i k(i ) + [2]. Observe that suh a set suh strings orresponds to a refletable language where x i = k(i ) and y i = k(i ) +. Another representation is presented in [4] where the nodes in a k-ary tree are defined reursively as follows: the root node is assigned 0, then for eah hild i =,..., k from left to right we assign the value k i plus the value of its parent. A pre-order traversal yields what is alled the right-distane sequene for a k-ary tree. An example is illustrated in Figure 3(b). Using this representation, any sequene orresponding to a tree with n nodes an be extended to a tree with n + nodes by appending any value between 0 and k [4]. Thus, the set of all right distane sequenes is a refletable language where x i = 0 and y i =. In the speial ase of binary trees (k = 2), we an assign a weight to eah vertex orresponding to the number of leaves in its left subtree. The sequene that results by reording these weights via an in-order traversal is the weight sequene introdued by Pallo [6]. An example is illustrated in Figure 3(). Pallo also shows a sequene w w 2... w n will orrespond uniquely to the weight sequene for a binary tree with n nodes if for eah i we have w i i, and for eah i w i + j i we have i w i j w j. Notie that this set of weight sequenes orresponds to a refletable language where x i = and y i = i. 4

proedure GrayCode (t) if (t > n) then Proess(w) else r := w t //w t will be either x t or y t GrayCode(t+) for eah z Σ {x t, y t } suh that w w t z is a prefix of some word in L n w t := z GrayCode(t+) end if (r = x t ) then w t := y t else w t := x t GrayCode(t+) Figure 4: Algorithm, GrayCode(t), to list all words of length n from a refletable language L in Gray ode order. 2.4 Open meandri systems We demonstrate that open meandri systems an be represented by a refletable language in Setion 4. 3 A Simple Gray Code Algorithm In this setion, we present a simple reursive algorithm to list L n (words of length n for some refletable language L) in Gray ode order. This algorithm generalizes independently developed algorithms for: binary strings [4], k-ary strings and ross produts [5, 3], restrited growth strings [3, 7], restrited growth tails [8], and binary [] and k-ary trees [2, 4]. These individual algorithms are still of interest, however, sine they often inlude extra effiieny onsiderations that are speifi to eah objet. For instane, adding data strutures to make the algorithm run in onstant amortized time or demonstrating a loop-free implementation. The basi idea behind the generi reursive algorithm is to apply the simple idea of refleting partiular subtrees that was disussed earlier. To do this, we use the speial haraters x i and y i as the first and last hildren of eah node at level i. The order of the other haraters (hildren) does not matter. This way, at the start of eah reursive all we an be sure that that the previous word generated had either the harater x i or y i at position i. Pseudoode is shown in Figure 4. The word being generated is stored in w = w w 2 w n. The urrent position is given by the parameter t and the variables x i and y i are speifi to the refletable language under onsideration as desribed in Definition 2.. To run the algorithm w 2 w n is initialized to x 2 x 3 x n, then for eah z Σ that starts a word in L n we assign w := z and all GrayCode(2). 5

To illustrate the algorithm, again reall the language S 3 whih onsists of all length 3 strings over the alphabet {a, b, } with no bb substring. By applying x i = a and y i =, the omputation tree that results from applying algorithm GrayCode(t) is given in Figure 2. Theorem 3.. For any refletable language L and given integer n, the algorithm GrayCode(t) will produe a list of all words L n in Gray ode order. Proof: First, it should be lear that every word in L n is generated exatly one by the algorithm. Thus, we need only show that suessive words in the resulting listing differ in exatly one position. Consider any two suh suessive words α = a a n and β = b b n. Suppose that their first ommon anestor in the omputation tree is at level i. Then a a i = b b i and a i+ b i+. Now sine the first reursive all in GrayCode(t) does not hange the value for urrent position t and sine the last reursive all never leads to a dead end, we must have a i+2 a n = b i+2 b n. Thus, every pair of suessive words generated will differ in exatly one position, i.e., the listing is a Gray ode. 3. Analyzing the generi Gray ode algorithm To analyze the generi Gray ode algorithm GrayCode(t), we perform an amortized analysis omparing the running time to the number of objets generated. For this analysis, the best we an hope for is an algorithm that runs in onstant amortized time. One assumption made in this analysis is that the time taken by the funtion Proess(w) is onstant, sine for many appliations this may be the ase. Now, fousing on the algorithm itself, observe that every non-leaf node in the omputation tree has at least two hildren sine reursive alls must be made for both x t and y t. Also, observe from the prefix test in the for loop that there will be no dead-ends, whih means that every leaf will be at level n of the omputation tree and will orrespond to a word in L n. Thus, if the time taken at eah internal node of omputation is proportional to the number of hildren (reursive alls made), then the overall running time will be proportional to the number of nodes in the omputation tree. Sine the branhing fator of eah internal node is at least 2, the number of leaves (words generated) will be greater than the number of internal nodes in whih ase the algorithm will run in onstant amortized time. Theorem 3.2. The algorithm GrayCode(t) runs in onstant amortized time if the following two onditions hold:. heking whether or not w w t z is a prefix of some word in L n takes O() time and 2. eah internal node in the omputation tree has Ω( Σ ) hildren. In several of the examples of refletable languages seen so for, the alphabet symbols that are possible at ertain positions in eah word may vary. Thus, in an analysis it may be more appropriate to onsider an alphabet Σ i for eah level i n of the omputation tree. The size of these alphabets ould then be applied to Theorem 3.2 rather than the more general alphabet Σ. 6

o d u d u o d u u (a) (b) Figure 5: (a) An open meander of order 6. (b) An open meandri system of order 6 with 3 urves. 4 A New Appliation: Open Meandri Systems An open meander an be thought of as an infinite meandering river whih passes beneath a series of bridges of an infinite straight road going from west to east. For example, Figure 5(a) illustrates an open meander with 6 bridges. Using a urve to represent the river and a line to represent the road, we an generalize the notion of an open meander by allowing multiple non-interseting urves to ross the line. Suh a onfiguration is alled an open meandri system (OMS). The order of an OMS is defined to be the number of times the urves ross the line. An example of an open meandri system of order 6 with 3 urves is shown in Figure 5(b). Enumeration sequenes for open meandri systems were studied by Baher [] and a fast algorithm for generating open meandri systems appears in [2]. The latter paper uses the alphabet Σ = {u,d,o,} to represent the four different types of rossings: u=up, d=down, o=open, =lose. Using this representation, eah OMS of order n an be represented uniquely by a word of length n over Σ as illustrated in Figure 5. Observe that any OMS of order n an always be extended into an OMS of order n + by appending either an o, d, or u. Only when adding a to an existing OMS is it possible that that a previously open urve an beome losed [2]. Thus, the language of all OMSs is refletable by setting x i =d and y i =u. The algorithm in [2] to generate all OMSs runs in onstant amortized time due to the introdution of data strutures that an test when it is possible to append a to an existing OMS in onstant time. Therefore, it is possible to diretly apply our generi Gray ode algorithm to onvert their lexiographi algorithm into a Gray ode algorithm. By applying the same data strutures the resulting Gray ode algorithm will ahieve the same asymptoti running time as the original algorithm. The result also follows from Theorem 3.2. Corollary 4.. A Gray ode for open meandri systems of order n an be generated in onstant amortized time. As an illustration of the resulting Gray ode algorithm, we show a partial omputation tree for n = 4 in Figure 6. The dead ends are shown by the dotted edges. For example, the words o, uo and oud are all invalid OMSs beause they inlude a losed urve. 7

d o u d o u u o d d o u u o d do uuoddo u uod do u uod do u uoddo uuod do uuoddo uuod do u do u uod do u uod do u Figure 6: The partial tree for OMS of order 4 that results from applying the generi Gray ode algorithm with x i =d and y i =u. Referenes [] R. Baher. Meander algebras. Prepubliation de l Institut Fourier, 478, 999. [2] B. Bobier and J. Sawada. A fast algorithm to generate open meandri systems. Manusript https://www.is.uoguelph.a/pubs/meander.pdf, 2007. [3] G. Ehrlih. Loopless algoirthms for generating permutations, ombinations, and other ombinatorial onfigurations. Journal of the ACM, 20:500 53, 973. [4] F. Gray. Pulse ode ommuniation. U.S. Patent, 2632058, 953. [5] G. Manku and J. Sawada. A loopless Gray ode for minimal signed-binary representations. In Pro. 3th Annual European Symposium on Algorithms (ESA 2005) LNCS, pages 438 447, Ot 2005. [6] J. M. Pallo. Enumerating, ranking and unranking binary trees. The Computer Journal, 29(2):7 75, 986. [7] F. Ruskey. Combinatorial Generation. Manusript, 200. [8] F. Ruskey and C. Savage. Gray odes for set partitions and restrited growth tails. Australasian Journal of Combinatoris, 0:85 96, 994. [9] C. Savage. A survey of ombinatorial Gray odes. SIAM Review, 39(4):605 629, 997. [0] M. Squire. Gray odes for a-free strings. Eletroni Journal of Combinatoris, 3(), 996. [] V. Vajnovszki. On the loopless generation of binary tree sequenes. Information Proessing Letters, 68:3 7, 998. 8

[2] D. Roelants van Baronaigien. A loopless Gray-ode algorithm for listing k-ary trees. Journal of Algorithms, 35:00 07, 2000. [3] S. Williamson. Combinatorial for Computer Siene. Computer Siene Press, 985. [4] R. Wu, J. Chang, and Y. Wang. Ranking, unranking and loopless Gray-odes generation of t-ary trees. Manusript, 2007. [5] S. Zaks. Generation and ranking or k-ary trees. Information Proessing Letters, 4():44 48, 982. 9