The Game of Nim on Graphs: NimG Gwendolyn Stockman Alan Frieze and Juan Vera.

Slides:



Advertisements
Similar presentations
Chapter 9 Graphs.
Advertisements

Divide and Conquer. Subject Series-Parallel Digraphs Planarity testing.
Introduction to Graphs
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
Algorithms and Networks
Tutorial 6 of CSCI2110 Bipartite Matching Tutor: Zhou Hong ( 周宏 )
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
Progressively Finite Games
Finding a Maximum Matching in Non-Bipartite Graphs Alicia Thilani Singham Goodwin /22/2013.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
The Game of Nim on Graphs: NimG By Gwendolyn Stockman With: Alan Frieze, and Juan Vera.
3/29/05Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 4.2 Minimal Spanning Trees Prepared by Amanda Dargie and Michele Fretta.
Applied Discrete Mathematics Week 12: Trees
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Great Theoretical Ideas in Computer Science.
Graph Algorithms Using Depth First Search Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
Great Theoretical Ideas in Computer Science.
Design and Analysis of Computer Algorithm September 10, Design and Analysis of Computer Algorithm Lecture 5-2 Pradondet Nilagupta Department of Computer.
A few leftover Decrease-and-conquer Algorithms
Modular Decomposition and Interval Graphs recognition Speaker: Asaf Shapira.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Module #19: Graph Theory: part II Rosen 5 th ed., chs. 8-9.
© Jalal Kawash 2010 Graphs Peeking into Computer Science.
Fall 2005Costas Busch - RPI1 Mathematical Preliminaries.
Prof. Busch - LSU1 Mathematical Preliminaries. Prof. Busch - LSU2 Mathematical Preliminaries Sets Functions Relations Graphs Proof Techniques.
 Rooted tree and binary tree  Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Discrete Structures Trees (Ch. 11)
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
15-853Page :Algorithms in the Real World Planar Separators I & II – Definitions – Separators of Trees – Planar Separator Theorem.
Chapter 7. Trees Weiqi Luo ( 骆伟祺 ) School of Software Sun Yat-Sen University : Office : A309
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Adversarial Games. Two Flavors  Perfect Information –everything that can be known is known –Chess, Othello  Imperfect Information –Player’s have each.
Introduction to Graphs. This Lecture In this part we will study some basic graph theory. Graph is a useful concept to model many problems in computer.
Matching Algorithms and Networks. Algorithms and Networks: Matching2 This lecture Matching: problem statement and applications Bipartite matching Matching.
Discrete Mathematics Chapter 5 Trees.
CHAPTER 11 TREES INTRODUCTION TO TREES ► A tree is a connected undirected graph with no simple circuit. ► An undirected graph is a tree if and only.
1 Mathematical Preliminaries. 2 Sets Functions Relations Graphs Proof Techniques.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Algorithm Design and Analysis June 11, Algorithm Design and Analysis Pradondet Nilagupta Department of Computer Engineering This lecture note.
5.6 Prefix codes and optimal tree Definition 31: Codes with this property which the bit string for a letter never occurs as the first part of the bit string.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Discrete Structures Li Tak Sing( 李德成 ) Lectures
Content Game of Nim Impartial Games Sprague-Grundy theorem
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Great Theoretical Ideas in Computer Science
Discrete Mathematicsq
12. Graphs and Trees 2 Summary
Algorithms and Networks
Spanning Trees Longin Jan Latecki Temple University based on slides by
Planarity Testing.
CSE 421: Introduction to Algorithms
Instructor: Shengyu Zhang
CMSC 202 Trees.
Lecture 11 CSE 331 Sep 19, 2014.
EMIS 8374 Search Algorithms Updated 9 February 2004
Spanning Trees Longin Jan Latecki Temple University based on slides by
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
EMIS 8374 Search Algorithms Updated 12 February 2008
Presentation transcript:

