DSAVisualiseData Structures & Algorithms Studio
Paths & Grids Hard

Weighted Graph: Substring Reversal

Each move reverses a substring of at least two UTF-16 units; Dijkstra minimizes the sum of substring lengths.

Trace input

Bounded JSON

Edit the lesson input, then build a deterministic source-linked trace.

This lesson validates its own input and operation limits.

Source scenarios

Complexity

BestO(S² log S)
AverageO(S² log S)
WorstO(S² log S)
SpaceO(S)

Array state

Follow the active comparisons and writes.

Live snapshot

Current operation

Trace state
Ready to explore
Source behavior & common mistakes

Find the minimum cost and a matching sequence of intermediate words. This is substring reversal, not single-letter substitution.

  • Using a word-ladder graph of one-letter changes.
  • Allowing a one-character substring reversal.
  • Charging a constant cost instead of the substring length.

Algorithm code

Java
WordTransformationSP.javaStep linked
The highlighted line follows the current step.

Ready to begin

Press Play to see what happens.

Detailed execution
Snapshot 1 / 1