AlgoScope

Suffix Array Construction

AlgorithmadvancedString Matching

Sort suffixes by doubling the compared prefix length each round.

Decision · step 2 of 6Suffix Array: Prefix doubling: ranks by 1, 2, 4, 8 characters
k=1k=2k=4k=8k=160 b1 a2 n3 a4 n5 a102020

Positions 1 and 3 both rank 0 on their first 1 character. To rank them on 1 more, look 1 ahead: position 2 ranks 2 and position 4 ranks 2. Still tied; a later round will separate them, or they are equal to the end.

Open in the player →or start at step 2

What you will see

Suffixes re-sort in rounds of 1, 2, 4, ... characters; ranks update.

How suffix array works →

Cost

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Text and pattern cells announce index and character; each step announces the aligned positions, the comparison result and the shift.

Reduced motion: The pattern row snaps to its new alignment with a crossfade instead of sliding.

Taught by the same lesson

Suffix Array covers these too, in the same run.