An FPT algorithm for orthogonal buttons and scissors

07/24/2019
by   Dekel Tsur, et al.
Ben-Gurion University of the Negev
0

We study the puzzle game Buttons and Scissors in which the goal is to remove all buttons from an n× m grid by a series of horizontal and vertical cuts. We show that the corresponding parameterized problem has an algorithm with time complexity 2^O(k^2 k) (n+m)^O(1), where k is an upper bound on the number of cuts.

READ FULL TEXT VIEW PDF

Authors

page 1

page 2

page 3

page 4

06/22/2015

An O(n^0.4732) upper bound on the complexity of the GKS communication game

We give an 5· n^_305 upper bund on the complexity of the communication g...
01/28/2021

An Upper Bound on the Complexity of Tablut

Tablut is a complete-knowledge, deterministic, and asymmetric board game...
02/27/2022

Vertical Machine Unlearning: Selectively Removing Sensitive Information From Latent Feature Space

Recently, the enactment of privacy regulations has promoted the rise of ...
03/28/2013

On the speed of constraint propagation and the time complexity of arc consistency testing

Establishing arc consistency on two relational structures is one of the ...
04/30/2020

The Complexity of Dynamic Data Race Prediction

Writing concurrent programs is notoriously hard due to scheduling non-de...
06/08/2017

Mobile vs. point guards

We study the problem of guarding orthogonal art galleries with horizonta...
01/10/2022

GridTuner: Reinvestigate Grid Size Selection for Spatiotemporal Prediction Models [Technical Report]

With the development of traffic prediction technology, spatiotemporal pr...
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

In the Buttons and Scissor puzzle one is given an grid, where some of the cells of the grid contain buttons. Each button has a color. The goal is to remove all buttons from the grid by applying cuts. A cut is a sequence of grid cells with the following properties.

  1. The cell and contain buttons.

  2. All the buttons in the cells of have the same color.

  3. has one of the following forms.

    1. and for all .

    2. and for all .

    3. and for all .

The cuts of the first, second, and third form above are called horizontal cuts, vertical cuts, and diagonal cuts, respectively. The application of a cut deletes all the buttons in the cells of . A horizontal cut will also be denoted and a vertical cut will also be denoted . See Figure 1 for an example.

Figure 1: An example of the Buttons and Scissor puzzle. In this example, the buttons can be removed by applying four cuts: a horizontal cut , a vertical cut , a horizontal cut , and a verticul cut .

The Buttons and Scissors puzzle can be formulated as a decision problem as follows. The input is an matrix representing the buttons and an integer , and the goal is to decide whether all buttons can be removed using at most cuts. The matrix represents the buttons as follows. If then there is no button at cell . If then there is a button with color at cell . The orthogonal buttons and scissor problem is a variant of the buttons and scissors problem in which only vertical and horizontal cuts are allowed.

Both the buttons and scissors problem and the orthogonal button and scissor problem are NP-hard [3]. Some variants of this problem were studied in [2].

Agrawal et al. [1] claimed to give an FTP algorithm for the orthogonal buttons and scissors problem. However, there is an error in their algorithm. In [1], a row block is defined to be a maximal interval of rows of such that all the non-zeros rows in the block are identical. It is claimed that if the number of row blocks is at least then is a no instance. However, this is not true. Suppose that is an

matrix defined as follows. For odd

, and . For even , and . The number of row blocks is while all the buttons in can be removed using two vertical cuts.

In this paper we give an algorithm for the orthogonal buttons and scissors problem whose time complexity is .

2 The algorithm

Let be an instance of the orthogonal buttons and scissors problem. A solution for is a sequence of at most cuts whose application remove all the buttons in . We say that a cut is contained in row (resp., column ) if (resp., ). A cut touches row if . A row or column of is called heavy if it contains at least buttons, and light otherwise. A button is heavy if it is in some heavy row or column. Otherwise, the button is light.

For a set of rows and a set of column , is a sub-matrix of containing the elements for and . A row block is a set of consecutive row indices such that for every column , all the buttons in have the same color. For a row block , let be a set containing every column index such that contains at least one button, and let be a set containing every column index such that contains between and buttons.

