A Dynamic Programming Approach for Generating N-ary Reflected Gray Code List



Similar documents
RN-Codings: New Insights and Some Applications

RN-coding of Numbers: New Insights and Some Applications

New binary representation in Genetic Algorithms for solving TSP by mapping permutations to a list of ordered numbers

Two classes of ternary codes and their weight distributions

Implementation of Modified Booth Algorithm (Radix 4) and its Comparison with Booth Algorithm (Radix-2)

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

Functional-Repair-by-Transfer Regenerating Codes

Implementation of Full -Parallelism AES Encryption and Decryption

CSI 333 Lecture 1 Number Systems

Efficient Recovery of Secrets

Lossless Grey-scale Image Compression using Source Symbols Reduction and Huffman Coding

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Resource Allocation Schemes for Gang Scheduling

AN ALGORITHM FOR DETERMINING WHETHER A GIVEN BINARY MATROID IS GRAPHIC

System Interconnect Architectures. Goals and Analysis. Network Properties and Routing. Terminology - 2. Terminology - 1

Row Echelon Form and Reduced Row Echelon Form

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

Memory Allocation Technique for Segregated Free List Based on Genetic Algorithm

IMPROVING PERFORMANCE OF RANDOMIZED SIGNATURE SORT USING HASHING AND BITWISE OPERATORS

Solution of Linear Systems

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Mathematical Induction

An Adaptive Decoding Algorithm of LDPC Codes over the Binary Erasure Channel. Gou HOSOYA, Hideki YAGI, Toshiyasu MATSUSHIMA, and Shigeichi HIRASAWA

THE DESIGN OF AN EFFICIENT LOAD BALANCING ALGORITHM EMPLOYING BLOCK DESIGN. Ilyong Chung and Yongeun Bae. 1. Introduction

HY345 Operating Systems

is in plane V. However, it may be more convenient to introduce a plane coordinate system in V.

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

A NEW APPROACH TO ENHANCE SECURITY IN MPLS NETWORK

Fault-Tolerant Routing Algorithm for BSN-Hypercube Using Unsafety Vectors

Developing and Investigation of a New Technique Combining Message Authentication and Encryption

Optimal Scheduling for Dependent Details Processing Using MS Excel Solver

Codes for Network Switches

DATA ANALYSIS II. Matrix Algorithms

Chapter 4 Register Transfer and Microoperations. Section 4.1 Register Transfer Language

Elements of Abstract Group Theory

How To Encrypt Data With A Power Of N On A K Disk

Computability Theory

Reduced echelon form: Add the following conditions to conditions 1, 2, and 3 above:

Notes on Cholesky Factorization

Warshall s Algorithm: Transitive Closure

How To Fix Out Of Focus And Blur Images With A Dynamic Template Matching Algorithm

Notes on Factoring. MA 206 Kurt Bryan

Mathematics of Computation, Vol. 41, No (Jul., 1983), pp

Chapter 3. if 2 a i then location: = i. Page 40

A Systolic Algorithm to Process Compressed Binary Images

5. Binary objects labeling

The enhancement of the operating speed of the algorithm of adaptive compression of binary bitmap images

Memory Systems. Static Random Access Memory (SRAM) Cell

Adaptive Linear Programming Decoding

Topological Properties

A HIGH PERFORMANCE SOFTWARE IMPLEMENTATION OF MPEG AUDIO ENCODER. Figure 1. Basic structure of an encoder.

FPGA Implementation of an Extended Binary GCD Algorithm for Systolic Reduction of Rational Numbers

Data Storage 3.1. Foundations of Computer Science Cengage Learning

DATA STRUCTURES USING C

Physical-Layer Security: Combining Error Control Coding and Cryptography

Finding Frequent Patterns Based On Quantitative Binary Attributes Using FP-Growth Algorithm

College of information technology Department of software

A simple algorithm with no simple verication

A NEW HASH ALGORITHM: Khichidi-1

Frsq: A Binary Image Coding Method

Wald s Identity. by Jeffery Hein. Dartmouth College, Math 100

A COMPARATIVE STUDY OF SECURE SEARCH PROTOCOLS IN PAY- AS-YOU-GO CLOUDS

Signature Sequences in Weave Design

FUZZY CLUSTERING ANALYSIS OF DATA MINING: APPLICATION TO AN ACCIDENT MINING SYSTEM

Flip-Flops, Registers, Counters, and a Simple Processor

JUST-IN-TIME SCHEDULING WITH PERIODIC TIME SLOTS. Received December May 12, 2003; revised February 5, 2004

Management of Software Projects with GAs

PETRI NET BASED SUPERVISORY CONTROL OF FLEXIBLE BATCH PLANTS. G. Mušič and D. Matko