The Game of Nim on Graphs: NimG Gwendolyn Stockman Alan Frieze and Juan Vera

The Game of Nim 2 players n piles of disks, with a 1, a 2, … a n disks on each pile Players take turns removing disks from each pile A player loses when there are no disks left

Impartial Games Geography, Nim, and NimG are impartial games A game in which the only difference between the two players is which one goes first Every position of an impartial game has a Grundy Number or Nim-Value

Used to represent wining and losing positions Given a game tree T = (V,E) Recursively define: with A player is in a winning position if at the end of his/her turn the playing piece is on such that Sprague-Grundy Numbers (Nim-Sums) x ywz

Grundy Numbers (cont.) Let a 1, a 2, … a n be the binary representations of the number of disks on each of the n piles In the game of Nim the Grundy number for a setup is the bit-wise sum (mod 2) of the a i ‘s Example: The Grundy number is 0 so this is a winning position! 00

Proposed Versions of NimG 2 players 1 piece is moved along an undirected graph with no self- loops, and discs are removed If discs on vertices:  Could move first and then remove discs  Could remove discs and then move Possibly allow moves to empty verticies If discs on edges:  Remove discs as you go along an edge Players take turns removing disks from piles How to win:  The other player can’t complete their turn

Example of Vertex NimG

Geography Two players alternately move a piece on a graph until one loses by being unable to make an legal moves Directed or Undirected Edge Geography  No edge repeated Vertex Geography  No vertex repeated Undirected Vertex Geography  Contained in a version of Vertex NimG with: 1 chip on each vertex Not allowed to move to empty vertices  Solvable in polynomial Time Second player has a winning strategy IFF the graph has a perfect matching (Fraenkel 1993) Undirected Edge Geography  PSPACE-complete (Fraenkel 1993)

Previous Work: Nim on Graphs In A Nim game played on Graphs I and II (Fukuyama 2003) Edge NimG was examined Proved that the Grundy Numbers can be found completely on:  Bipartite Graphs  Trees  Cycles Main Method: matchings on graphs Contains normal Nim  2 vertices with n edges with a 1, a 2, … a n disks on each edge Contains Undirected Edge Geography  1 disk on each edge

The game from now on:  Vertex NimG  Moves to empty vertices allowed Notation for Vertex NimG on a path of length N  ( a 0,a 1,…,a n-1,a n ):0 represents:  Where is the piece being moved The Game: Vertex NimG v0v0 v n-1 a 0 disks a 1 disks a n disks a n-1 disks vnvn … v1v1

Theorem 1: Vertex NimG on path of length 2

NimG on a Path of Length 3 Not so simple on longer paths Grundy Numbers bounded by a function of d, the number of disks on the graph First note that  x    Easy to see that is a child forand  Easy to see that is a child and  Rest omitted for brevity 0 xx 0 0 x 000 x 0

Will prove that given a,b   such that a>b then Because with NimG on a Path of Length 3 (cont.) (0,a,b,0):1 (0,0,b,0):2(0,1,b,0):2(0,2,b,0):2(0,b-1,b,0):2(0,b,b,0):2 0ab0

Take a   and we want to know the value of Examine the children of that position in the game tree and find NimG on a Path of Length 3 (cont.) a +1 1 a 1

NimG on a Path of Length 3 (cont.) Take a   and we want to know the value of Examine the children of that position in the game tree and find a

NimG on a Path of Length 3 (cont.) So given a,b   such that a>b then And Further suppose we have a, b, c, e  {0} such that then (0,a,b,0):1 (0,0,b,0):2(0,1,b,0):2(0,2,b,0):2(0,b-1,b,0):2(0,b,b,0): b+1 2 (0,1,b,0):0 0

