WorksMathematics
An Algebraic Matching Algorithm for the Genus of Grid Diagrams
Abstract
Grid diagrams encode knots and links combinatorially through an (n,n) winding matrix W(G). A fundamental invariant of the grid diagram is its genus g(G), which records essential topological information about the underlying knot. We give an algebraic algorithm that computes g(G) directly from W(G). The method repurposes the Hungarian algorithm ,after a column normalization that makes the matrix non-negative, it applies row-column reductions and minimum-vertex-cover corrections until the zero entries admit a perfect matching, equivalently until the minimum marking number equals n. By Konig's theorem the resulting permutation defines a distinguished grid state, and g(G) is then read from this matrix via the classical grid homology formula (Ozsvath-Stipsicz-Szabo). The novelty of this paper is the algorithm and its strongly polynomial analysis; the underlying invariant is known grid-homology theory. We illustrate the method on the trefoil and additional examples, and discuss extensions to (m,n) matrices and grid-move navigation toward the knot genus g(K).
Introduction
Grid diagrams provide a purely combinatorial encoding of knots and links: an grid diagram records the positions of and markers, and the horizontal and vertical segments joining them form a knot diagram (Cromwell [2, 3]; Dynnikov [4]).
In 2009, C. Manolescu, P. Ozsváth, and S. Sarkar [9] found a purely combinatorial description of knot floer homology by grid diagram. In 2025, C. Manolescu, P. Ozsváth and D. Thurston [10] gave combinatorial descriptions of the Heegaard Floer homology groups for arbitrary three-manifolds via the grid diagram of link.
What we consider here is the genus of grid diagram. Each grid diagram carries a winding matrix , an integer matrix (first column and last row identically zero) that records the relative winding of the horizontal and vertical arcs. A central integer of is its associated genus (the genus of a Seifert surface constructed from ). In the grid-homology framework of Ozsváth–Stipsicz–Szabó [11], is computed from a minimal non-negative matrix derived from by row and column operations. The associated genus of a grid diagram realises the Seifert genus of the underlying knot: for every knot there exists a grid diagram with (see e.g. Ozsváth–Stipsicz–Szabó [11]); computing it directly from is the central problem addressed in this paper.
The contribution of this paper is algorithmic. We show that the relevant matrix can be produced from by a repurposed Hungarian algorithm, and that the data required are computed in strongly polynomial time. We do not re-prove that is determined by ; our result is the computation of and of .
Theorem 1.1 (Main algorithmic result). Let be a grid diagram of index with winding matrix . After the column normalization (2) and Algorithm 1, the output is a matrix with that is a minimal non-negative matrix in the sense of Ozsváth–Stipsicz–Szabó [11]. The genus is then obtained from by the closed formula of Proposition 3.4.9 in [11], whose well-definedness is guaranteed by Corollary 3.4.10 in [11]. The algorithm performs this computation in strongly polynomial time.
Termination of Algorithm 1 and the bound are established in § 3. That the output is a minimal non-negative matrix, and that is read from , which are known results in grid homology; we recall them and verify that our normalization (2) places us in their setting in § 4.
As an application of the algorithm, the effect of grid moves on the associated genus of grid diagram was considered in Section 5. It is known that given a grid diagram representing knot , after a sequence of grid moves, we will obtain a new grid diagram satisfying . Therefore, the study of the associated genus of grid diagram, and in particular the effect of grid moves on the associated genus, is important for the study of knot genus. In [8], Marc Lackenby proved that any diagram of the unknot with crossings may be reduced to the trivial diagram using at most Reidemeister moves. Thus we have the following conjecture.
Conjecture 1.2. Given a grid diagram representing knot . How can we find a finite sequence of grid moves to obtain a grid diagram from , which satisfying ? Or is there an upper bound on the grid moves?
The algebraic procedure developed here is not new in the optimisation sense: it is the Hungarian algorithm repurposed, looking for any permutation of zeros rather than a minimum-cost one. What is new is the application to grid diagrams: the winding matrix of a grid diagram encodes its genus , and Algorithm 1 computes algebraically, by producing the minimal non-negative matrix from which is read via the grid-homology formula of Ozsváth–Stipsicz–Szabó (Proposition 3.4.9; Corollary 3.4.10).
The method extends without difficulty to matrices, with the termination condition . Directions for further work include adapting it to coloured grid graphs and to diagrams that encode knots, and relating the extracted genus more explicitly to the Seifert genus over all grid diagrams of a knot (see e.g. Cromwell [2] and Jin, Stoimenow & Lee [6]). The minimal grid number and the range of associated genera over grid diagrams of have been studied extensively, e.g. by Cromwell [2] and Jin, Stoimenow & Lee [6].
The paper is organised as follows. Section 2 develops the algebraic algorithm (minimum marking number, the iterative procedure, and why a maximum matching survives each correction). Section 3 establishes termination via a potential-function argument and a strongly polynomial time bound. Section 4 applies the algorithm to grid diagrams, recalls the grid-homology formula that yields , and illustrates it on the trefoil and further examples. Section 5 applied the algorithm to find the relation between associated genus of grid diagram and gird move. This is important for computing the genus of knot.
Algorithm
Let be an matrix. Write for its set of zero positions.
Definition 2.1. A pair with marks all zeros of if for every , either or (or both). The minimum marking number of is defined by
By König’s theorem, equals the size of a maximum matching in the bipartite graph with bipartition and edge set . One can therefore compute in time via the Hopcroft–Karp algorithm [5], or by any other maximum matching algorithm.
We now describe the algorithm.
The algorithm has two phases. Phase 1 ensures that every row and every column of the matrix contains at least one zero. Phase 2 iteratively adjusts the matrix until .
Algorithm 1 Transforming a non-negative matrix to one with
Require: An non-negative integer matrix
Ensure: A non-negative matrix with
Phase 1: Initial reduction.
for to do
for to do
end for
end for
for to do
for to do
end for
end for
Phase 2: Incremental Hungarian (Kőnig) iteration.
Initialise dual potentials from Phase 1 (the current reduced matrix is , non-negative with a zero in each row/column).
Compute an initial maximum matching in the zero graph .
loop
if then
and terminate
end if
Grow an alternating tree from the unmatched rows of in
if an augmenting path is found then
24: Augment along it; restart from the new unmatched rows ▷ MNM increases by 1
25: else
26: defines a minimum vertex cover ; set ,
27: ▷ , Lemma 2.2
28: Update potentials: for ; for
29: The newly created zeros enter and are added to ; continue growing ▷ no restart
30:
31: end if
32: end loop
Figure 1. Flowchart of the iterative correction phase (Phase 2). The loop repeats the minimum-vertex-cover correction until the minimum marking number reaches (equivalently, the zero positions admit a perfect matching); (, respectively) denotes the matrix with all elements equal to 0, except the -th row (-th column, respectively), where all elements are 1; the the returned non-negative matrix is .
For each row of the Phase 1 (lines 2–13), we subtract its minimum entry, then for each column we subtract its minimum entry. The resulting matrix is non-negative and each row and each column contains at least one zero.
At the start of Phase 2 (lines 15–32) we maintain, together with the current reduced matrix, a maximal matching in its zero graph and the dual potentials introduced in Phase 1 (so that the current entry is ). If the matching is perfect and we terminate. Otherwise we grow an alternating tree from an unmatched row. If an augmenting path is found we augment (raising MNM by one) and continue; if no augmenting path exists, the tree yields a minimum vertex cover by König’s theorem. This is the standard alternating-path construction (see e.g. [12 Ch. 7]) and has the following well-known property:
Lemma 2.2. Let be the minimum vertex cover obtained from a maximum matching via alternating paths. Let and be the rows and columns not in the cover. Then there is no zero of the current reduced matrix in . Hence
We then apply the dual update
decrease by for every unmarked row ;
increase by for every marked column .
Equivalently, in the explicit matrix form this subtracts from the unmarked rows and adds to the marked columns. The operation is the dual-update step of the Hungarian algorithm (Kuhn [7]; see also Burkard, Dell’Amico & Martello [1]). Crucially, the alternating tree, the matching and a slack array over the tree frontier are maintained across corrections: a correction only exposes new zero edges on the frontier and the search continues without restarting. It is this incremental maintenance—not a from-scratch recomputation of the matching at each step—that delivers the strongly polynomial bound of § 3.
| Row status | Column status | Update | Zeros preserved? |
| (unmarked) | (marked) | unchanged | |
| (unmarked) | (unmarked) | new zeros appear | |
| (marked) | (marked) | zeros disappear | |
| (marked) | (unmarked) | unchanged |
Table 1. Effect of the correction step on matrix entries
After the update we increment and repeat.
Termination and Complexity
The termination proof requires that MNM never decreases along the iteration. The naive claim that the current maximum matching survives each correction step is false in general; we therefore establish monotonicity from the structure of minimal markings instead. Write for the set of zero positions of a matrix .
Non-decrease of MNM
Lemma 3.1. Let be a minimal marking of all zeros of an matrix , where is the set of marked rows and the set of marked columns. For any subset , define its neighbour set in the unmarked columns by
Then .
Proof. Suppose, for a contradiction, that some satisfies . Build a new marking with and . We check that marks every zero :
if , then is marked by the row ;
if : when we have , and when the definition of gives ;
if , minimality of the original marking forces .
Since , we have . Let be MNM. Then
contradicting the minimality of . Hence .
The symmetric statement also holds: for any , writing , one has .
Definition 3.2. A zero of that is marked by both a row in and a column in is called a cross zero.
Proposition 3.3. Let be the set of all zeros of , and let be obtained from by deleting all cross zeros. Then the minimum marking number of equals the minimum marking number of .
Proof. Write and . Since , we have .
For the reverse inequality, take any marking of , and set and . For a row we have , so every zero with must be column-marked, i.e. , hence ; thus . Because the columns in avoid , they are disjoint from , so . Symmetrically, . Adding and using Lemma 3.1 (and its symmetric form),
Since was arbitrary, , and therefore .
Proposition 3.4. In each iteration of the algorithm the minimum marking number stays the same or increases.
Proof. Let be before the correction, the of the zeros remaining after deleting the cross zeros before the correction, and the after the correction. If there are no cross zeros, the correction only creates new zeros and never removes old ones, so . If cross zeros are present, Proposition 3.3 gives ; the post-correction is the minimum marking number of the old non-cross zeros together with the newly created zeros, hence . In either case , so never decreases.
Termination
For each matrix , let be the total amount subtracted from row of and the total amount added to column of . Then the matrix can be expressed as
Denote
with .
Lemma 3.5. If , then
Hence strictly increases when the algorithm has not yet terminated.
Proof. The correction step subtracts from the unmarked rows and adds to the marked columns. Therefore
Since and , we have . The assumption gives , and by Lemma 2.2, so the increment is at least 1.
Lemma 3.6 (Bounded potential). For every permutation in the symmetric group ,
Proof. From (1) and the non-negativity of we have for all . Fix and sum with :
Because is a bijection, , and the left-hand side is .
Proposition 3.7. If at some iteration, then must strictly increase after finitely many additional iterations.
Proof. Assume stays constant at forever after that iteration. Then by Lemma 3.5, the potential increases by at least 1 at each step and diverges to . But Lemma 3.6 gives a finite upper bound (take any permutation, say the identity), a contradiction. Hence cannot stay at indefinitely.
Theorem 3.8. For any non-negative integer matrix , Algorithm 1 terminates with a matrix satisfying .
Proof. After Phase 1, . Proposition 3.4 shows that never decreases. Proposition 3.7 shows that whenever is below , it must eventually rise. Since it can only take integer values bounded by , it reaches after finitely many steps.
Time bound
Let be the largest entry after Phase 1. Lemmas 3.5 and 3.6 give a crude pseudo-polynomial bound of iterations between successive increases of . This is sharpened to a strongly polynomial bound by implementing Phase 2 as the incremental Hungarian (Kőnig) iteration described above: the alternating tree, the matching , and a slack array over the tree frontier are maintained across corrections, so a single correction that exposes new zeros costs only amortised work and adds at least one new vertex to the tree. Consequently at most corrections occur between two augmentations, and there are at most augmentations in total. Each augmenting-path search therefore terminates in time, and the overall worst-case running time is . This is the classical tight bound of the Hungarian method (Kuhn [Kuh55]; see also Burkard, Dell’Amico & Martello [BDM12]) and is independent of the numerical magnitude .
Application 1: computing the genus of grid diagrams
A grid diagram of size places rows and columns of squares in the plane, with one “X” marker and one “O” marker in each row and each column. Connecting each X to the O in its column by a vertical segment and each O to the X in its row by a horizontal segment, with crossing information determined by the diagram, gives a knot diagram. We follow Cromwell [3] in defining the winding matrix of a grid diagram . This is an integer matrix whose first column and last row are identically zero. The matrix need not be non-negative. To apply the algorithm we first add column constants:
The algorithm then produces a matrix with . By König’s theorem, admits a permutation with for all . And this matrix is minimal non-negative matrix by [11 Lemma 3.4.2]. This permutation encodes a distinguished grid state.
The fact that can be read from any minimal non-negative matrix derived from , and that its value is independent of the choice of , is part of the grid-homology framework of Ozsváth–Stipsicz–Szabó [11]. In that work, the Euler characteristic , and hence the genus , as a function of the and the grid number ; then shows that , and therefore , is independent of the particular minimal non-negative matrix chosen. Our contribution is algorithmic: we show that the row–column reduction of Algorithm 1 produces exactly such a matrix from and computes the data needed for the formula in time.
Theorem 4.1 (Genus formula, Ozsváth–Stipsicz–Szabó). [11 Prop. 3.4.9] Let be a minimal non-negative matrix produced by Algorithm 1 and let be the grid number of . The Euler characteristic of the associated surface is
where is the invariant of defined in [11 Def. 3.4.8]: for each square marked with an X or an O in the grid, let be the average of the four matrix entries , , , adjoining (indices taken modulo on the torus), and set
Since is a connected orientable surface with one boundary component, ; therefore the genus of the grid diagram is
Example 4.2 (Trefoil knot). The grid diagram of the trefoil knot (, ) gives the winding matrix
Phase 1: All column minima and row minima are 0, so .
Phase 2: Zero positions:
, , , , , , , , , , , , .
Then we get that has the number 5 (e.g. , ). Hence the algorithm terminates immediately with . The permutation selects the zeros . Thus , hence the genus formula then gives . This is equal to Seifert genus of the trefoil. □
Example 4.3 (Conway knot). The grid diagram of Conway knot (, ) gives the winding matrix
Phase 1: First, get the non-negative matrix:
Phase 2: All column minima and row minima are 0, then .
Phase 3:
Zero positions:
, , , , , , , , , , , ,
, , , , , , , , , , , ,
, , , , , , , , , , , . Then we get has the number 10 (e.g. , ). Hence the algorithm continue, and we get . Thus it is obtained
Zero positions:
, , , , , , , , , , , ,
, , , , , , , , , , , ,
, , , , , , , , , , .
Then we get has the number 11 (e.g. , ). Hence the algorithm terminated with .
The permutation selects the zeros . Thus , then we get that
In the first example the algorithm terminates after Phase 1. As shown in Example 4.3, more complex diagrams require additional iterative updates, but the bounded potential argument and standard augmenting path techniques guarantee efficient eventual termination.
Application 2: Grid moves and the search for minimal genus of knot
Grid diagrams admit three types of elementary moves—commutation, stabilization, and destabilization—coined grid moves collectively (Definition 3.1.8 of [11]). Cromwell’s theorem [3] states that two planar grid diagrams represent equivalent links if and only if one can be transformed into the other by a finite sequence of grid moves [11]. Consequently, every grid diagram of a knot can be reached from any other diagram of the same knot by a suitable sequence of commutations, stabilizations and destabilizations.
Unlike the Seifert genus , which is a knot invariant, the quantity computed from a single grid diagram depends on the particular diagram chosen. Different grid diagrams representing the same knot may therefore yield different values of . The Seifert genus is recovered as the minimum over all diagrams:
Grid moves provide a mechanism for navigating the space of grid diagrams. In particular, destabilization can, in favourable cases, reduce and bring one closer to a genus-minimizing diagram. An analogous role is played by commutation, which permutes the markings without changing the grid size and can prepare a diagram for a subsequent destabilization. Together, they open the possibility of a descent algorithm that, starting from a given grid diagram of a knot , produces a sequence
with maybe decreasing genus (or equal, or increasing) at each step, and terminates at a diagram whose genus equals the Seifert genus .
Understanding how each type of grid move affects the winding matrix , and therefore the minimal non-negative matrix and the value , is an essential step towards realising such a descent algorithm. The analysis of these effects is the subject of ongoing work and will be presented in a subsequent paper. The present contribution provides the algebraic engine (Algorithm 1) that computes from in time, which forms a necessary building block for any move-based optimisation.
This raises a natural question: given a grid diagram , what features of its winding matrix determine whether a particular stabilization or commutation will increase, decrease, or leave unchanged genus ? We formulate this problem here and indicate a promising direction of investigation suggested by the algebraic machinery of Algorithm 1.
Let be an grid diagram and a stabilization of , so that is an grid diagram. Write and for the minimal non-negative matrices produced by Algorithm 1. The genus formula gives
Their difference is therefore
Thus increases by if and only if ; it stays the same precisely when .
Because is a sum of local averages of the entries of around each and marking, the change is controlled by how the new row and column inserted during stabilization affect these local averages. For a destabilization—the inverse operation—the sign is reversed, and one obtains a descent move precisely when .
We now consider the case as an example. Let be a grid diagram with grid number . After performing an stabilization on at an -marking , denote by the resulting grid diagram, which has grid number , as shown in Figure 2.
Figure 2.
The following example is about the knot . We can see that the genus increase 1 after the stabilization O:NW which occur at a given O-marking .
Example 5.1. The grid diagram of knot (, ) gives the following winding matrix
We will see that . Since , , and we get the associated genus
After the stabilization O:NW which occur at a given O-marking , we get a grid diagram (, ), and its winding matrix is
It is easy to see under the algorithm 1, then , and we get the associated genus
Acknowledgements
The author would like to thank Xiang Liu and Ziyi Liu at Hebei Normal University for discussions, and Xiaowei Pang for her encouragement. The project was funded by Science and Technology Project of Hebei Education Department (Grant No. QN2023030), Science Foundation of Hebei Normal University (Grant Nos. L2022B02, L2025ZD04).
Data availability
No data was used for the research described in the article.
Declaration
Python was used for the implementation of the algorithm.
AI was used for typesetting and grammar.
References
- [1]R. Burkard, M. Dell’Amico, and S. Martello. Assignment Problems. SIAM, Philadelphia, 2012.
- [2]P. R. Cromwell. Embedding knots and links in an open book I: Basic properties. Topology and its Applications, 64:37–58, 1995.DOI
- [3]P. R. Cromwell. Knots and Links. Cambridge University Press, 2004.DOI
- [4]I. A. Dynnikov. Arc-presentations of links: monotonic simplification. Fundamenta Mathemat-icae, 190:29–76, 2006.arxiv.org/abs/math/0208153
- [5]J. Hopcroft and R. Karp. An n⁵/² algorithm for maximum matchings in bipartite graphs. SIAM Journal on Computing, 2(4):225–231, 1973.
- [6]G. T. Jin and H. J. Lee. Minimal grid diagrams of 11 crossing prime alternating knots. Journal of Knot Theory and Its Ramifications, 29:1–14, 2020.DOI
- [7]H. W. Kuhn. The hungarian method for the assignment problem. Naval Research Logistics Quarterly, 2(1–2):83–97, 1955.
- [8]Marc Lackenby. A polynomial upper bound on reidemeister moves. annals of mathematics, 182:491–564, 2015.arxiv.org/abs/1302.0180
- [9]C. Manolescu, P. Ozsvath, and S. Sarkar. A combinatorial description of knot floer homology. Annals of Mathematics, 169:633–660, 2009.
- [10]C. Manolescu, P. Ozsvath, and D. Thurston. Grid diagrams and heegaard floer invariants. Annals of Mathematics, 201, 2025.arxiv.org/abs/0910.0078
- [11]P. Ozsvath, Stipsicz A., and Szabo Z. Grid Homology for Knots and Links. American Mathematical Society, 2015.DOI
- [12]C. H. Papadimitriou and K. Steiglitz. Combinatorial Optimization: Algorithms and Complexity. Prentice-Hall International, Inc., New Jersey, 1982.

