Skip to main content

ORIGINAL RESEARCH article

Front. Phys., 02 November 2022
Sec. Quantum Engineering and Technology

A linear algorithm for the restricted subtraction games

Zongbao Yang,,Zongbao Yang1,2,3Zhimin He&#x;Zhimin He 4Lvzhou Li&#x;Lvzhou Li 5Shoubin Dong&#x;,Shoubin Dong 1,3Shenggeng Zheng&#x;
Shenggeng Zheng 2*
  • 1School of Computer Science and Engineering, South China University of Technology, Guangzhou, China
  • 2Peng Cheng Laboratory, Shenzhen, China
  • 3Zhongshan Institute of Modern Industrial Technology of SCUT, Zhongshan, China
  • 4School of Electronic and Information Engineering, Foshan University, Foshan, China
  • 5School of Computer Science and Engineering, Sun Yat-Sen University, Guangzhou, China

The subtraction game is a well-known problem in the field of game theory, which is often called a one-heap Nim game. There are two players, a heap of tokens, and a strategy matrix, in this game. It is called a restricted subtraction game if some constraints are imposed on the strategy matrix. The subtraction game could be solved by a classical algorithm with a query complexity no less than O(N2) and computed by an O(N32logN) quantum query algorithm with an error probability ϵ1N. The restricted subtraction game proposed by Huang et al. can be computed by an exact quantum algorithm with O(N32) queries. They also proved that the classical exact query complexity is Θ(N2). In this study, we use an array and an adjacency list to replace the strategy matrix and propose another more general subtraction game than the one introduced by Huang et al. Based on dynamic programming and the replaced game strategy, two linear classical query algorithms are designed to solve the restricted subtraction game proposed by Huang and this study, respectively.

1 Introduction

Quantum computing is becoming a very hot research topic nowadays. There are various computing models [1, 2], including quantum query complexity [35], communication complexity [6, 7], and quantum finite automata [811] [12,13]. Game theory is an important branch of modern mathematics, which has been applied in many fields, such as economics and business, project management, and computer science. There are many kinds of games in game theory, including infinitely long games, discrete and continuous games, and combination games. Quantum games and quantum strategies have been investigated since the 1990s [14,15]. Recently, the subtraction game has attracted great attention. It is a kind of Nim game, which belongs to combination games [16]. Nim games are notable games in game theory, and they have similar definitions to subtraction games [17]. Following the definition of subtraction games introduced by Kravchenko et al. [18], there are two players, a heap of tokens and a strategy matrix Γ, in a subtraction game. Based on the strategy matrix Γ, two players take away a number of tokens one by one. The one who cannot make a legal move will lose the game. In addition, Huang proposed a restricted subtraction game in [19], where a constraint is imposed on the strategy matrix. In the restricted subtraction games, at most one “1ˮ is allowed in each column of the strategy matrix, and the rest is the same as the common subtraction games introduced in [18].

Inspired by Huang, another restricted subtraction game is proposed in this study, which is more general than the one introduced by Huang et al. [19], that there are only a small number of “1sˮ in each column of Γ. The other part of this game is also the same as the common subtraction game. The detailed definition of the subtraction game and the restricted subtraction games is shown in Section 2.3.

The core of solving the (restricted) subtraction games is to find an element from the disorder strategy matrix, which is the basis of all the classical and quantum algorithms. As shown by Kravchenko [18] and Huang et al. (2020), when solving the subtraction games, the query complexity of the classical algorithms is no less than O(N2). To reduce query complexity, researchers have proposed quantum query algorithms to solve common subtraction games. For example, Khadiev and Kravchenko et al. (2019) had designed a bounded error quantum query algorithm, with an error probability of ϵ1N, to solve the subtraction game in the query complexity of O(N32logN). As for the restricted subtraction game, Huang [19] proposed an exact quantum query algorithm to solve it with a query complexity of O(N32).

