Enumerative Combinatoric Algorithms. Gray code

Similar documents
An Efficient Implementation of Tower of Hanoi using Gray Codes

PUZZLES ON GRAPHS: THE TOWERS OF HANOI, THE SPIN-OUT PUZZLE, AND THE COMBINATION PUZZLE

Let start by revisiting the standard (recursive) version of the Hanoi towers problem. Figure 1: Initial position of the Hanoi towers.

Games of Skill ANSWERS Lesson 1 of 9, work in pairs

LAMC Junior Circle January 22, Oleg Gleizer. The Hanoi Tower. Part 2

Mathematics Competition Practice Session 6. Hagerstown Community College: STEM Club November 20, :00 pm - 1:00 pm STC-170

Games of Skill Lesson 1 of 9, work in pairs

CS 32 Puzzles, Games & Algorithms Fall 2013

Balanced Trees. Balanced Trees Tree. 2-3 Tree. 2 Node. Binary search trees are not guaranteed to be balanced given random inserts and deletes

A NEW PUZZLE FOR ITERATED COMPLETE GRAPHS OF ANY DIMENSION

MA/CSSE 473 Day 14. Permutations wrap-up. Subset generation. (Horner s method) Permutations wrap up Generating subsets of a set

Geometric Functions. The color channel toolbar buttons are disabled.

Directed Towers of Hanoi

Games, Triangulations, Theory

20 Memory Drawers. Copyright 2002 IPP Design Competition All rights reserved. Puzzle Solution:

Graphs of Tilings. Patrick Callahan, University of California Office of the President, Oakland, CA

Computer Graphics (CS/ECE 545) Lecture 7: Morphology (Part 2) & Regions in Binary Images (Part 1)

Gray code and loopless algorithm for the reflection group D n

ECS 20 (Spring 2013) Phillip Rogaway Lecture 1

Embedded Systems and Software. Rotary Pulse Generators

Lesson Plan for Teachers

What is an ENCODER. An electronic component that generates an ON and OFF output signal periodically.

Organizing Gray Code States for Maximum Error Tolerance

Contemplation of Synchronous Gray Code Counter and its Variants using Reversible Logic Gates

6.111 Lecture # 19. Controlling Position. Some General Features of Servos: Servomechanisms are of this form:

Two Flipping Puzzles...

arxiv: v1 [cs.cc] 21 Jun 2017

Evacuation and a Geometric Construction for Fibonacci Tableaux

Encoding and Code Wheel Proposal for TCUT1800X01

Compressing Pattern Databases

Quarter Turn Baxter Permutations

On Variable Dependencies and Compressed Pattern Databases

Game, Set, and Match Carl W. Lee September 2016

Building a Heuristic for Greedy Search

Lecture 02: Digital Logic Review

More Great Ideas in Theoretical Computer Science. Lecture 1: Sorting Pancakes

CSE 21 Practice Final Exam Winter 2016

Stack permutations and an order relation for binary trees

NuSMV: Planning as Model Checking

The Apprentices Tower of Hanoi

Rotary Pulse Generators and other Lab 3 Considerations

Puzzling Math, Part 2: The Tower of Hanoi & the End of the World!

Extended Introduction to Computer Science CS1001.py

Topic 23 Red Black Trees

wood (koa, maple, ebony, cocobolo, new guinea rosewood) and metal (brass, copper, steel) Secret Opening Box

Module 3 Greedy Strategy

Magnetic Towers of Hanoi and their Optimal Solutions

NOVOTURN Multiturn Sensor non-contacting. Series RSM-2800

Game, Set, and Match Carl W. Lee September 2016

COMP 2804 solutions Assignment 4

((( ))) CS 19: Discrete Mathematics. Please feel free to ask questions! Getting into the mood. Pancakes With A Problem!

Numan Sheikh FC College Lahore

Solving the Rubik s Cube

SEVENTH EDITION and EXPANDED SEVENTH EDITION

CS256 Applied Theory of Computation

Midterm Examination. CSCI 561: Artificial Intelligence

Week 1. 1 What Is Combinatorics?

KAERI Feeder Tube Inspection Using EMAT Generated Circumferential Guided Waves

Odd king tours on even chessboards

Analyzing ELLIE - the Story of a Combinatorial Game

Othello/Reversi using Game Theory techniques Parth Parekh Urjit Singh Bhatia Kushal Sukthankar

Lecture 19 November 6, 2014

repeated multiplication of a number, for example, 3 5. square roots and cube roots of numbers

Digital Communication Systems ECS 452

Heuristic Search with Pre-Computed Databases

5.1 State-Space Search Problems

Perimeter and Area: The Mysterious Connection Assessment

A Note on Downup Permutations and Increasing Trees DAVID CALLAN. Department of Statistics. Medical Science Center University Ave


Game Playing Part 1 Minimax Search

18 Two-Dimensional Shapes

An Approach to Korean License Plate Recognition Based on Vertical Edge Matching

6. FUNDAMENTALS OF CHANNEL CODER

UMBC 671 Midterm Exam 19 October 2009

Features & Benefits 360, 512, 720, 1000, 1024, 1440, 1800, 2000, 2048, 2880, 3000, 3600, 4000, 4096, 5000, 5120, 6000, 7200, 8000, 8192, 9000, 10000

Rotary Measuring Technology

From Tetris to polyominoes generation. June 3rd, 2016 GASCOM 2016 La Marana, Bastia, France.

Comparative analysis of speed decoding algorithms for rotary incremental encoders

Finding and Characterizing Knights Tours on the Chessboard

