Combinatorial algorithms

Similar documents
Use of patterns in n-tuple combinatorial generation

Practice Exam 1 CIS/CSE 607, Spring 2009

A new Euler-Mahonian constructive bijection

Generating Permutations and Combinations

T Combinatorial algorithms. Combinatorial structures. T Combinatorial algorithms

1 The Algebraic Normal Form

Gray Codes and Overlap Cycles for Restricted Weight Words

Week 4-5: Generating Permutations and Combinations

SYMMETRIC (66,26,10) DESIGNS HAVING F rob 55 AUTOMORPHISM GROUP AS AN. Dean Crnković and Sanja Rukavina Faculty of Philosophy in Rijeka, Croatia

Exploring the infinite : an introduction to proof and analysis / Jennifer Brooks. Boca Raton [etc.], cop Spis treści

Homework 7 Solutions, Math 55

Pollard s Rho Algorithm for Elliptic Curves

Introduction to Randomized Algorithms: Quick Sort and Quick Selection

CDM Combinatorial Principles

Divide-and-Conquer and Recurrence Relations: Notes on Chapter 2, Dasgupta et.al. Howard A. Blair

Some results on the existence of t-all-or-nothing transforms over arbitrary alphabets

De Bruijn Sequences for the Binary Strings with Maximum Density

Definition: Let S and T be sets. A binary relation on SxT is any subset of SxT. A binary relation on S is any subset of SxS.

BIJECTIVE PROOFS FOR FIBONACCI IDENTITIES RELATED TO ZECKENDORF S THEOREM

Constant Time Generation of Set Partitions

Mathematical Structures Combinations and Permutations

Randomized Sorting Algorithms Quick sort can be converted to a randomized algorithm by picking the pivot element randomly. In this case we can show th

arxiv: v1 [math.nt] 4 Mar 2014

Orthogonal arrays of strength three from regular 3-wise balanced designs

F = k Z +F k T = k Z +T k. ν(x) :=0 (x N) By the successor function one means the function σ in T 1 defined as follows: σ(x) :=x +1 (x N)

Efficient random number generation on FPGA-s

The constructible universe

Computing Isomorphism [Ch.7, Kreher & Stinson] [Ch.3, Kaski & Östergård]

Finding the Largest Fixed-Density Necklace and Lyndon word

Topics in Algorithms. 1 Generation of Basic Combinatorial Objects. Exercises. 1.1 Generation of Subsets. 1. Consider the sum:

Additional Constructions to Solve the Generalized Russian Cards Problem using Combinatorial Designs

Nonexistence of (9, 112, 4) and (10, 224, 5) binary orthogonal arrays

Lecture 5: Fusion Trees (ctd.) Johannes Fischer

CS1800 Discrete Structures Final Version A

Data selection. Lower complexity bound for sorting

Monotone Gray Codes and the Middle Levels Problem

Relations. Binary Relation. Let A and B be sets. A (binary) relation from A to B is a subset of A B. Notation. Let R A B be a relation from A to B.

Bijective proofs for Fibonacci identities related to Zeckendorf s Theorem

PARTITIONS OF FINITE VECTOR SPACES INTO SUBSPACES

A fast algorithm to generate necklaces with xed content

Hanoi Graphs and Some Classical Numbers

New Constructions for De Bruijn Tori

MODEL ANSWERS TO THE SEVENTH HOMEWORK. (b) We proved in homework six, question 2 (c) that. But we also proved homework six, question 2 (a) that

Generalized hyper-bent functions over GF(p)

R ij = 2. Using all of these facts together, you can solve problem number 9.

Iterations of sum of powers of digits

Sets of MOLSs generated from a single Latin square

Necklaces Pólya s Enumeration Theorem. Pólya Counting I. Gordon Royle. Semester 1, 2004

Alternative Combinatorial Gray Codes

Characterization of 2 n -Periodic Binary Sequences with Fixed 2-error or 3-error Linear Complexity

Tricks of the Trade in Combinatorics and Arithmetic

Number Theory. Modular Arithmetic