We now present our algorithm. The algorithm first repeatedly applies the reduction rules given below. When no reduction rule is applicable, the algorithm solves the reduced instance.

(1)  If there are at more than heavy rows or more than heavy columns, return no.

Lemma 1.

Rule (1) is safe.

Proof.

Suppose that is yes instance and let be a solution for . If no cut of is contained in row  then row  is light since a cut in can remove at most one button from row  of . Therefore, the number of heavy rows is at most . Similarly, the number of heavy rows is at most . Therefore, Rule (1) is safe. ∎

(2)  If there are more than light buttons, return no.

Lemma 2.

Rule (2) is safe.

Proof.

Suppose that is yes instance and let be a solution for . Let be a horizontal cut that is contained in row . If row is heavy then does not remove light buttons. Otherwise, removes at most light buttons. Similarly, a vertical cut removes at most light buttons. Since every button must be removed by a cut in , it follows that there are at most light buttons. ∎

(3)  If row  (resp., column ) does not contain buttons, delete row  (resp., column ) from .

The following reduction rule is adapted from Rule 2 in [1]. For completeness, we give a full proof of the safeness of the rule.

(4)  Suppose that there is row block and an index such that for every column , either (1) does not contain buttons, or (2) there are at least buttons in and at least buttons in . Return the instance , where is a matrix obtained from by deleting all the buttons in row of .

Lemma 3.

Rule (4) is safe.

Proof.

We need to show that is a yes instance if and only if is a yes instance. To prove the first direction we use following claim.

Claim 4.

If is a yes instance, there is a solution for such that no cut of is contained in a row of . Additionally, there is no vertical cut in with endpoint for some column .

Proof.

Suppose that is yes instance, and let be a solution for . We construct a new solution by generating a cut for every cut in . If is cut in that does not touch any row in then the corresponding cut in is . If is a horizontal cut in that is contained in a row in then the corresponding cut in is .

Let be some column. If does not contain buttons then for every vertical cut in such that is contained in column and touches at least one row of , the corresponding cut in is .

Now suppose that contains buttons. Due to the condition of Rule (4), contains at least buttons. Therefore, there is an index such that and there is no cut in that is contained in row . Therefore, the cut in that removes the button is a vertical cut.

Let be the last vertical cut in such that the application of (after the application of the preceding cuts in ) removes at least one button in . Note that exists since is removed by a vertical cut. If is a vertical cut in that is contained in column , touches at least one row of , and appears after in , then the corresponding cut in is . Now, let be a vertical cut in that touches at least one row of and appears before in . The interval cannot contain the interval otherwise we get a contradiction to the definition of . Therefore, there are three possible cases.

  1. and , and at least one inequality is strict.

  2. and .

  3. and .

If is a cut in of the first type above then the corresponding cut in is . Now, let be the cuts in of the second type, according to their order in (note that can be zero). Denote . Since the application of removes all buttons in , we have that . Let be the row indices of the top buttons in . For each cut , the corresponding cut in is . The cuts of the third type are handled analogously: Let be the cuts of the third type, where . Let be the row indices of the bottom buttons in . For each cut , the corresponding cut in is . Finally, the cut that corresponds to is .

It is easy to show by induction that the cuts in are valid cuts (namely, every cut contains buttons of the same color, and the endpoints of the cut contains buttons) and that the application of the cuts of removes all the buttons of . Therefore, is a solution for . ∎

Suppose that is a yes instance. Let be the solution of Claim 4 for . Since there is no cut in with endpoint for some , is also a solution for . Therefore, is a yes instance.

The proof of the opposite direction is similar. Suppose that is a yes instance. Using the same arguments used to prove Claim 4, we have that there is a solution for such that no cut of is contained in a row of . We now generate a solution for by generating a cut for every cut in . Let be a column of such that . Let be the minimum index such that and . Let be the cut in whose application removes the button . If then the corresponding cut in is . Otherwise, the corresponding cut in is . For a cut in that is not one of the cuts above, the corresponding cut in is . It is easy to verify that is a solution for . Therefore, is a yes instance. ∎

(5)  If the number of rows is more than return no.