The proposed quantum algorithms to solve the common subtraction games and the restricted subtraction games in [18,19] are mainly based on Grover’s algorithm [20] and exact Grover’s algorithm [21], respectively. As mentioned earlier, there is a subroutine to find the position of an element in a disorder data set. Grover's algorithm (with a query complexity of O(N)) is the most efficient method to accomplish this compared with any classical algorithms (with a query complexity of Ω(N)), where N stands for the size of the data set. If the number of targets is not clear, Grover’s algorithm will return a bounded error result with a query complexity of O(N). However, when there is only one target in the data set, Long [21] designed an exact Grover’s algorithm to find its position with a query complexity of O(N).

To better solve the common subtraction games and the restricted subtraction games, two new data structures are introduced, and two linear query complexity algorithms are designed to solve them. The designed algorithms are based on dynamic programming and other forms of game strategy, which replace the strategy matrix with other data structures. In more detail, the strategy matrix is replaced with the strategy array when dealing with the subtraction game proposed by Huang et al. [19]. When dealing with the restricted subtraction game proposed in this study, we replace the strategy matrix with the strategy adjacency list. More details will be introduced in the following sections.

This article is organized as follows: the background knowledge is introduced in Section 2, including definitions of exact quantum query algorithms, bounded error quantum query algorithms, (restricted) subtraction games, and some notations used in this study. Section 3 introduces the data structures and the designed algorithms. Finally, Section 4 shows the conclusions.

2 Preliminary

In this section, we recall some background knowledge, including the notations used in this study, the definitions of quantum query algorithms, the common subtraction games, and the restricted subtraction games.

2.1 Some basic notations

In this part, we introduce some notations used in this study.

• Γ: It stands for the strategy in the subtraction games, which is often represented by an n × n Boolean matrix. n means the number of tokens in a heap. If Γij = 1 and there are enough tokens in the heap, the current player can remove ji tokens from the heap.

• Position: We call each number of tokens a position, so that if Γij = 1 and the remaining tokens are available, the current player can move from position j to position i.

• Losing position: A position is called a losing position if there are no available moves in this position or each possible move leads to a winning position of the opponent.

• Winning position: A position is called a winning position if there exists a possible move leading to a losing position for the opponent.

• W-value: It represents the property of a position. The W-value is 0 for a losing position and 1 for a winning position.

W[i]: It denotes the W-value of position i. The main purpose of the subtraction game and its variations is to find the value of W by querying the elements of Γ as few as possible.

ADJ(k): It stands for the neighbor of a given node k.

2.2 Quantum query algorithms

Quantum query complexity is the quantum generalization of classical decision tree complexity. In this complexity model, an algorithm is charged for “queries” to the input bits, while any intermediate computation is considered free. See [3, 22] for details on quantum query complexity and exact quantum query complexity.

For an input x = {x1x2xn} ∈ {0,1}n, a quantum query could be regarded as a unitary transformation determined by the following Eq. 1:

Ox|i=1xi|i,(1)

during which i ∈ {1, 2, , n}. Therefore, if there are t queries in a quantum algorithm A, then A could be regarded as performing a series of unitary operators, U0, Ox, U1, , Ox, Ut, on the initial state |ψ0⟩. This process could be formulated as the following Eq. 2, and the final state is denoted as |ψf⟩:

|ψf=UtOxUt1U1OxU0|ψ0.(2)

Finally, we measure the final state |ψf⟩ with measure operators {M0, M1}. For a special input x, the measured results are the outputs of algorithm A, which can be denoted as A(x). According to the quantum information theory, it is obvious to know that Pr[A(x)=0]=M0|ψf2 and Pr[A(x)=1]=M1|ψf2.

We say that the quantum query algorithm A computes f within an error ɛ if it holds Pr[A(x) = f(x)] ≥ 1 − ɛ for every input x ∈ {0,1}n. If ɛ = 0, we say that the quantum algorithm is exact.

2.3 Subtraction games and their variations

The detailed definition of subtraction games and restricted subtraction games is mainly referred to in [18, 19]. We will retell in brief these two games as follows.

2.3.1 Subtraction games