EXHAUSTIVELY generating a class of combinatorial objects

ON THE CONSTRUCTION OF ORTHOGONAL BALANCED INCOMPLETE BLOCK DESIGNS

SIMPLE ALGORITHM FOR SORTING THE FIBONACCI STRING ROTATIONS

Latin Squares and Orthogonal Arrays

arxiv: v1 [math.co] 25 Apr 2013

Ch6 Addition Proofs of Theorems on permutations.

Part V. Chapter 19. Congruence of integers

Outline. We will now investigate the structure of this important set.

Harvard CS 121 and CSCI E-207 Lecture 6: Regular Languages and Countability

COMBINATORIAL COUNTING

arxiv: v1 [math.co] 10 Sep 2010

Number Theory Basics Z = {..., 2, 1, 0, 1, 2,...} For, b Z, we say that divides b if z = b for some. Notation: b Fact: for all, b, c Z:

A conjecture on the alphabet size needed to produce all correlation classes of pairs of words

Subquadratic Space Complexity Multiplication over Binary Fields with Dickson Polynomial Representation

Coloring Vertices and Edges of a Path by Nonempty Subsets of a Set

Part IA Numbers and Sets

Chapter 4 Mathematics of Cryptography

Ranks of Hadamard Matrices and Equivalence of Sylvester Hadamard and Pseudo-Noise Matrices

AN EXPLICIT UNIVERSAL CYCLE FOR THE (n 1)-PERMUTATIONS OF AN n-set

Chapter 5: Integer Compositions and Partitions and Set Partitions

Golomb-Lempel Construction of Costas Arrays Revisited

Finite Mathematics. Nik Ruškuc and Colva M. Roney-Dougal

TESTING FOR A SEMILATTICE TERM

Chapter 5: Integer Compositions and Partitions and Set Partitions

Classical Cryptography

REPORT DOCUMENTATION PAGE

Fast Sorting and Selection. A Lower Bound for Worst Case

The Chinese Remainder Theorem

Permutations with Ascending and Descending Blocks

New quasi-symmetric designs constructed using mutually orthogonal Latin squares and Hadamard matrices

Constructing c-ary Perfect Factors

Generating Functions

Reverse mathematics and marriage problems with unique solutions

INEQUALITIES OF SYMMETRIC FUNCTIONS. 1. Introduction to Symmetric Functions [?] Definition 1.1. A symmetric function in n variables is a function, f,

A Universal Turing Machine

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Andrews Curtis Groups and the Andrews Curtis Conjecture

A Kruskal-Katona Type Theorem for the Linear Lattice

Roux-type Constructions for Covering Arrays of Strengths Three

Some recent results on all-or-nothing transforms, or All or nothing at all

Section 11.1 Sequences

MATH 215 Sets (S) Definition 1 A set is a collection of objects. The objects in a set X are called elements of X.

ICT12 8. Linear codes. The Gilbert-Varshamov lower bound and the MacWilliams identities SXD

Algorithms (II) Yu Yu. Shanghai Jiaotong University

Apollonian Circle Packings: Number Theory II. Spherical and Hyperbolic Packings

Efficient Enumeration of Regular Languages

5. Peano arithmetic and Gödel s incompleteness theorem

Higher Bruhat order on Weyl groups of Type B

Transcription:

Combinatorial algorithms computing subset rank and unrank, Gray codes, k-element subset rank and unrank, computing permutation rank and unrank Jiří Vyskočil, Radek Mařík 2012

Combinatorial Generation definition: Suppose that S is a finite set. A ranking function will be a bijection rank: S {0,, S 1} and unrank function is an inverse function to rank function. definition: Given a ranking function rank, defined on S, the successor function satisfies the following rule: potential uses: successor(s) = t rank(t) = rank(s) + 1 storing combinatorial objects in the computer instead of storing a combinatorial structure which could be quite complicated generation of random objects from S ensuring equal probability 1/ S 2 / 22