Vertex NimG on Any Graph Represent positions of NimG as ( G, A ): v where G is the graph, A is the amount function for G, and marker is at vertex v  V ( G ) A reduced game tree is used to find if a winning strategy exists from a given position, and if one does, what it is Create the reduced game tree, T, where each node is a position, by  making ( G, A ): v the root  For each u  N( v ) such that A ( u )< A ( v ) add node ( G, A ’): u as a child to ( G, A ): v where  Repeat once for each node added to T v x u y (G, A):v (G, A’):u

c v a Example: Create T b v a d bf e c h Player P1 starts with setup (G,A):v v ba c h v abc

c v a Example: Create T d b b v a d bf e c h Start with setup (G,A’):a d b v a bd

c v a Example: Create T d b b v a d bf e c h Start with setup (G,A’’):b a d

c v a Example: Create T d b b ef v a d bf e c h Start with setup (G,A’’):b a e v b ef f

c v a Example: Create T d b b e f f v a d bf e c h Start with setup (G,A’’’):e b c e f f

c v a Example: Create T d b b e f f v a d bf e c h Start with setup (G,A’’’):e b e c f

ee c e f v a Example: Create T df b f fb e f f v a d bf e c h f f e f f

Labeling T If it is player P1’s turn then label all even levels, including 0, of T, P1, and all odd levels P2 Label each node either P1 or P2  Player P1 has a winning strategy from nodes labeled P1  Player P2 has a winning strategy from nodes labeled P2 Label all n  V(T), with labeling function L:V(T)  {P1,P2}, using a depth first labeling starting with the n =root of V(T)  Apply the depth first labeling to all children of n in T  Label n with L ( n ) The root of T is labeled P1 IFF there is a winning strategy for player P1

ff e c e f v a Example: Labeling T df b f fb ef w f a P1 P2 P1 P2 P1 b v w fe w w a v b e b v fe bdd ac e c e f f f ef c f ef b Depth First Labeling of T : = A node labeled P2 = A node labeled P1 = A node whose subtree is being labeled = The node currently being examined P1 does NOT have a winning strategy from (G,A):v ! L(n):= P1 n a leaf and on a P2-level or n on a P1-level and at least one child of n labeled P1 or n on a P2-level and all children of n labeled P1 P2 n a leaf and on a P1-level or n on a P2-level and at least one child of n labeled P2 or n on a P1-level and all children of n labeled P2 n a leaf and on a P1-level or n on a P2-level and at least one child of n labeled P2 n a leaf and on a P2-level or n on a P1-level and at least one child of n labeled P1 or n on a P1-level and all children of n labeled P2

f ef c f ef b f fe bd a Why P1 can’t win Assume that players will always follow a winning strategy if one exists If P1 moves to a, b, or c then P2 will win What if P1 moves to h ? vP1 P2 P1 P2 P1 vvv v a d bf e c h v P1 still loses!

The Winning Strategy: Case 1 If player P2 just moved from vertex u to vertex v, creating setup ( G, A ): v, and ( G, A ’): u is a child of ( G, A ): v labeled P1  Remove r  [1, A ( v )- A ( u )] disks from vertex v and move to vertex u, creating setup with  Replace the sub-tree with root ( G, A’ ): u with the tree of root created as described before (G, A):v (G, A’):u (G, A):v

The Winning Strategy: Case 2 Otherwise, given setup ( G, A ): v pick any child ( G, A ’): u of node ( G, A ): v in T that is labeled P1  remove r  [1, A ( v )- A ( u )] disks from vertex v and move to vertex u, creating setup with  Replace the sub-tree with root ( G, A ’): u with the tree of root created as described before The alterations to T insure that T maintains the property that for any node y=( G, A ): w  V ( T ) (G, A):w (G, A’):x

NimG on any Graph: Analysis Tree T is exponential in size What if there is a maximum number of disks allowed on each vertex?  Polynomial – at most n d number of nodes, where d is the maximum number of disks allowed on a vertex and n =  V ( G )   There does not exist any path starting from the root with a node ( G, A ): v and a node for any amount functions A and root of T  n -1 nodes 1 node  n -2 nodes  n - d nodes

Questions???