There are two players in a subtraction game, who remove some positive number of tokens from a heap one by one. There is only one heap in the subtraction games, and it assumes that there are n tokens in a heap in the initial state. The number of tokens that each player can remove is constrained by an n × n strategy matrix Γ, and each element Γij ∈ {0, 1}. In addition, Γ is an upper triangle matrix. For any element in Γ, if Γij = 1, then the current player can remove ji tokens from the heap when the number of tokens left in the heap is available. In the end, a player will lose the game if (s)he cannot make a legal move or if this player is now in a losing position where each possible move will lead to a winning position for the opponent. Otherwise, the other player will win the game.

2.3.2 Restricted subtraction game

Huang proposed a restricted subtraction game in [19]. They imposed a constraint on the strategy matrix Γ and supposed that only one “1” at most is allowed in each column of Γ. The other part of the restricted subtraction game is the same as the subtraction games. With this assumption, they could find the position of this “1” in each column by an exact quantum query algorithm [21] rather than the bounded error one. So, the algorithm designed in their study has an acceleration compared with the classical algorithm.

We can relax the restriction proposed by Huang et al. [19] by assuming that there are only a small number of “1s” in each column of the strategy matrix Γ. The other parts are the same as with the common subtraction game.

In this section, we recall some background knowledge, including the notations used in this study, the definitions of quantum query algorithms, the common subtraction games, and the restricted subtraction games.

3 The proposed algorithms

In this section, the data structures that are used to replace the strategy matrix are introduced, and the linear exact query algorithms are designed for the proposed restricted subtraction games and the one in [19]. In addition, we also designed a dynamic programming-based algorithm for the common subtraction game [18].

3.1 Data structures

This section introduces two data structures that can achieve the same effect as the strategy matrix, which are the adjacency list and the array.

3.1.1 The adjacency list

The adjacency list is a collection of unordered lists used to represent a finite graph as an array in graph theory and computer science. The index of the array stands for a vertex, and each element in its linked list represents the other vertices that form an edge with the vertex. It can achieve the same effect with a matrix, while it is more efficient when the matrix is sparse.

For the subtraction games, because the original strategy matrix Γ may be given in a random way, we do not know the position of the element “1.” If the strategy matrix is sparse, we can append i (0 < i < j) to the adjacency list Γ′ randomly, where i is the position of “1” in each column j to obtain the same strategy. From this point of view, both the strategy matrix Γ and the adjacency list Γ′ can represent the same strategy for the subtraction games. Therefore, the strategy matrix can be replaced with the adjacency list when there are only a small number of “1s” in each column of the strategy matrix Γ. We do not quantify this “small numberˮ as long as it reflects the storage advantage of the adjacency list.

Furthermore, we take a 5 × 5 strategy matrix Γ as an example to explain this process more clearly. For example, if we have a 5 × 5 strategy matrix Γ, where

Γ=1100001100000100001100001,

then the position of each element “1” in each column is appended to Γ′. For example, as the position of the element “1” in column 3 of Γ is 2 and 3, we can append the nodes 2 and 3 to V3 in Γ′ sequentially. Therefore, we can obtain the adjacency list of the strategy Γ′, which has the same effect as the matrix strategy Γ, as follows:

Please note that the previous explanation is aimed to illustrate that the matrix and the adjacency list are equivalent when generating the game strategy not that the matrix and the adjacency list are equivalent at the data structure level.

3.1.2 The array

In computer science, an array is a data structure composed of a collection of elements of the same type, and a contiguous piece of memory is allocated for storage. Each element in the array can be obtained through the index immediately.

As for the restricted subtraction game proposed by Huang [19], there is only one “1” at most in each column of the matrix strategy. Therefore, if we know the index of element “1” in each column, we can determine the strategy. In this situation, the position of each element “1” can be stored in the array and achieve the same effect as the matrix. Therefore, the strategy matrix can be replaced by the array.

For more detail, we denoted the column j of Γ as Γ[j] and the strategy array as Γ′′. The element in Γ″[j] ∈ [ − 1, i] and Γ″[j] ∈ Z. If Γ″[j] = −1, then there is no “1” in Γ[j], else the value of Γ″[j] stands for the position of “1” in Γ[j]. Therefore, both Γ and Γ″ can generate the strategy of restricted subtraction games. We also take a 5 × 5 strategy matrix Γ as an example, where

