# Solving Problems With Two Variables

consider a model of classroom scheduling in which a set of teachers must be scheduled to teach each of cohorts of students. The number of hours per week that teacher spends with cohort is described by entry of a matrix given as input to the problem, and each teacher also has a set of hours during which he or she is available to be scheduled. As they show, the problem is , even when each teacher has at most three available hours, but it can be solved as an instance of 2-satisfiability when each teacher only has two available hours. (Teachers with only a single available hour may easily be eliminated from the problem.) In this problem, each variable corresponds to an hour that teacher must spend with cohort , the assignment to the variable specifies whether that hour is the first or the second of the teacher's available hours, and there is a 2-satisfiability clause preventing any conflict of either of two types: two cohorts assigned to a teacher at the same time as each other, or one cohort assigned to two teachers at the same time.^{}

## algebra 9.3.2 solving problems with two variables

Photo provided by Flickr

### algebra 9.3.2 solving problems with two variables - YouTube

Next to 2-satisfiability, the other major subclass of satisfiability problems that can be solved in polynomial time is . In this class of satisfiability problems, the input is again a formula in conjunctive normal form. It can have arbitrarily many literals per clause but at most one positive literal. found a generalization of this class, , that can still be solved in polynomial time by means of an auxiliary 2-satisfiability instance. A formula is when it is possible to put it into Horn form by replacing some variables by their negations. To do so, Lewis sets up a 2-satisfiability instance with one variable for each variable of the renamable Horn instance, where the 2-satisfiability variables indicate whether or not to negate the corresponding renamable Horn variables. In order to produce a Horn instance, no two variables that appear in the same clause of the renamable Horn instance should appear positively in that clause; this constraint on a pair of variables is a 2-satisfiability constraint. By finding a satisfying assignment to the resulting 2-satisfiability instance, Lewis shows how to turn any renamable Horn instance into a Horn instance in polynomial time.^{} By breaking up long clauses into multiple smaller clauses, and applying a linear-time 2-satisfiability algorithm, it is possible to reduce this to linear time.^{}

### algebra 9.3.2 solving problems with two variables

Although there exist polynomial time algorithms to find a matrix having given row and column sums,^{} the solution may be far from unique: any submatrix in the form of a 2 × 2 can be complemented without affecting the correctness of the solution. Therefore, researchers have searched for constraints on the shape to be reconstructed that can be used to restrict the space of solutions. For instance, one might assume that the shape is connected; however, testing whether there exists a connected solution is NP-complete.^{} An even more constrained version that is easier to solve is that the shape is : having a single contiguous block of squares in each row and column. Improving several previous solutions, showed how to reconstruct connected orthogonally convex shapes efficiently, using 2-SAT.^{} The idea of their solution is to guess the indexes of rows containing the leftmost and rightmost cells of the shape to be reconstructed, and then to set up a 2-satisfiability problem that tests whether there exists a shape consistent with these guesses and with the given row and column sums. They use four 2-satisfiability variables for each square that might be part of the given shape, one to indicate whether it belongs to each of four possible "corner regions" of the shape, and they use constraints that force these regions to be disjoint, to have the desired shapes, to form an overall shape with contiguous rows and columns, and to have the desired row and column sums. Their algorithm takes time where is the smaller of the two dimensions of the input shape and is the larger of the two dimensions. The same method was later extended to orthogonally convex shapes that might be connected only diagonally instead of requiring orthogonal connectivity.^{}

Photo provided by Flickr