Equivalence Classes of Permutations Modulo Replacements Between 123 and Two-Integer Patterns

LEARNING ABOUT MATH FOR K TO 5. Dorset Public School. April 6, :30 pm 8:00 pm. presented by Kathy Kubota-Zarivnij

Absolute Encoders Multiturn

Coin-Moving Puzzles. arxiv:cs/ v1 [cs.dm] 31 Mar Introduction. Erik D. Demaine Martin L. Demaine Helena A. Verrill

2 Building Blocks. There is often the need to compare two binary values.

Unit 12: Artificial Intelligence CS 101, Fall 2018

Lecture5: Lossless Compression Techniques

Outline. In One Slide. LR Parsing. LR Parsing. No Stopping The Parsing! Bottom-Up Parsing. LR(1) Parsing Tables #2

EECS 473 Final Exam. Fall 2017 NOTES: I have neither given nor received aid on this exam nor observed anyone else doing so. Name: unique name:

Greedy Flipping of Pancakes and Burnt Pancakes

NOVOHALL Rotary Sensor non-contacting. Series RSC2800 digital SSI, SPI, Incremental

Absolute Encoders - Singleturn

PRIMES STEP Plays Games

Detecting and Correcting Bit Errors. COS 463: Wireless Networks Lecture 8 Kyle Jamieson

Olympiad Combinatorics. Pranav A. Sriram

Technical data. General specifications. Measurement range min max. 360

Solving the 4 x 4 Cube

LOGIC DIAGRAM: HALF ADDER TRUTH TABLE: A B CARRY SUM. 2012/ODD/III/ECE/DE/LM Page No. 1

Technical data. General specifications. Linearity error ± 0.1 Functional safety related parameters MTTF d 700 a at 40 C Mission Time (T M ) L 10

Generating trees and pattern avoidance in alternating permutations

Circular Nim Games. S. Heubach 1 M. Dufour 2. May 7, 2010 Math Colloquium, Cal Poly San Luis Obispo

Transcription:

Enumerative Combinatoric Algorithms Gray code Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27

Standard binary code: Ex, 3 bits: b = b = b = 2 b = 3 b = 4 b = 5 b = 6 b = 7 Binary code Problem: In the transition from 3 to 4 every bit changes. Thus, if timing is not absolutely perfect (it never is) then any number from to 7 can be read. e.g.: position encoder, electronic circuits,... Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 2

Gray code a.k.a. reflected binary code (Frank Gray, 947) binary Gray code: successive values differ in only one bit generate a Gray code (G(n)) for n bits from G(n ): reflected binary code G(n)...... G(n ) G(n ) n=: n=2: n=3: Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 3-6 Observe that this way also the last and the first number differ only in one position.

Uses applications initially for analog to digital conversion for compatible color television signals also used in telegraphy and position encoders (linear and rotary) error correction in digital communications genetic algorithms solving puzzles (Towers of Hanoi, Chinese rings puzzle, Spin-out,...) Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 4

binary Gray code conversion b n b n 2... b b g n g n 2... g g b n = g n i < n b i = b i+ XOR g i g i = b i+ XOR b i X Y X XOR Y Ex: standard binary b? Ex: Gray code g? Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 5

Puzzle: Tower of Hanoi Given: A stack of n different sized disks, arranged from largest on the bottom to smallest on top, placed on a rod, A. Plus two more empty rods, B and C. Valid move: move one disk from one rod to another one but not placing a larger disk on top of a smaller disk. Task: Move the stack (tower) from rod A to rod B (using rod C) (... with minimum number of moves) Solution (recursive): to move a tower, T (n), of size n from A to B using C: move T (n ) from A to C using B, then the largest disk from A to B, and then move T (n ) from C to B using A. Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 6-2

Tower of Hanoi vs. Gray code label the disks from (smallest) to n (largest) g n g n 2... g g... a number in Gray code The changes in the Gray code (if bit i changes) define the disk (disk i) that has to be moved: disk always cw (or always ccw, depending on parity) disks i, < i < n, unique way to move Ex: n = 4 A start: all 4 disks on A goal: all 4 disks on B n is even move ccw Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 7-2 C B

Tower of Hanoi vs. Gray code A B C Ex: n = 4 A start: all 4 disks on A goal: all 4 disks on B n is even move ccw Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 7-3 C B

Tower of Hanoi vs. Gray code M. Gardner proved (957,59) that the Tower of Hanoi problem is isomorphic to finding a Hamiltonian path on an n-hypercube. n-hypercube has 2 n vertices a path visiting them all has 2 n edges at least 2 n moves Ex: n = 4 A start: all 4 disks on A goal: all 4 disks on B n is even move ccw Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 7-9 C B

Another puzzle: Spin-out very similar to Chinese Rings puzzle 7 spinners take one of two possible orientations:, initially all are ; the goal is that all are problem: only the rightmost spinner can rotate and any spinner which is the left neighbor of the rightmost Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 8 -

Another puzzle: Spin-out Solution: n spinners from left to right g n... g spinner i is g i = ; spinner i is g i = traverse the Gray code from... to... in reverse direction Ex: n = 4 done Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 8-6

Generate next Gray code number G[i] G[i + ] count the number # of s in G[i] if # is even then flip g of G[i] to get G[i + ] else flip the left neighbor (bit position) of the rightmost func nextgray(g):... g = g[n ]... g[] if (#(g) is even) then flip g[]; else r index of rightmost of g if (r < n ) then flip g[r+]; else flip g[r]; fi fi return (g)... next Gray number (G[] if input was G[2 n ]) Oswin Aichholzer (slides TH): Enumerative Combinatoric Algorithms, 27 9