MA/CSSE 473 Day 19 Sleepsort Finish Nim Josephus problem

Slides:



Advertisements
Similar presentations
Extensible Networking Platform CSE 240 – Logic and Discrete Mathematics Review: Mathematical Induction Use induction to prove that the sum of the.
Advertisements

Introduction to Combinatorial Game Acm Honored Class Weitao.
Progressively Finite Games
SCIT1003 Chapter 2: Sequential games - perfect information extensive form Prof. Tsang.
New Toads and Frogs Results By Jeff Erickson Presented by Nate Swanson.
The Game of Nim on Graphs: NimG Gwendolyn Stockman Alan Frieze and Juan Vera.
The Game of Nim on Graphs: NimG By Gwendolyn Stockman With: Alan Frieze, and Juan Vera.
Using Reduction for the Game of NIM. At each turn, a player chooses one pile and removes some sticks. The player who takes the last stick wins. Problem:
4. There once lived a king, named Hagar, who had thousands of sons and daughters, still giving more births to his wives. One of his serious problems was.
DAST 2005 Tirgul 6 Heaps Induction. DAST 2005 Heaps A binary heap is a nearly complete binary tree stored in an array object In a max heap, the value.
Games, Hats, and Codes Mira Bernstein Wellesley College SUMS 2005.
Great Theoretical Ideas in Computer Science.
Great Theoretical Ideas in Computer Science.
MA/CSSE 473 Day 22 Gray Code More Decrease and Conquer Algorithms No class Day 22 in because of Abby's broken arm.
Copyright © Cengage Learning. All rights reserved.
MA/CSSE 473 Day 20 Josephus problem Transform and conquer examples.
A few leftover Decrease-and-conquer Algorithms
MA/CSSE 473 Day 23 Transform and Conquer. MA/CSSE 473 Day 23 Scores on HW 7 were very high (class average was 93%). Good job! (Score was not included.
Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so.
Complexity 20-1 Complexity Andrei Bulatov Parallel Arithmetic.
Winning Strategies of Games Played with Chips. I got a interesting game Now we show the game P 1 =4 P 2 =6 P 3 =8 Rule 1: Two players.
Chapter 8 Integers.
1 INFO 2950 Prof. Carla Gomes Module Induction Rosen, Chapter 4.
Greatest Common Divisors & Least Common Multiples  Definition 4 Let a and b be integers, not both zero. The largest integer d such that d|a and d|b is.
PROBLEM-SOLVING TECHNIQUES Rocky K. C. Chang November 10, 2015.
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
More Induction Discrete Structures (CS 173) Madhusudan Parthasarathy, University of Illinois 1 A Pork-Butchers Shop Seen from a Window Van Gogh.
Benjamin Casey C S 329 E Spring  Variants played since ancient times; resemblance to Chinese “Jianshizi” or “picking stones”  Current name and.
03/05/13 More Induction Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1 Artist: Frank.
MA/CSSE 473 Day 21 In , Day 21 was the exam.
MA/CSSE 473 Days Optimal linked lists Optimal BSTs.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Mathematical Induction I Lecture 19 Section 4.2 Mon, Feb 14, 2005.
MA/CSSE 473 Day 20 Finish Josephus
Some more Decrease-and-conquer Algorithms
Digital Logic & Design Adil Waheed Lecture 02.
Introductory Game Theory
MA/CSSE 473 Day 06 Euclid's Algorithm.
Chapter 4 Systems of Linear Equations; Matrices
Great Theoretical Ideas in Computer Science
CSE322 PUMPING LEMMA FOR REGULAR SETS AND ITS APPLICATIONS
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Nim, nim.py and games.py Homework 4 Problem 4.
Comp/Math 553: Algorithmic Game Theory Lecture 09
Numerical Analysis Lecture 25.
BASIC PROBABILITY Probability – the chance of something (an event) happening # of successful outcomes # of possible outcomes All probability answers must.
SCIT1003 Chapter 2: Sequential games - perfect information extensive form Prof. Tsang.
CDA 3101 Spring 2016 Introduction to Computer Organization
CDA 3101 Summer 2007 Introduction to Computer Organization
Unconventional Fixed-Radix Number Systems
Greedy Algorithm Enyue (Annie) Lu.
Advanced Algorithms Analysis and Design
Digital Logic & Design Lecture 02.
Basic Counting.
UNIVERSITY OF MASSACHUSETTS Dept
Let’s Practice Play 2 Missing Digits !
Josephus Puzzle 毕秋宇.
Systems of distinct representations
Strike it out.
Binary to Decimal Conversion
Heuristic Minimization of Two Level Circuits
Each player can remove 1 or 2 pegs. Player who removes the last peg wins
Each player can remove 1 or 2 pegs. Player who removes the last peg wins
Try starting with fewer objects to investigate.
Induction Rosen 5 Lecture 8: Oct 29, 30.
Game Theory Day 2: More Simple Games.
Activity 2 How is the word length of a two’s complement representation changed without affecting its value? In this activity, we are going to study how.
THE WELL ORDERING PROPERTY
Tutorial 2 - Daniel Razavi
Linear Equations in Linear Algebra
Presentation transcript:

MA/CSSE 473 Day 19 Sleepsort Finish Nim Josephus problem Transform and conquer examples

MA/CSSE 473 Day 19 Announcement of Exam 2 allowed resource change Student Questions SleepSort demo Proofs of Nim strategy lemmas Josephus problem Transform and conquer – what's it all about? Instance simplification: presorting Instance simplification: Gaussian elimination and LU decomposition (Representation change: AVL trees) Pass around attendance sheet.

Recap Multi-Pile Nim There are multiple piles of chips. Two players take turns by removing from any single pile at least one and at most all of that pile's chips. (The number of chips taken can vary from move to move) The winner is the player who takes the last chip. What is the winning strategy for 2-pile Nim? For the general case, consider the "Nim sum", x  y, which is the integer obtained by bitwise XOR of corresponding bits of two non-negative integers x and y. What is 6  3? 2-piles: Take enough chips form larger pile so that n1 = n2. 6  3: 1 1 0 0 1 1 ------ 1 0 1 = 5

Recap: Multi-Pile Nim Strategy Solution by C.L. Bouton: The first player has a winning strategy iff the nim sum of the "pile counts" is not zero. Let's prove it. Note that  is commutative and associative. Also note that for any non-negative integer k, kk is zero.

Multi-Pile Nim Proof Notation: Let x1, … ,xn be the sizes of the piles before a move, and y1, … ,yn be the sizes of the piles after that move. Let s = x1  …  xn, and t = y1  …  yn. Observe: If the chips were removed from pile k, then xi = yi for all ik, and xk > yk . Lemma 1: t = s  xk  yk . Lemma 2: If s = 0, then t  0. Lemma 3: If s  0, it is possible to make a move such that t=0. [after proof, do an example]. Proof of the strategy is then a simple induction. (It's a HW problem) Example: 3 piles, containing 7, 13, and 8 chips. Lemma 1 proof: t = 0 ⊕ t = s ⊕ s ⊕ t = s ⊕ (x1 ⊕ ... ⊕ xn) ⊕ (y1 ⊕ ... ⊕ yn) = s ⊕ (x1 ⊕ y1) ⊕ ... ⊕ (xn ⊕ yn) = s ⊕ 0 ⊕ ... ⊕ 0 ⊕ (xk ⊕ yk) ⊕ 0 ⊕ ... ⊕ 0 = = s ⊕ xk ⊕ yk Lemma 2 proof: If there is no possible move, then the lemma is vacuously true (and the first player loses the normal play game by definition). Otherwise, any move in heap k will produce t = xk ⊕ yk from (*). This number is nonzero, since xk ≠ yk. Lemma 3 proof: Let d be the position of the leftmost (most significant) nonzero bit in the binary representation of s, and choose k such that the dth bit of xk is also nonzero. (Such a k must exist, since otherwise the dth bit of s would be 0.) Then letting yk = s ⊕ xk, we claim that yk < xk: all bits to the left of d are the same in xk and yk, bit d decreases from 1 to 0 (decreasing the value by 2d), and any change in the remaining bits will amount to at most 2d−1. The first player can thus make a move by taking xk − yk objects from heap k, then t = s ⊕ xk ⊕ yk (by (Lemma 1)) = s ⊕ xk ⊕ (s ⊕ xk) = 0.

Josephus problem - background Flavius Josephus was a Jewish general and historian who lived and wrote in the 1st century AD Much of what we know about 1st century life in Israel (and the beginnings of Christianity) before and after the Roman destruction of the Jewish temple in 70 AD comes from his writings The "Josephus problem" is based on an odd suicide pact that he describes He and his men stood in a circle and counted off Every other person (or every third person, accounts vary) was killed The last person was supposed to kill himself He must have been the next-to-last person! When it got down to two people, he persuaded the other person that they should surrender instead http://en.wikipedia.org/wiki/Josephus

Josephus Problem n people, numbered 1-n, are in a circle Count starts with 1 Every 2nd person is eliminated The last person left, J(n), is the winner Examples: n=8, n=7 J(1) = 1 Solution if n is even: Solution if n is odd: Use it to find J(2) … J(8) Clever solution: cyclic bit shift left n=8: First pass eliminates positions 2, 4, 6, 8. Second pass eliminates 3, 7. Third pass 5. 1 left n=7. First pass 2, 4, 6, 1. Then 5, 3 . 7 is left If n is even: We eliminate 2, 4, 6, … n on first round. This leaves us with the same problem for n/2 (except for renumbering) 1 1, 2 3, 35, etc. i2*i-1. Thus J(2k) = 2∙J(k)-1 If n is odd: We eliminate 2, 4, 6, … n-1, 1 on first round. This leaves us with the same problem for (n-1)/2 items (except for renumbering) 1 3, 2 5, 37, etc. i2*i+1. Thus J(2k+1) = 2∙J(k)+1 Cyclic bit shift: 11, 1001, 1111, 100001, 101011, 110101, 111111, 100001