Papers
Topics
Authors
Recent
Search
2000 character limit reached

In-and-Out Algorithm: Cross-Domain Techniques

Updated 6 July 2026
  • 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 (u,v)(u,v)-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 QQ, 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 Q=(0,0)Q=(0,0), uses the positive xx-axis as the primary ray, skips vertices on the xx-axis, and replaces runs of such vertices by auxiliary edges between the nearest non-xx-axis vertices. When skipped vertices include at least one with positive xx-value, the intersection test is taken against the complete xx-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 xx-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-xx-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 QQ0 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 QQ1 to QQ2. 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 QQ3-pairs

In digraph theory, the in-and-out problem is the existence of an out-branching QQ4 rooted at QQ5 and an in-branching QQ6 rooted at QQ7 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 QQ8-pair is a pair QQ9 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 Q=(0,0)Q=(0,0)0 has a good Q=(0,0)Q=(0,0)1-pair if and only if, for every choice of Q=(0,0)Q=(0,0)2, there exist arc-disjoint paths Q=(0,0)Q=(0,0)3 and Q=(0,0)Q=(0,0)4, and Q=(0,0)Q=(0,0)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 Q=(0,0)Q=(0,0)6-arc-strong connectivity is especially favorable: strong spanning arc-decompositions and the existence of good Q=(0,0)Q=(0,0)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 Q=(0,0)Q=(0,0)8 by an arbitrary digraph Q=(0,0)Q=(0,0)9. This produces a significantly richer class, encompassing quasi-transitive digraphs through known decomposition theorems. The main result is again polynomial solvability for prescribed xx0: given a composition xx1, where xx2 is semicomplete or transitive, there is a polynomial algorithm deciding whether xx3 has a good xx4-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 xx5 of a graph xx6 so that the realized edges in xx7 contain an approximate maximum matching of the unknown random realization xx8. 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 xx9, the out-query set xx0 is the set of vertices for which at least one incident edge is discovered while computing the output for xx1. Dually, the in-query set xx2 is the set of vertices xx3 such that xx4. A correlated set xx5 consists of all vertices whose query explorations overlap with that of xx6. 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: xx7 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 xx8 independent realizations of xx9, compute a maximum matching in each, and output their union. The main theorem states that for every fixed xx0 and every xx1, every graph xx2 has a subgraph xx3 of maximum degree xx4 such that

xx5

Before this result, a xx6-approximation was known only with quasi-polynomial degree in xx7; the in-n-out framework removes that gap by making the necessary correlation control polynomial in xx8 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 xx9 accessible via a membership oracle. The target distribution is

xx0

Each proper step consists of two Gaussian moves. From the current point xx1, first sample

xx2

then sample

xx3

conditioned on xx4, implemented by rejection sampling. The chain can be interpreted as Gibbs sampling for the augmented density

xx5

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, xx6, xx7, and xx8. From an xx9-warm start, it reaches xx0 after

xx1

iterations, and in the isotropic case after

xx2

iterations, with corresponding expected membership-query bounds xx3 and xx4 (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).

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 xx5 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 xx6, it achieves xx7 time with xx8 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.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to In-and-Out Algorithm.