LIS and network flow
This post discusses Longest Increasing Subsequence (LIS) and network flow problem.
Two Chains Problem
link Give a -permutation and a poset associated with it. That is, such that if and . Find two nonintersecting chains such that is maximized. Output .
Note that finding a maximal chain first and picking up another longest one does not work. For example, the array is . Then, the longest chain is , but the answer is .
Sol 1 - DP
Let denote the maximum size of two chain covering in such that the two chains end with and respectively. Here, to make math concepts reflect the program code, I use superscripts to represent the iteration of algorithm (i.e. loop variables) and subscripts for indices of arrays.
At the -th step, we try to pick to one of the chain, and let another chain remain . Thus, the best length is . Then we can update as:
Other cells do not change.
Note that we can use a segment tree to handle the second dimension of . Thus, the overall complexity is .
Sol 2 - Cost Flow
This problem can be reduced to a min-cost circulation problem as follows. Let node and denote the "source" and "destination". We need two chains, so add a flow with For each element , we build two nodes and for it. Add edges , , . Now we need to add edges among elements to represent the chain relationship.
The simplest solution is to add for all . However, this adds up to edges into the graph. Since is a partial order, we can use the transtivity to optimize the graph. That is, we only link to the antichain covering :
Add for all . To let a flow bypass a node, we can add one of the follows:
- for all ;
- for all .
In the worst case we can still have . For example, and . But this is more efficient in most cases, especially when chains are long, since any two elements that are connected must be neighbours in a saturated chain.
Two-Chain Covering Problem
Give and a saturated chain . Find two disjoint chains such that and the total length is maximized. Output a feasible pair of chains . Of course cost flow works. But the condition that is saturated gives us more chances.
This problem is proposed by me. I'm not sure whether there are more solutions if only the length is required. I think my DP is the best algorithm if we need the chains.
Sol 1 - DP
A naive thinking is letting and be another LIS. This is wrong of course, but we can improve it. (PS: a longer counter example is and , where needs to be broken into fragments.) Note that can be segmented into subsequences, where each segment is either in or . Suppose and , . For example, assume is in . Then, and are in : , . Thus, if we replace with in , will be still a chain. Based on this observation, consider interval-based dynamic programming (区間DP).
Let denote the maximal length when we only consider and where is . Let denote the how many element in we can choose to make a chain between and . Clearly, . Let for all s.t. in and for all not in . We know that and . Here the calculation of is costly, so we want to optimize it. Similar to the optimization used in cost flow, let be the antichain covering :
And we only need to consider those from :
If this algorithm can calculate in , the overall complexity will become . Well, it is false in some rare cases, but true most of the time.
is a graded poset. All are actually part of an antichain decomposition. Therefore, the time complexity is bound by and the worst case is
where and our algorithm is . However, the shorter is, the easier we can find another long chain.
Min-Cost Flow/Circulation Problem
Given a digraph with capacity function , cost function , supply-demand function A feasible flow is a function s.t. (capacity constraints) for all and (flow conservation) for all . In most of the cases, , , for all . In the circulation problem, for all .
Negative Circuit Condition
Given a feasible flow , define its residue network to be , where , with , , , . Then, is a min-cost flow if and only if there is no negative circuit with non-zero capacity in .
Proof: is clear, as we can always augment on a negative circuit to get a better flow.
To prove , suppose all circuits has a non-negative cost . Let be an arbitrary feasible circulation. Then, by flow conservation, is the sum of several circuits in : . Thus, .
Complementary Slackness Condition
The linear programming equiation is: (here denotes )
The first constraint can be written as , where is the incidence matrix. Recall that a digraph's incidence matrix is always totally unimodular, so the linear programming automatically gives an integer solution if , and are all integers.
Its dual programming is:
Recall how we write dual programming equations:
- Transpose the matrix, swap coefficients in the goal and right hand side in constraints.
- For every constraint in ( constraint in ), let the dual varible be non-negative.
- For every constraint, let the dual variable be free.
- For every non-negative variable, let the dual constraint be in ( in ).
- For every free variable, let the dual constraint be .
Look at the dual programming, observe that:
- the absolute values of (called potential) does not matter. Relative values make sense.
- Since all are positive, we can always take to get a optimized solution.
By the complementary slackness theorem, if and are feasible solutions to two programmings respectively, then they are optimal if and only if
Substitute for and get the the following condition: is a min-cost flow if and only if there exists a potential function s.t.
- for all
- for all
- Note:
- Some book uses so and are interchanged.
- When , we have .
- We can take if we want to calculate .
Let for all . Take a cycle with non-zero capacity from the residue network , sum the inequality up, and get:
which is exactly the negative circuit condition.
Feasible Tree Theorem
In simplex algorithm of linear programming, one jumps among vertices to get an optimal solution. Then, a natural problem is what a vertex means in a digraph. Consider the edges with in the residue graph. If there is a cycle , it must have zero cost. Thus, we can flow in either direction until the cycle breaks. This cycle is corresponding to a hyperplane perpendicular to the target, and the two directions give two optimal vertices. Suppose is weakly connected. Then, we only need to consider case that all non-tight arcs form a spanning tree.
A set of columns of the incidence matrix is a basis if and only if its arcs form a spanning tree.
Proof: Since is weakly connected, . Let denote a set of columns. If is a basis, then , which means there is no cycle in its arcs. Thus, it must be connected and a spanning tree. If is a spanning tree, then clearly . Thus, is a basis.
Pivoting in the (residue) network is:
- Select a non-tree edge such that the entering number .
- is calculated along the tree by setting the root .
- Augment through the cycle it makes until some edge is tight ( or )
- The augment amount is the minimum capacity of all edges on the cycle, which can be zero.
- Remove the tight edge and move the new edge in.
Similar to Bland Rule, one can prove that this algorithm does not fall into an infinite loop with some rules obeyed.
Fix a root node in a feasible tree. Call a feasible tree strong, if all degenerated edges with is pointing away from the root (and similarly edges that is pointing towards the root). A strong tree will only pivot into another strong tree. And if one always remove the first edge going from in pivoting, all strong trees will be different.
Greene-Kleitman Theorem
Let be an DAG, and . Then, for any collection of at most directed cuts , and any collection of any number of paths ,
where and .
- Here, a directed cut is all edges going out of a set into , , where and .
- Some books define S-T cut as , and , without requiring . The minimum S-T cut under this definition equals to the minimal directed cut.
Proof: To see :
because one path can intersect with each cut at most once.
The intersection property does not apply to S-T cut. For example, , , and . Then, the S-T cut contains 2 edges , and path passes both.
To prove equality, suppose has a single source and a single sink , and construct that make both sides equal.
Make a network , where is a copy of . Assign
- for
- for
Let be a min-cost circulation and be the negative of potential function such that . More specifically,
- for , with equality if .
- This ensures for all .
- For
- if
- if
- , with equality if the flow is not empty
Take as the collection of paths . The negative part of cost of (contributed by ) is exactly , and the positive part is . Thus, the right hand side of the equation is .
Note: Not clearly written in the book, but here we use the condition that is acyclic. Otherwise, may contain a cycle that does not pass and .
Take cuts as follows. For , let . Take as (at most) cuts. Since , for all , .
For all , if , then , so the original arc . That is, an arc in which is not in a path must be included in one of the cut (). Thus, .
On the other hand, for an arc in a cut, it may or may not be included in a path. ( for ) If it is included(), then must be on only exactly one path ( for ). Actually,
The last step comes from flow conservation and that a potential function sums up to on a circuit.
Thus,
For any collection of at most paths , and any collection of any number of directed cuts ,
where and .
Proof: Use the network we build before, but change the arc to , . Note that this is exactly what we do in the "Two Chains Problem". The rest of the proof is similar.
In a poset , the maximum size of the union of antichains is equal to:
where ranges over disjoint chain partitions.
Proof: Build the network as follows:
- , where is a copy of . Let and denote the the in and , respectively.
-
- Recall what we do in the "Two Chains Problem".
- Let . Apply the theorem above. For each arc , we take a singleton .
The maximum size of the union of chains is equal to:
where ranges over disjoint antichain partitions.
The difference of numbers of the union of chains & the union of antichains are conjugate partitions of .
RSK correspondence
Robinson-Schensted Bijection
Recall how we calculate LIS:
- Let be the least possible end of an increasing sequence of length , out of first elements.
- Initialize this sequence empty .
- When we move to , we try to replace the first element greater than from
- Suppose is the first such element, then and for .
- If is larger than all , append it to the last.
At last, the length of is the length of LIS. We call this operation "inserting into a row".
Now let us modify this algorithm a bit so no element are dropped:
- Initialize two empty standard Young tableaux .
- For to , insert into the first row of .
- If some element gets out, insert it into the next row; repeat this until no element is bumped out.
- At last, write in at the position we finish the insertion in .
It is easy to prove that are standard Young tableaux. Also, note that each step is invertible: we drop the largest element from , and pop the corresponding element in up. Thus, this algorithm gives a correspondence between a permutation and a pair of standard Yound tableaux of the same shape.
With proof omitted we have the following theorems:
- Row insertion and column insertion commute.
- The of the reversed sequence is the transpose.
- If enters at the -th column, then the longest increasing sequence ending at has length .
Knuth Correspondence
Knuth relation: Suppose we have . Swap with , and we will get . We can also do this reversely.
Two permutations are Knuth equivalent if one can be flipped to another with a sequence of Knuth relations.
Theorem: Two permutations are Knuth equivalent if and only if they share the tableaux.
k-LIS
Theorem: The longest total length of -increasing subsequences is the total size of first rows of .
- Let be the permutation concatenate the rows of bottom up. Clearly, the theorem is true for .
- It is proven that Kunth relations preserve -LIS.
References
- Igor Pak, UCLA MATH206A, Fall 2020.
- Alexander Schrijver, Combinatorial Optimization, Chapter 14, Springer, 2004.
- Bruce Sagan, The Symmetric Group, Second Ed., Chapter 3, Springer, 2000.