kuniga.me > NP-Incompleteness > The Geography Game
14 Sep 2024
In this post we’d like to discuss the Geography game. In the variant we’ll consider, an instance of the game is an undirected graph, and a token placed in one of its vertices.
Two players take turn in moving the token to an adjacent vertex with the constraint that no vertex can be visited twice. If a player cannot move the token without violating that constraint, they lose.
Assuming both players play optimally, it turns out that we can determine which player will win. We’ll also present the optimal strategy each player can use and discuss other variants.
Let’s provide a more formal definition of the problem and some related terminology. Let $G = (V, E)$ be an undirected graph and $v \in V$ a vertex on which a token is placed. We denote by $G \setminus \curly{v}$ the graph with vertex $v$ removed, i.e. with vertices $V \setminus \curly{v}$ and edges $E \setminus \curly{(v, u) \in E, u \in V}$.
Player 1 is the first to go and they can only move the token using an edge $(v, u) \in E$. Then, vertex $v$ is removed from the graph and it’s player 2’s turn with a starting vertex $u$ and graph $G \setminus \curly{v}$. A player loses if their starting vertex is isolated (i.e. they cannot move the token).
The problem consists in determining which player will win (or equivalently which one will lose). We’ll see how to solve this problem in the next section.
Before that, let’s define some useful terminology. A matching $M$ of a graph $G = (V, E)$ is a subset of $E$ such that no two edges are incident to the same vertex. The cardinality of a matching is simply the number of edges in it and denoted by $\abs{M}$.
A maximum matching of $G$ is a matching of the largest cardinality, in other words, if $M^*$ is a maximum matching, no other matching $M$ of $G$ exists such that $\abs{M} \gt \abs{M^*}$. Note that there may be multiple maximum matchings.
A matching saturates a vertex $v \in V$ if it contains an edge incident to $v$.
We’re ready to state the winning condition of the geography game:
Lemma 1. Player 1 wins (and player 2 loses) if and only if all maximum matchings $M$ of $G$, $M$ saturates $v$.
It sounds hard to determine whether all maximum matchings saturate $v$. However, it’s easier than it seems, we don’t have to enumerate all of them. We just need to find any maximum matching $M$ of $G$ and any maximum matching $M’$ of $G \setminus \curly{v}$. If the size of $\abs{M’} = \abs{M}$, then there’s at least one maximum matching in $G$ that does not saturate $v$, but if $\abs{M’} \lt \abs{M}$, we know for sure $v$ is needed in all maximum matchings of $G$!
A maximum matching can be found in polynomial time, for example via the Blossom algorithm, which is $O(\abs{E}\abs{V}^2)$. This lead us to the corollary:
Corollary 2. Let $G = (V, E), v \in V$ be an instance of the undirected vertex Geography game. It’s possible to determine which player loses first in polynomial time.
Summarizing the proof, the optimal strategy for players depend on whether the condition of Lemma 1 is satisfied. We consider both cases:
Case 1. All maximum matches saturate $v$, so player 1 wins. In this case player 1 can win by computing any maximum matching $M$ and moving along an edge in $M$. No matter which move player 2 makes, it’s guaranteed that player 1 will be able to continually move along edges in $M$. Further, player 1 will be the last one to move, so player 2 loses.
Case 2. There’s at least one maximum match $M$ that doesn’t saturate $v$, so player 2 wins. Supose they move along an edge $(v, u)$. Then player 2 computes any maximum match $M’$ of $G \setminus v$. The proof shows that player 2 can keep moving along edges in $M’$ throughout the game, no matter which move player 1 makes, and they will be the last to play, so player 1 loses.
Algorithm. Even though it’s possible to determine which case a given instance belongs to, players don’t need to do this. Their optimal strategy is to compute the maximum match of the graph in their first respective turn. Then always try to move along edges in that matching. If they can’t, it’s a sign they can’t win this instance (assuming the other player plays perfectly), so they might as well choose a random edge.
A generalization of the problem is one in which we don’t specify the starting vertex $v$, but let player 1 choose it.
We can extend the solution of the original problem to this one. Player 1 first computes the maximum matching $M$ of $G$. Then they iterate over each vertex $v$ until they find a matching $M’$ of $G \setminus \curly{v}$ with $\abs{M’} = \abs{M}$. Once they do, they pick that vertex which will give them the victory.
If they cannot find any such vertex, they will lose, so they can just play randomly.
The authors in [1] consider other variants of this problem: the case where the graph is directed, and the case where only the edges cannot be reused, by the vertices can. Surprisingly, all these variants are NP-Complete!
The solution to the Geography game is really neat. It’s non trivial to me that it boils down to computing maximum matchings!
An interesting thing is that the edge-based version of this game is NP-Complete, while the vertex one is in P. A parallel can be drawn between the Hamiltonian path problem (NP-Complete) and the Eulerian path (P). The Hamiltonian is vertex-constrained while the Eulerian is edge-constrained.
Eulerian Circuits. In that post we discussed the Eulerian circuit which is closely related to the Eulerian path, and can also be solved in polynomial time. The “vertex version” of this problem is the Travelling Salesman Problem which is NP-Complete.