Advanced maths

Signed permutation reversal distance calculator with a shortest sorting sequence

Find minimum interval reversals that also flip every sign within the reversed interval.

Your numbers

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 minimum interval reversals that also flip every sign within the reversed interval. Adjacent token swaps move endpoints and preserve sign; the state graph and optimization problem differ.

THE FORMULAρᵢⱼ(p)=(p₀,…,pᵢ₋₁,−pⱼ,−pⱼ₋₁,…,−pᵢ,pⱼ₊₁,…); d=min number of reversals to target.

A worked example

The signed permutation [−3,−2,−1] reaches [1,2,3] in one reversal of the full interval [0,2]. Reversing the order and flipping all three signs are both required.

Good to know

Signed permutation of 1..n, n≤6, target identity or another same-label signed permutation. At most 2^6·6!=46,080 states and ≤1 million generated transitions per search; shortest sequence only after complete BFS.

Signed permutation conventions

A signed permutation contains each absolute label from 1 through n exactly once. The sign records orientation, so +2 and −2 represent the same labeled item with opposite direction.

The target must use the same absolute labels. Missing labels, repeated absolute values and zero are invalid because they do not represent states in the signed-permutation reversal model.

Signed permutation reversal distance calculator with a shortest sorting sequence worked exampleReverse [0,2] and flip each sign-3-2-1123one signed reversalDistance = 1
Scroll across to see the full diagram.
The signed permutation [−3,−2,−1] reaches [1,2,3] in one reversal of the full interval [0,2]. Reversing the order and flipping all three signs are both required.

Compare this with the Minimum token swapping calculator with an adjacent swap sequence. Find minimum interval reversals that also flip every sign within the reversed interval. Adjacent token swaps move endpoints and preserve sign; the state graph and optimization problem differ.

Interval reversal and sign flips

A reversal selects one consecutive interval, reverses its item order and flips every sign inside it. Items outside the interval remain unchanged. Even a length-one interval is a legal orientation flip.

This move differs from swapping adjacent tokens. It also differs from an unsigned reversal that changes order without sign changes, so the reported distance depends on retaining the signed rule exactly. Reversing the entire default signed permutation [−3,−2,−1] produces [1,2,3] in one move: both order and signs change. Omitting the sign flip would solve a different sorting problem. Move endpoints are zero-based and inclusive, so [0,2] touches three positions. A one-position reversal is permitted and flips that single sign. The displayed trace lets you reproduce each move on the original vector, rather than trusting only a reported minimum length.

Target normalization

The shortest sorting sequence is a path in the finite graph of signed permutations. Each allowed interval reversal supplies an edge, and every edge has cost one.

Breadth-first or bidirectional breadth-first search establishes a shortest path when the search completes. The bounded initial implementation uses this exact small-state computation rather than claiming a large-instance polynomial algorithm.

Exact shortest-path search

An arbitrary signed target can be normalized to the positive identity by relabeling and orienting each item consistently with its target occurrence. Apply that same normalization to the starting permutation.

The resulting move indices still refer to positions. A certificate must replay the chosen interval reversals on the original state and reach the original target, independent of internal normalization. Breadth-first search explores signed permutation states in nondecreasing move count. The first target discovery therefore supplies a shortest sequence, provided the search completes within the work limit. At length six the state universe has2^6×6!=46,080 possible states, although a particular search may visit fewer before finding the target. This bounded exhaustive method prioritizes a transparent shortest-path certificate; it is not an implementation of the more elaborate polynomial-time signed-reversal-distance algorithms used on much larger instances.

Reading the move certificate

For [−3,−2,−1], reversing positions 0 through 2 first changes the order to [−1,−2,−3] and then flips signs to [1,2,3]. This proves an upper bound of one.

The input is not already the target, so zero moves are impossible. Together these observations prove distance one without any exhaustive search, making the example a useful basic correctness fixture.

Worked multi-move sorting example

The illustration draws signed blocks before and after one interval reversal. Read the sign and the position independently; a reversed strip with unchanged signs would depict the wrong operation.

For a returned multi-move certificate, check every intermediate state. Its move count must match the reported distance, while shortestness comes from the completed search rather than merely from successful replay. Changing the target to another same-label signed permutation is supported on the same page rather than counted as a new calculator. Labels must occur exactly once by absolute value. Duplicate genes, unsigned permutations interpreted as hidden signs and circular-genome equivalence require different state spaces. A cap error means a shortest sequence was not established; a partial path must not be relabeled as an optimum just because it reaches the target eventually.

Small-state limits and genome-model exclusions

There are 2^n n! signed states, which explains the deliberately small input bound. Search-state and transition limits must be reported as unresolved if they interrupt optimality certification.

The model preserves item labels and count throughout. Insertions, deletions, duplications and chromosome translocations are not allowed moves, so the distance is a mathematical reversal distance rather than a general biological divergence estimate.

A few questions, answered

Does reversing also flip signs?

Yes. Every sign inside the chosen interval flips as the order reverses.

Can a single element be reversed?

Yes. A length-one reversal flips that item’s orientation.

Is this adjacent-swap distance?

No. Adjacent swaps use different moves and preserve signs unless another rule is added.

Does this model insertions or chromosome translocations?

No. The allowed operation is only a signed reversal of one interval.

Find your calculator

Start typing to explore the library.