Γ=0100000100000000000000000.

When the strategy array Γ is used to replace the strategy matrix Γ, we can set Γ″[2] = 1 and Γ″[3] = −1 because the position of “1” in Γ[2] is 1, and there is no “1” in Γ[3]. Therefore, we can obtain Γ″ as Γ″ = [ − 1, 0, 1, − 1, − 1].

3.2 Solving the common subtraction game

We first designed an algorithm to solve the common subtraction game and analyze its query complexity. Based on it, two algorithms are designed for solving the restricted subtraction games proposed in this study by Huang et al. [19], and their query complexity is analyzed.

Algorithm design: Algorithm 1 is designed for solving common subtraction games. During this, Wt(k) stands for the name of the function, and the other notations are introduced as before.

ALGORITHM 1
www.frontiersin.org

Algorithm 1. Solving the common subtraction games.

Query complexity analysis: From Algorithm 1, it is clear to find that only the operator of ADJ[j] needs to query the strategy matrix Γ. In addition, Algorithm 1 is based on dynamic programming, and the function Wi(k) is invoked recursively in the “while” loop. Therefore, it is easy to know that the query complexity of Algorithm 1 is O(N2). It should be noted that the query complexity of the subtraction game has been proved to be no less than O(N2).

3.3 Solving the restricted subtraction game proposed in this study

When the number of “1” in each column is a small constant m, (mn), the n × n strategy matrix Γ will be very sparse. In this situation, we can use the adjacency list Γ′ to replace the strategy matrix Γ.

Algorithm design: Based on the characteristics of an adjacency list, we can obtain ADJ(j) of a given node j in a constant time, and Algorithm 2 is designed to solve this restricted subtraction game.

ALGORITHM 2
www.frontiersin.org

Algorithm 2. Solving the restricted subtraction game proposed in this study.

Query complexity analysis: The query complexity of the adjacency list is O(m), where m is the total number of “1s” in each column of the strategy matrix Γ. Since there are only a small number of “1s” in Γ to access all of the “1s” in the strategy matrix, the query complexity can be regarded as constant, which is O(1). Therefore, the query complexity of the ADJ(k) operator in Algorithm 2 is (O(1)). According to the analysis in Section 3.2, it is easy to know that the query complexity of Algorithm 2 is O(N). However, following the analysis in Kravchenko et al. (2019), the query complexity of this game is O(N32logN) and O(N2) for the quantum query algorithm and the classical algorithm, respectively. Therefore, we can draw a conclusion that the query complexity can be improved when replacing the strategy matrix with the adjacency list.

3.3.1 Solving the restricted subtraction games in Huang et al.

As mentioned in Huang et al. [19], the main idea of the restricted subtraction games is imposing a constraint on the strategy matrix, such that there should be only one “1” at most in each column. With this constraint, Huang et al. [19]used the exact Grover’s algorithm to find the position of such a “1” if there exists a “1” in that column [19]. After that, they update the value of W[i] with the following conditions; if W[i] = 0, then W[j] = 1, else W[j] = 0(ij). Based on Grover’s algorithm, the query complexity of this exact quantum algorithm is O(n32logN) [21] compared with the classical algorithm O(N2).

Similarly, with the situation in Section 3.3, we could further decrease the query complexity of the restricted subtraction game by replacing the strategy matrix Γ with the array Γ″.

Algorithm design: According to the characteristics of the array, it will be more efficient to search for the target point “1” in the array Γ″ because it can be directly accessed without using other algorithms. So, the query complexity of finding the position of “1” is constant (O(1)). In addition, the other parts of this algorithm are similar to Huang’s method. Finally, we could design Algorithm 3 to solve the restricted subtraction games proposed by Huang et al. [19].

ALGORITHM 3
www.frontiersin.org

Algorithm 3. Solving the restricted subtraction games in Huang et al. [19].

Query complexity analysis: Since the query complexity of determining the value of Γ′′ is O(1), it is easy to find that the algorithm 0 can be computed in a linear query time, that is, the query complexity is O(N). It is more efficient compared with Huang’s method (Huang et al., 2020), whose query complexity is O(N32logN).