Chapter 15: Dynamic Programming

Topology-based network security

Regular Languages and Finite Automata

GameTime: A Toolkit for Timing Analysis of Software

Interconnection Network

Lecture 17 : Equivalence and Order Relations DRAFT

Computer Science. General Education Students must complete the requirements shown in the General Education Requirements section of this catalog.

HYBRID GENETIC ALGORITHMS FOR SCHEDULING ADVERTISEMENTS ON A WEB PAGE

ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science

Sub-class Error-Correcting Output Codes

Factoring Algorithms

GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE AND O(n) TIME J. Patera

Attack graph analysis using parallel algorithm

How To Improve Performance On A Single Chip Computer

ETEC 2301 Programmable Logic Devices. Chapter 10 Counters. Shawnee State University Department of Industrial and Engineering Technologies

ADVANCED APPLICATIONS OF ELECTRICAL ENGINEERING

Discrete Mathematics. Hans Cuypers. October 11, 2007

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

Weakly Secure Network Coding

A Genetic Algorithm Approach for Solving a Flexible Job Shop Scheduling Problem

Offline 1-Minesweeper is NP-complete

Efficient Software Implementation of AES on 32-bit Platforms

Transcription:

A Dynamic Programming Approach for Generating N-ary Reflected Gray Code List Mehmet Kurt 1, Can Atilgan 2, Murat Ersen Berberler 3 1 Izmir University, Department of Mathematics and Computer Science, Izmir 2, 3 Dokuz Eylul University, Department of Computer Science, Izmir Abstract In this work, some dynamic programming approaches are proposed to generate binary gray codes, which have various fields of application, as well as n-ary gray codes and anti-gray codes. Algorithms are described and programmed to carry out computational tests. Keywords : Binary gray code, N-ary gray code, anti-gray code, dynamic programming 1. Introduction The gray code is named after Frank Gray, who patented the use of them in shaft encoders in 1953 [1]. The gray code is a code with the property that there is only one bitchange between any 2 consecutive numbers. This unique property allows gray codes to be used for linear and rotary shaft position encoding, labeling the axes of Karnaugh maps, solving puzzle problems such as Tower of Hanoi, processing of mutations of genetic algorithms efficiently, detecting and correcting errors in digital data transmission [2]. Generating gray codes is a well-studied task and various solution approaches such as, recursive, straightforward, dynamic programming approaches are brought [3-8]. In some works, a generalization of the gray code is also studied. The generalized gray code is known as n-ary gray code, in which numbers are represented in any base n [9, 10]. The rest of the paper is organized as follows. A dynamic programming approach for generating binary reflected gray codes is given in section 2. The approach is then expanded to produce n-ary reflected gray codes in section 3, and producing anti-gray codes (i.e. total number of bit-changes is maximum) using previously generated binary gray codes is discussed in section 4. Finally, section 5 concludes the paper. 2. Binary Reflected Gray Code Algorithm Consider a set A that has n elements. There are 2 n subsets of set A and they can be mapped using integer indices, where 0 is the empty set and 2 n -1 is the entire set A. Binary representations of these indices can be consecutively generated by toggling the rightmost bit at every step, second-rightmost bit at every second step and likewise the leftmost bit, i.e. nth bit at (2 n-1 )th step. By the nature of dynamic programming, a matrix consisting of n2 n elements is generated. The first row of the matrix is a zero vector. For each index value, corresponding row in the matrix is incrementally updated using the loop below. Note that each row will hold the binary representation of its index.

for i 1 to 2 n do for j 1 to n do if (i mod 2 j = 0) b[j] (b[j] XOR 1); Same approach is used to generate binary reflected gray code. As shown in Fig.1., jth column of gray code binary string of length n is actually stored in the vertical block starting with 2 j+1 th index of (j+1)th column of (n+1)-length ordinary binary code. Exploiting this pattern, the following loop is used to generate gray code with a dynamic programming sense. for i 1 to 2 n do for j 1 to n do if (i mod 2 j+1 = 2 j ) g[j] (g[j] XOR 1); Fig. 1.