Lemma 5.

Rule (5) is safe.

Proof.

Suppose that is yes instance and let be a solution for .

We first show that the rows of can be partitioned into at most row blocks. Define to be a set containing and for every heavy row . Let be some column. If is a light column, define . If is a heavy column, let be the set of all indices such that and , where is the maximum index such that and (if the index does not exist, the index is not in ). Let . We partition into row blocks according to as follows. Suppose that where and denote . The row blocks are for every . Additionally, if we define the row block . It is clear from the definition of that each generated interval is a row block.

We now give an upper bound on . The heavy rows generate at most elements in (since there are at most heavy rows). We next consider the contribution of the light columns to . Since we already bounded the number of indices generated by the heavy rows, we only need to consider the light buttons in the light columns. These buttons generate at most elements in (since there are at most light buttons).

We now consider some heavy column . Suppose we remove buttons from according to the cuts of , and after each removal we update . Each cut in (except the last) can decrease the size of by at most 2: The cut can remove all the buttons in for some specific . This causes the removal of from . Additionally, if then will also be removed from . After all the cuts of are applied, . It follows that before applying the cuts, . Therefore, column generates at most elements in . Since there are at most heavy columns, we conclude that . Therefore, the number of generated row blocks is at most .

We now partition the row blocks generated above to sub-blocks. We perform a recursive procedure on every block generated above whose size is at least 2. Note that for such block, contains buttons only in heavy columns and therefore . Denote by the current block given to the recursive procedure. The recursion stops when . Note that in this case, since every row of contains at least one button (otherwise Rule (2) can be applied) and by the definition of , the number of buttons in is at most ( since every column is heavy).

Now suppose that . We consider two cases. In Case 1, . In this case, arbitrarily pick . Let be the row numbers of the buttons in , and define and . We partition into sub-blocks for every , and for every such that . We then continue recursively on each of these sub-blocks. Note that the number of sub-blocks generated from is at most . Moreover, for every generated sub-block of size at least 2 we have and therefore . Since for the initial block , it follows that the number of times Case 1 can occur during a chain of recursive calls is at most .

In Case 2, . For every , let be the row number of the -th button from the top in . Let and let be the column such that . We create two sub-blocks and and continue recursively on each of these sub-blocks. Note that and in particular . Additionally, there is at least one column such that the number of buttons in is less than , since otherwise Rule (2) can be applied on with . Therefore, . It follows that the number of times Case 2 can occur during a chain of recursive calls is bounded by the number of times Case 1 can occur.

From the above, we have that the number of sub-blocks generated from some block is at most . Therefore, the number of rows in is at most . It follows that Rule (5) is safe. ∎

We also use additional reduction rules, Rule (2) and Rule (2), that are analogous to Rule (2) and Rule (3), respectively. If these rules cannot be applied, the number of columns in is at most .

(8)  If the number of buttons is at least , return no.

The safeness of Rule (8) is proved in [1]. The following lemma is also proved in [1].

Lemma 6.

Let be an instance of orthogonal buttons and scissors such that contains buttons. Then, the instance can be solved in time.

Let be an instance on which the above reduction rules cannot be applied. Since Rule (3), Rule (2), and Rule (5) cannot be applied, the number of buttons in is . By Lemma 6, the instance can be solved in time.

References

  • [1] A. Agrawal, S. Kolay, S. Saurabh, and R. Sharma. Kernelizing buttons and scissors. In Proc. 28th Canadian Conference on Computational Geometry (CCCG), pages 279–286, 2016.
  • [2] K. Burke, E. D. Demaine, H. Gregg, R. A. Hearn, A. Hesterberg, M. Hoffmann, H. Ito, I. Kostitsyna, J. Leonard, M. Löffler, et al. Single-player and two-player buttons & scissors games. In Proc. 18th Japanese Conference on Discrete and Computational Geometry and Graphs (JCDCGG), pages 60–72, 2015.
  • [3] H. Gregg, J. Leonard, A. Santiago, and A. Williams. Buttons & scissors is NP-complete. In Proc. 27th Canadian Conference on Computational Geometry (CCCG), page 275, 2015.