Advanced maths

Minimum linear arrangement calculator from graph edges

Find an exact minimum-sum linear ordering of a small graph, with individual edge lengths and prefix-cut certificates.

Your numbers

Zero-based labels 0 through n−1, including isolated vertices.
One row: u v. No loops or duplicate unordered pairs.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Find an exact minimum-sum linear ordering of a small graph, with individual edge lengths and prefix-cut certificates.

THE FORMULAL(π)=Σ_{uv∈E}|pos_π(u)−pos_π(v)|=Σ_{k=1}^{n−1}|δ(S_k)|; F(S)=|δ(S)|+min_{v∈S}F(S\{v}).

A worked example

For the star with center 0 and leaves 1,2,3, order [1,0,2,3] has edge lengths 1,1,2 and total 4. Its prefix cuts 1,2,1 also sum to 4.

Good to know

Simple undirected unweighted graphs on 1–12 vertices. Exact subset dynamic programming over all 2^n states. One optimal order, not all ties. Consecutive equally spaced slots; no weights, pinned positions, directed costs or geometric routing constraints.

Minimize total connection length

A linear arrangement places every graph vertex in a distinct position on a line. Each edge contributes the absolute difference between its endpoint positions. The objective adds those contributions, so a layout with one long edge can still beat another layout that has many moderately long edges.

This sum objective differs from bandwidth, which cares only about the longest edge, and from cutwidth, which cares about the largest number of edges crossing one prefix cut. The same graph can have different best arrangements for these three criteria. Choose this page when total connection length is the intended quantity.

For the star with center 0 and leaves 1,2,3, order [1,0,2,3] has edge lengths 1,1,2 and total 41023slot 0slot 1slot 2slot 3Edge lengths 1 + 1 + 2 = 4
Scroll across to see the full diagram.
For the star with center 0 and leaves 1,2,3, order [1,0,2,3] has edge lengths 1,1,2 and total 4. Its prefix cuts 1,2,1 also sum to 4.

Compare this with the Graph bandwidth calculator with optimal vertex ordering. Minimize the sum of edge endpoint separations; bandwidth minimizes only the largest separation.

Keep labels separate from positions

The input labels identify vertices; they are not fixed coordinates. A result ordering such as [1,0,2,3] means vertex one is placed first, vertex zero second, vertex two third and vertex three fourth. Positions are consecutive integers, starting at zero in the displayed certificate.

Adding the same constant to every position would leave all edge lengths unchanged. Empty gaps are not useful for this unweighted objective, so the optimization uses consecutive slots. The declared vertex count includes isolated vertices, and the calculator preserves them rather than silently removing them from the ordering problem.

The prefix-cut identity

Consider a particular edge whose endpoints occupy positions i and j, with i smaller than j. It crosses exactly the j minus i prefix boundaries between those slots. Summing the number of crossing edges over every boundary therefore counts that edge exactly as many times as its length.

This identity allows a subset dynamic program. For a prefix set S, its cut size depends only on which vertices are inside S, not on their order. The recurrence takes the best smaller prefix and adds the cut of the new prefix. The full-set cut is zero, so it adds no extra length at the end.

Work through the four-vertex star

The default graph has center zero and leaves one, two and three. Placing the center at an endpoint gives edge lengths one, two and three, totaling six. Moving it into an interior slot reduces the unavoidable farthest leaf distance without lengthening every other connection.

The returned optimum is four. For ordering [1,0,2,3], the three edge lengths are one, one and two. The successive prefix cuts contain one, two and one crossing edges, which also sum to four. Either calculation reproduces the objective without relying on the dynamic-program table.

Use the certificate rather than the label order

The result includes a full ordering, a position for each original label and an edge-by-edge length table. These outputs let you distinguish the input numbering from the optimized layout and check whether every declared vertex occurs once. Reversing an arrangement preserves its total cost.

Several arrangements may attain the same minimum. This calculator returns one witness and does not claim to enumerate all of them. If a downstream application requires a special tie-break, fixed endpoint or fixed position, that extra requirement changes the feasible set and is not implied by the chosen witness.

Exact scope and exponential growth

The graph is simple, undirected and unweighted, with at most twelve vertices. The algorithm completes all subset states rather than sampling random orders. At the maximum size there are 4,096 subsets, making exact optimization practical while keeping the browser workload predictable.

Weights, prescribed positions, directed edge costs and layouts with multiple dimensions require different objective bookkeeping. Entering a third number on an edge row is rejected instead of interpreted as a weight. No inference about an unrestricted large instance follows from the small-instance bound, and the result does not optimize geometric coordinates supplied elsewhere.

Compare layouts on a fair basis

When comparing two candidate layouts manually, use the same vertex set and the same consecutive slot spacing. Omitting an isolated vertex or changing the slot unit can alter the reported numerical sum even though the connection pattern looks similar. The calculator reports dimensionless slot distances.

For a physical application, multiply the optimum by a fixed slot pitch only when every edge cost is proportional to that pitch. Congestion, routing obstacles and differently priced edges can break that simple interpretation. The mathematical optimum is a useful baseline for the stated graph objective, not a complete placement solution for all engineering constraints.

A few questions, answered

Is this the same as graph bandwidth?

No. Linear arrangement minimizes the sum of edge lengths, while bandwidth minimizes only the largest edge length.

Why do prefix cuts reproduce the length sum?

An edge contributes to exactly the prefix boundaries between its two positions, once for each unit of its length.

Can several orderings be optimal?

Yes. Reversal preserves all lengths, and additional ties can occur; this calculator returns one checked optimum.

Can I enter weighted edges?

No. Each accepted edge has two endpoints and unit contribution per slot; weighted layout needs a different objective.

Find your calculator

Start typing to explore the library.