Subsets Suppose that n is a positive integer and S = {1,, n}. Define S to consist of the 2 n subsets of S. Given a subset T S, let us define the characteristic vector of T to be the one-dimensional binary array χ T = [x n 1, x n 2,, x 0 ] where x i = 1 if (n i) T 0 if (n i) T 3 / 22

Subsets Example of the lexicographic ordering on subsets of S = {1,2, 3}: T χ T = [x 2, x 1, x 0 ] rank(t) [0,0,0] 0 {3} 0,0,1 1 {2} [0,1,0] 2 {2,3} [0,1,1] 3 {1} [1,0,0] 4 {1,3} [1,0,1] 5 {1,2} [1,1,0] 6 {1,2,3} [1,1,1] 7 4 / 22

Subsets computing the subset rank over lexicographical ordering 1) Function SUBSETLEXRANK( size n; set T ) : rank 2) r = 0 ; 3) for i = 1 to n do { 4) if i T then r = r + 2 n-i ; 5) } 6) return r ; 1) Function SUBSETLEXUNRANK( size n; rank r ) : set 2) T = ; 3) for i = n downto 1 do { 4) if r mod 2 = 1 then T = T {i} ; 5) r = 6) } r 2 ; 7) return T ; 5 / 22

definition: Gray Code The reflected binary code, also known as Gray code, is a binary numeral system where two successive values differ in only one bit. G n will denote the reflected binary code for 2 n binary n-tuples, and it will be written as a list of 2 n vectors, as follows: G n =[G n 0, G n n 1,, G 2 n 1] The codes G n are defined recursively: example: G 1 =[0,1] G n =[0G n 1 0, 0G n 1 1,, 0G n 1 2 n 1,1G n 1 2 n 1,,1G n 1 1, 1G n 1 0 ] G 3 =[000, 001, 011, 010, 110, 111, 101, 100] 6 / 22

Gray Code Example: G3 r binary representation of r r 000 000 0 001 001 1 011 010 2 010 011 3 110 100 4 111 101 5 101 110 6 100 111 7 7 / 22

Gray Code lemma 1 Suppose 0 r 2 n 1 B = b n,, b 0 is a binary code of r G = g n,, g 0 is a Gray code of r Then for every j {0,1,, n 1} g j = b j + b j+1 mod 2 proof By induction on n. 8 / 22

Gray Code lemma 2 Suppose 0 r 2 n 1 B = b n,, b 0 is a binary code of r G = g n,, g 0 is a Gray code of r Then for every j {0,1,, n 1} b j = g j + b j+1 mod 2 proof g j = b j + b j+1 mod 2 g j b j + b j+1 (mod 2) b j g j + b j+1 mod 2 b j = g j + b j+1 mod 2 9 / 22

lemma 3 Gray Code Suppose 0 r 2 n 1 B = b n,, b 0 is a binary code of r G = g n,, g 0 is a Gray code of r Then for every j {0,1,, n 1} n 1 b j = g i i=j mod 2 proof n 1 g i i=j n 1 mod 2 = (b i +b i+1 ) i=j n 1 mod 2 = b j + b n + 2 b i i=j+1 mod 2 = (b j +b n ) mod 2 = b j By lemma 1. By the sum reordering. By the property of modulo. By the maximum range of r and the range of b j. 10 / 22

Gray Code converting to and from minimal change ordering (Gray code) 1) Function BINARYTOGRAY( binary code rank B ) : gray code rank 2) return B xor (B >> 1) ; 1) Function GRAYTOBINARY(gray code rank G ) : binary code rank 2) B = 0; 3) n = (number of bits in G) 1; 4) for i=0 to n do { 5) B = B << 1; 6) B = B or (1 and ( (B >> 1) xor (G >> n) ) ); 7) G = G << 1; 8) } 9) return B ; 11 / 22

Subsets Gray Code computing the subset rank over minimal change ordering 1) Function GRAYCODERANK( size n; set T ) : rank 2) r = 0 ; 3) b = 0 ; 4) for i = n 1 downto 0 do { 5) if n i T then b = 1 b ; 6) if b = 1 then r = r + 2 i ; 7) } 8) return r ; 12 / 22

