AlgoScope

Suffix Array

Data structureadvancedString Structures

The starting indices of all suffixes, sorted; binary search finds substrings.

Decision · step 2 of 5Suffix Array: Binary search for a pattern
startsuffix0123455a3ana1anana0banana4na2nana

Rows 0 to 5 are still possible; the middle row 2 holds "anana" (start 1). "nan" sorts after it, so the block can only be below: search rows 3 to 5.

Open in the player →or start at step 2

What you will see

Suffixes listed and sorted; a binary search narrows the range that starts with the pattern.

How suffix array works →

Cost

buildO(n log n)
substring queryO(m 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, try operations in any order.

Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.

Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.

Leads to

Topics that need this one first.

Taught by the same lesson

Suffix Array covers these too, in the same run.