4 Conclusion

Subtraction games and their variants can be solved by both classical and quantum algorithms. Inspired by the restricted subtraction game proposed by Huang, we proposed another restricted subtraction game. Two linear query complexity algorithms are designed to solve them, which is based on dynamic programming and data structures, namely, the adjacency list and the array. The query complexity of the proposed algorithms is O(N), which is more efficient than that of the traditional classical algorithms, whose query complexity is O(N2), and the quantum algorithms, whose query complexity is O(N32logN).

Data availability statement

The original contributions presented in the study are included in the article/Supplementary Material; further inquiries can be directed to the corresponding author.

Author contributions

SZ, LL, and ZH conceived the idea and algorithms. ZY wrote the manuscript under the guidance of SZ and SD.

Funding

This work is supported in part by the National Natural Science Foundation of China (61976239), Innovation Foundation of High-end Scientific Research Institutions in Zhongshan of China (2019AG031), Natural Science Foundation of Guangdong Province of China (2021A1515011942). ZY and SZ acknowledge supports in part from the Major Key Project of PCL. ZH acknowledges supports in part from the Key Platform, Research Project of Education Department of Guangdong Province (No.2020KTSCX132). LL acknowledges supports in part from the the Guangdong Basic and Applied Basic Research Foundation (Grant No.2020B1515020050).

Conflict of interest

The authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.

Publisher’s note

All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors, and the reviewers. Any product that may be evaluated in this article, or claim that may be made by its manufacturer, is not guaranteed or endorsed by the publisher.

References

1. Gruska J (1999). Quantum computing, vol. 2005. United States: McGraw-Hill London.

Google Scholar

2. de Wolf R (2019). Quantum computing: Lecture notes. arXiv preprint Available at: http://arXiv/org.abs1907.09415

Google Scholar

3. Buhrman H, de Wolf R. Complexity measures and decision tree complexity: A survey. Theor Comp Sci (2002) 288:21–43. doi:10.1016/s0304-3975(01)00144-x

CrossRef Full Text | Google Scholar

4. Qiu D, Zheng S. Revisiting deutsch–jozsa algorithm. Inf Comput (2020) 275:104605. doi:10.1016/j.ic.2020.104605

CrossRef Full Text | Google Scholar

5. Qiu D, Zheng S. Generalized deutsch-jozsa problem and the optimal quantum algorithm. Phys Rev A (Coll Park) (2018) 97:062331. doi:10.1103/physreva.97.062331

CrossRef Full Text | Google Scholar

6. Buhrman H, Cleve R, Massar S, de Wolf R. Nonlocality and communication complexity. Rev Mod Phys (2010) 82:665–98. doi:10.1103/revmodphys.82.665

CrossRef Full Text | Google Scholar

7. Gruska J, Qiu D, Zheng S. Generalizations of the distributed Deutsch–Jozsa promise problem. Math Struct Comp Sci (2017) 27:311–31. doi:10.1017/s0960129515000158

CrossRef Full Text | Google Scholar

8. Ambainis A, Freivalds R. 1-way quantum finite automata: Strengths, weaknesses and generalizations. In: Proceedings 39th Annual Symposium on Foundations of Computer Science; 08-11 November 1998. CA, USA: IEEE (1998). p. 332–41.

Google Scholar

9. Bhatia AS, Zheng S. A quantum finite automata approach to modeling the chemical reactions. Front Phys (2020) 8:547370. doi:10.3389/fphy.2020.547370

CrossRef Full Text | Google Scholar

10. Zheng S, Qiu D, Gruska J, Li L, Mateus P. State succinctness of two-way finite automata with quantum and classical states. Theor Comp Sci (2013) 499:98–112. doi:10.1016/j.tcs.2013.06.005

CrossRef Full Text | Google Scholar

11. Zheng S, Qiu D, Gruska J. Power of the interactive proof systems with verifiers modeled by semi-quantum two-way finite automata. Inf Comput (2015) 241:197–214. doi:10.1016/j.ic.2015.02.003