Algorithm is programmed in C language and computational tests are done for some n values. Results are seen in Table 1. Column Full involves CPU times for the tests where the entire set with 2 n indices is generated straightforward, and column Half involves the CPU times for the tests where the subset with the first 2 n-1 indices (that is, the half of the set) is generated and the rest is completed by taking advantage of symmetry in reflected gray code. Table 1. CPU Time (sec) n Full Half 15 0,000 0,000 16 0,000 0,000 17 0,031 0,025 18 0,046 0,031 19 0,109 0,046 20 0,223 0,109 21 0,436 0,218 22 0,993 0,468 23 2,001 1,007 24 4,077 2,100 25 8,421 4,245 26 17,343 8,759 27 35,990 18,081 28 74,403 37,206 29 163,608 77,157 3. N-ary Reflected Gray Code Algorithm In this chapter, symmetry property is exploited for proposing a new approach. This generalized approach will allow to generate reflected gray codes in any radix and length. The rightmost bit is the most significant but in a symmetric gray code, since the entire structure can be constructed starting from this bit. The rightmost bit repeats symmetric sequences such as (0, 1, 1, 0) in binary, (0, 1, 2, 2, 1, 0) in ternary, (0, 1, 2, 3, 3, 2, 1, 0) in quaternary, etc. Using this observation, an array with 2m elements, where m is the number base, is defined and filled in with symmetric sequences of the rightmost bit. In order to use at the later steps of the algorithm, an array representing the indices is created and filled with zeros. In the following, the loop for filling the arrays is given. for j 0 to m-1 do k[j] 0; g[j] j; g[2*m-1-j] j; Given a radix and a length, notated with m and n respectively, the loop below will generate the desired n-ary reflected gray code.

for i 0 to m n do for j 0 to n-1 do if ((i>0) AND (i mod m j = 0)) k[j] (k[j]+1) mod (2*m); print(g[k[j]]); Results of the computational tests for 3-ary and 4-ary reflected gray codes are shown in Table 2. Table 2. CPU Time (sec) n 3-ary 4-ary 10 0,000 0,093 11 0,015 0,453 12 0,062 1,953 13 0,203 8,500 14 0,656 36,421 15 2,093 158,265 16 6,703 679,859 4. Anti-Gray Code Another interesting task is generating a binary list whose consecutive lines have the maximum number of bit-changes. Such a list is called an anti-gray code. Binary gray code can easily be used to generate anti-gray code. Evidently, the maximum number of bit-changes between 2 consecutive lines is the given length n. An obvious example is a line and it s complement. For an n-length anti-gray code, there can be 2 n /2 = 2 n-1 pairs of lines, which are complements of each other. It is illustrated below, in Fig. 2. Fig. 2. A previously generated binary gray code list can be used to sort these 2 n-1 pairs and obtain an anti-gray code. Since only 1 bit is toggled between 2 consecutive lines of a gray code, there are n-1 different bits between the complement of the first line and the second line itself. Hence, there can be 2 n-1-1 consecutive lines yielding (n-1) bit-changes. In total, there

will be n2 n-1 + (n - 1) (2 n-1-1) bit-changes, which is the maximum possible number of changes (See Table 3). Table 3. 5. Conclusion The dynamic programming approaches in this paper are easy to implement. If the entire gray code list is not obligatory to be present at a time, a small memory space to hold merely two lines will be sufficient. Contrarily, if memory is not an issue, the gray code list can be swiftly generated without the overhead. The algorithms presented in the paper are programmed and uploaded to http://kisi.deu.edu.tr/murat.berberler/gray/. References [1] F. Gray, Pulse code communication, U.S. Patent 2 632 058, Mar. 17, 1953. [2] A. Ahmad, F. Bait-Shiginah, A Nonconventional Approach To Generating Efficient Binary Gray Code Sequences, IEEE Potentials, vol. 31, issue 3, pp. 16-19, 2012. [3] J. Boothroyd, Algorithm 246, Gray code, Comm. ACM 7, 12, pp. 701, 1964. [4] J. Misra, Remark on Algorithm 246, ACM Trans. Math. Software 1, 3, pp. 285, 1975. [5] E.N. Gilbert, Gray codes and paths on the n-cube. Bell Syst. Tech. J. 37, 9, pp. 815-826, 1958. [6] G. Ehrlich, Algorithm 466, Four combinatorial algorithms, Comm. ACM16, 1, pp. 690-691, 1973. [7] J.W. Lenstra, A. H. G. Rinnooy Kan, A recursive approach to the generation of combinatorial configurations, Rep. BW 50/75, Mathematisch Centrum, Amsterdam, 1975. [8] A. T. Phillips, M. R. Wick, A Dynamic Programming Approach to Generating a Binary Reflected Gray Code Sequence, Proc. 38th Annual Midwest Instruction and Computing Symposium, Eau Claire, WI, 2005. [9] M.C. Er, On generating the N-ary reflected gray codes, IEEE Transactions on Computers, vol. 33, 8, pp. 739-741, 1984. [10] I. Stojmenovic, Generating n-ary reflected gray codes on a linear array of processors, Parallel Processing Letters, vol. 6, 1, pp. 27-34, 1996.