In-and-Out Algorithm: Cross-Domain Techniques
- The in-and-out algorithm is a collection of methods that alternate between local excursions and global decision steps across various domains.
- It applies in computational geometry for parity tests, in digraph theory for arc-disjoint branchings, and in stochastic matching through efficient local computation.
- These frameworks offer practical insights with polynomial-time guarantees and improved complexity in areas like convex-body sampling and randomized matching.
Searching arXiv for recent and directly relevant papers on “In-and-Out” terminology and algorithms across the domains represented in the source material. arXiv search: query = "In-and-Out Algorithm OR In-n-Out OR point in polygon even-odd semicomplete digraph out-branching in-branching stochastic matching convex bodies" “In-and-Out Algorithm” does not denote a single canonical procedure across the literature. Rather, the label is used for several technically distinct algorithmic patterns organized around an alternation between entering a local structure and exiting with a classification, branching, sample, or local certificate. In computational geometry it is closely associated with the even–odd rule for point-in-polygon queries; in directed graph theory it describes the search for an out-branching arc-disjoint from an in-branching; in stochastic matching it appears as “in-n-out” local computation; and in convex-body sampling it names a specific Gaussian forward/backward Markov chain with uniform stationary distribution on a convex body (Galetzka et al., 2012, Bang-Jensen et al., 2023, Azarmehr et al., 2024, Kook et al., 2024).
1. Terminological scope
The term is best read as a family of domain-specific meanings rather than as the name of one universally standardized algorithmic object. The usages represented in the literature are summarized below.
| Domain | Meaning of “in-and-out” | Representative paper |
|---|---|---|
| Point-in-polygon | Even–odd parity rule: boundary crossings toggle inside/outside | (Galetzka et al., 2012) |
| Convex polygons | Perpendicular-based in/out judgment reduced to a quadrilateral | (Yixuan et al., 2022) |
| Semicomplete digraphs | Arc-disjoint out-branching and in-branching with prescribed roots | (Bang-Jensen et al., 2023) |
| Semicomplete compositions | Polynomial construction or certification of good -pairs | (Bang-Jensen et al., 2023) |
| Stochastic matching | “In-n-out” LCAs with bounded in-queries and out-queries | (Azarmehr et al., 2024) |
| Convex-body sampling | Two-step Gaussian walk with rejection-conditioned return to the body | (Kook et al., 2024) |
A useful unifying observation is that all of these formulations alternate between a local excursion and a global decision rule. In geometry, a ray crosses a boundary and parity toggles. In digraph theory, an outward-oriented spanning structure is paired with an inward-oriented one. In local computation, outward probes and inward dependencies are jointly controlled. In sampling, a point diffuses outward into ambient space and is then drawn back into the feasible region. This suggests a recurrent conceptual motif, but not a single shared formalism.
2. Geometric uses: parity rules and convex-polygon localization
In computational geometry, the phrase “in-and-out” most directly refers to the classical even–odd rule for the point-in-polygon problem. A ray is cast from the query point , the number of polygon-edge intersections is counted, and the point is classified as inside when the count is odd and outside when it is even. The 2012 treatment formalizes this rule for arbitrary polygons, including complex polygons whose edges intersect each other creating holes, and proves correctness in linear time. Boundary points are treated as inside. The algorithm translates the polygon so that , uses the positive -axis as the primary ray, skips vertices on the -axis, and replaces runs of such vertices by auxiliary edges between the nearest non--axis vertices. When skipped vertices include at least one with positive -value, the intersection test is taken against the complete -axis rather than only its positive part, which preserves the correct parity in degenerate configurations (Galetzka et al., 2012).
The same literature distinguishes simple polygons from complex polygons and emphasizes that self-intersections, holes, overlapping regions, vertices on the ray, and edges lying on the ray are precisely the configurations that make naive implementations error-prone. The robust formulation avoids double counting by ensuring that every counted edge either clearly intersects the -axis or clearly does not. Its correctness proof combines the general correctness of even–odd classification with a case analysis showing that auxiliary edges preserve the desired parity for all possible quadrant configurations of the non--axis endpoints (Galetzka et al., 2012).
A different geometric use appears in work specialized to simple convex polygons. There, the in/out decision is organized around a perpendicular from the query point 0 to the line through a chosen edge, a test against the segment connecting the outer points of the neighboring edges, and a reduction of the global problem to a point-in-quadrilateral test decided by a standard ray algorithm. The method is explicitly designed for simple convex polygons, not general non-convex or self-intersecting polygons, and its reported complexity ranges from 1 to 2. The paper states that the algorithm has fewer intersections and greatly improves the efficiency of the judgment (Yixuan et al., 2022).
3. Directed graphs: out-branchings, in-branchings, and good 3-pairs
In digraph theory, the in-and-out problem is the existence of an out-branching 4 rooted at 5 and an in-branching 6 rooted at 7 that are arc-disjoint. An out-branching is a connected spanning subdigraph in which every vertex except the root has in-degree one; dually, an in-branching is a connected spanning subdigraph in which every vertex except the root has out-degree one. A good 8-pair is a pair 9 with no arc in common. The general decision problem is sharply harder than the classical problem of finding many out-branchings of the same orientation: it is already NP-complete to decide whether a digraph has one out-branching arc-disjoint from some in-branching (Bang-Jensen et al., 2023).
For semicomplete digraphs, however, the structure becomes tractable. A complete characterization states that a semicomplete digraph 0 has a good 1-pair if and only if, for every choice of 2, there exist arc-disjoint paths 3 and 4, and 5 is not isomorphic to any of a fixed list of five small exceptional digraphs. The proof is constructive and yields a polynomial algorithm that either finds the two branchings or certifies that no such pair exists. The same work shows that for semicomplete digraphs the case of 6-arc-strong connectivity is especially favorable: strong spanning arc-decompositions and the existence of good 7-pairs align in a way that confirms a conjecture of Bang-Jensen for this class (Bang-Jensen et al., 2023).
The 2023 extension to semicomplete compositions replaces each vertex of a semicomplete digraph 8 by an arbitrary digraph 9. This produces a significantly richer class, encompassing quasi-transitive digraphs through known decomposition theorems. The main result is again polynomial solvability for prescribed 0: given a composition 1, where 2 is semicomplete or transitive, there is a polynomial algorithm deciding whether 3 has a good 4-pair and outputting one when it exists. In particular, the result implies polynomial-time solvability for quasi-transitive digraphs and confirms a conjecture of Bang-Jensen and Gutin from 1998 (Bang-Jensen et al., 2023).
4. “In-n-out” local computation in stochastic matching
In stochastic matching, the phrase is used in a more specialized form: “in-n-out LCAs.” The underlying problem is to choose, non-adaptively, a sparse subgraph 5 of a graph 6 so that the realized edges in 7 contain an approximate maximum matching of the unknown random realization 8. The conceptual contribution is to connect local computation algorithms to stochastic matching for the first time and to refine the LCA model by simultaneously bounding two dual notions: out-queries and in-queries (Azarmehr et al., 2024).
For a queried vertex 9, the out-query set 0 is the set of vertices for which at least one incident edge is discovered while computing the output for 1. Dually, the in-query set 2 is the set of vertices 3 such that 4. A correlated set 5 consists of all vertices whose query explorations overlap with that of 6. For natural LCAs, whose discovered prefixes always induce connected subgraphs, bounded expected in-queries and bounded expected out-queries imply bounded expected correlated-set size: 7 This is the technical form of “in-n-out”: local computation with bounded outward exploration and bounded inward dependence (Azarmehr et al., 2024).
The stochastic matching application uses this limited-correlation property to control the dependence structure of random matching decisions. The global construction of the sparse queried subgraph is simple: sample 8 independent realizations of 9, compute a maximum matching in each, and output their union. The main theorem states that for every fixed 0 and every 1, every graph 2 has a subgraph 3 of maximum degree 4 such that
5
Before this result, a 6-approximation was known only with quasi-polynomial degree in 7; the in-n-out framework removes that gap by making the necessary correlation control polynomial in 8 rather than quasi-polynomial (Azarmehr et al., 2024).
A recurring clarification in this line of work is terminological: “in-n-out” refers only to the dual bounds on in-queries and out-queries. It is not related to geometric in/out tests, queueing systems, or input/output throughput (Azarmehr et al., 2024).
5. Convex-body sampling: the specific “In-and-Out” random walk
A distinct and explicit usage appears in high-dimensional sampling. Here “In-and-Out” is the name of a Markov chain for approximately uniform sampling from a convex body 9 accessible via a membership oracle. The target distribution is
0
Each proper step consists of two Gaussian moves. From the current point 1, first sample
2
then sample
3
conditioned on 4, implemented by rejection sampling. The chain can be interpreted as Gibbs sampling for the augmented density
5
and also as the composition of a forward heat flow and a backward heat flow (Kook et al., 2024).
The algorithm achieves state-of-the-art runtime complexity with stronger guarantees on the output than previously known, namely in Rényi divergence, which implies total variation, 6, 7, and 8. From an 9-warm start, it reaches 0 after
1
iterations, and in the isotropic case after
2
iterations, with corresponding expected membership-query bounds 3 and 4 (Kook et al., 2024).
The proof departs from conductance-based analyses of Ball walk and Speedy walk. Instead, convergence is derived from a stochastic diffusion perspective: contraction toward the target is governed by the Poincaré and log-Sobolev constants of the stationary distribution. This makes the algorithm notable not only as a sampling routine but also as a bridge between oracle-based convex-body sampling and diffusion-based functional-inequality analysis (Kook et al., 2024).
6. Cross-cutting structure, distinctions, and related usage
Despite the shared label, these algorithms solve different problems on different state spaces. The geometric parity rule is a classification procedure on planar embeddings. The digraph formulations are spanning-structure packing problems in directed graphs. The in-n-out LCA framework is a dependence-control principle for local randomized algorithms. The convex-body sampler is a Markov chain on 5 with rejection-conditioned Gaussian updates. Confusing these meanings obscures the fact that they share terminology but not a common operational core.
A common misconception is that “in-and-out” always means the same kind of boundary test. That is accurate for the even–odd point-in-polygon rule, where every boundary crossing toggles between outside and inside (Galetzka et al., 2012). It is inaccurate for the digraph and stochastic-matching usages, where “in” and “out” refer to opposite arc orientations or to inward and outward query incidence (Bang-Jensen et al., 2023, Azarmehr et al., 2024). It is likewise inaccurate for convex-body sampling, where the name refers to an outward Gaussian diffusion followed by a return step conditioned on re-entering the body (Kook et al., 2024).
A related but looser descriptive use appears in deterministic in-place permutation inversion. One exposition states that the 2019 algorithm does not explicitly use the phrase “In-and-Out Algorithm,” but its control structure repeatedly goes into the permutation’s functional graph from local starting points, performs local restructuring through procedures such as Tortoise-and-Hare, Make-Segments, and Restore-Long-Cycle, and returns to global scans. Under the strict requirement that every array entry remain in 6, it achieves 7 time with 8 bits of additional memory (Guśpiel, 2019).
This suggests a broader interpretive pattern: “in-and-out” recurrently names algorithms that alternate between a global traversal and a local excursion whose outcome can be encoded compactly enough to support a global decision, update, or certificate. That interpretation is descriptive rather than formal, but it captures why the same phrase recurs across computational geometry, digraph theory, local computation, sampling, and related algorithmic constructions.