CrossRef Full Text | Google Scholar

12. Zhang S, Li L. A brief introduction to quantum algorithms. CCF Trans High Perform Comput (2022) 4:53–62. doi:10.1007/s42514-022-00090-3

CrossRef Full Text | Google Scholar

13. Wang Y, Lou X, Fan Z, Wang S, Huang G. Verifiable multi-dimensional (t, n) threshold quantum secret sharing based on quantum walk. Int J Theor Phys (2022) 61:24. doi:10.1007/s10773-022-05009-w

CrossRef Full Text | Google Scholar

14. Meyer DA. Quantum strategies. Phys Rev Lett (1999) 82:1052–5. doi:10.1103/physrevlett.82.1052

CrossRef Full Text | Google Scholar

15. Eisert J, Wilkens M, Lewenstein M. Quantum games and quantum strategies. Phys Rev Lett (1999) 83:3077–80. doi:10.1103/physrevlett.83.3077

CrossRef Full Text | Google Scholar

16. Fudenberg D, Tirole J. Game theory. United States: MIT press (1991).

Google Scholar

17. Kravchenko D, Khadiev K, Serov D, Kapralov R. Quantum-over-classical advantage in solving multiplayer games. In: Proceedings Reachability Problems - 14th International Conference; October 19-21, 2020; Paris, France, 12448. Springer (2020). p. 83–98.

CrossRef Full Text | Google Scholar

18. Kravchenko D, Khadiev K, Serov D. On the quantum and classical complexity of solving subtraction games. In: ProceedingsComputer Science - Theory and Applications - 14th International Computer Science Symposium in Russia; July 1-5, 2019; Novosibirsk, Russia, 11532 of. Springer (2019). p. 228–36. CSR 2019Lecture Notes in Computer Science.

CrossRef Full Text | Google Scholar

19. Huang Y, Ye Z, Zheng S, Li L. An exact quantum algorithm for a restricted subtraction game. Int J Theor Phys (Dordr) (2020) 59:1504–11. doi:10.1007/s10773-020-04418-z

CrossRef Full Text | Google Scholar

20. Grover LK. A fast quantum mechanical algorithm for database search. In: Proceedings of the Twenty-Eighth Annual ACM Symposium on Theory of Computing; New York, NY, USA, ’96. New York: Association for Computing Machinery (1996). p. 212–9.

PubMed Abstract | CrossRef Full Text | Google Scholar

21. Long GL. Grover algorithm with zero theoretical failure rate. Phys Rev A (Coll Park) (2001) 64:022307. doi:10.1103/physreva.64.022307

CrossRef Full Text | Google Scholar

22. Ambainis A, Gruska J, Zheng S. Exact quantum algorithms have advantage for almost all boolean functions. Quan Inf Comput (2015) 15:435–52. doi:10.26421/qic15.5-6-5

CrossRef Full Text | Google Scholar

Keywords: subtraction games, restricted subtraction games, query complexity, quantum query algorithm, classical query algorithm

Citation: Yang Z, He  Z, Li  L, Dong  S and Zheng  S (2022) A linear algorithm for the restricted subtraction games. Front. Phys. 10:1049019. doi: 10.3389/fphy.2022.1049019

Received: 20 September 2022; Accepted: 12 October 2022;
Published: 02 November 2022.

Edited by:

Nanrun Zhou, Shanghai University of Engineering Sciences, China

Reviewed by:

Kejia Zhang, Heilongjiang University, China
Xiaoping Lou, Hunan Normal University, China

Copyright © 2022 Yang, He , Li , Dong  and Zheng . This is an open-access article distributed under the terms of the Creative Commons Attribution License (CC BY). The use, distribution or reproduction in other forums is permitted, provided the original author(s) and the copyright owner(s) are credited and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is permitted which does not comply with these terms.

*Correspondence: Shenggeng Zheng , zhengshg@pcl.ac.cn

Disclaimer: All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors and the reviewers. Any product that may be evaluated in this article or claim that may be made by its manufacturer is not guaranteed or endorsed by the publisher.