Subsets Gray Code computing the subset unrank over minimal change ordering 1) Function GRAYCODEUNRANK( size n; rank r ) : set 2) T = ; 3) c = 0 ; 4) for i = n 1 downto 0 do { 5) b = r 2 i ; 6) if b c then T = T {n i} ; 7) c = b ; 8) r = r b 2 i ; 9) } 10) return T ; 13 / 22

k - Element subsets Suppose that n is a positive integer and S = {1,, n}. S k consists of all k-element subsets of S. A k-element subset T S can be represented in a natural way as a sorted one-dimensional array T = t 1, t 2,, t k where t 1 < t 2 < < t k. 14 / 22

k - Element subsets Example of the lexicographic ordering on k-element subsets: T T rank(t) {1,2,3} [1,2,3] 0 {1,2,4} 1,2,4 1 {1,2,5} [1,2,5] 2 {1,3,4} [1,3,4] 3 {1,3,5} [1,3,5] 4 {1,4,5} [1,4,5] 5 {2,3,4} [2,3,4] 6 {2,3,5} [2,3,5] 7 {2,4,5} [2,4,5] 8 {3,4,5} [3,4,5] 9 15 / 22

k - Element subsets computing the k-element subset successor with lexicographic ordering 1) Function KSUBSETLEXSUCCESOR(k-element subset as array T; 2) number n, k ) : k-element subset as array ; 3) U = T ; 4) i = k ; 5) while ( i 1 ) and ( T[i] = n k + i ) do i = i 1 ; 6) if ( i = 0 ) then 7) return undefined ; 8) else { 9) for j = i to k do U[j] = T[i] + 1 + j i ; 10) return U ; 11) } 16 / 22

k - Element subsets computing the k-element subset rank with lexicographic ordering 1) Function KSUBSETLEXRANK(k-element subset as array T; 2) number n, k ) : rank ; 3) r = 0 ; 4) T[0] = 0 ; 5) for i = 1 to k do { 6) if ( T[i-1]+1 T[i] 1 ) then { 7) for j = T[i-1]+1 to T[i] 1 do r = r + 8) } 9) } 10) return r ; n j k i ; 17 / 22

k - Element subsets computing the k-element subset unrank with lexicographic ordering 1) Function KSUBSETLEXUNRANK(rank r; 2) number n, k ) : k-element subset as array ; 3) x = 1 ; 4) for i = 1 to k do { n x 5) while ( r ) do { k i n x 6) r = r ; 7) x = x + 1 ; 8) } 9) T[i] = x ; 10) x = x + 1 ; 11) } 12) return T ; k i 18 / 22

Permutations A permutation is a bijection from a set to itself. one possible representation of a permutation π: 1,, n 1,, n is by storing its values in a one-dimensional array as follows: index 1 2 n value π[1] π[2] π[n] 19 / 22

Permutations computing the permutation rank over lexicographical ordering 1) Function PERMLEXRANK( size n; permutation π ) : rank 2) r = 0 ; 3) ρ = π ; 4) for j = 1 to n do { 5) r = r + (ρ[ j ] 1) (n j)! ; 6) for i = j +1 to n do if ρ[ i ] > ρ[ j ] then ρ[ i ] = ρ[ i ] 1 ; 7) } 8) return r ; 20 / 22

Permutations computing the permutation unrank over lexicographical ordering 1) Function PERMLEXUNRANK( size n; rank r ) : permutation 2) π[ n ] = 1 ; 3) for j = 1 to n 1 do { 4) d = r mod j+1! j! 5) r = r d j! ; 6) π[ n j ] = d + 1 ; ; 7) for i = n j + 1 to n do if π[ i ] > d then π[ i ] = π[ i ] + 1 ; 8) } 9) return π ; 21 / 22

References D.L. Kreher and D.R. Stinson, Combinatorial Algorithms: Generation, Enumeration and Search, CRC press LTC, Boca Raton, Florida, 1998. 22 / 22