---
id: suffix-array
title: "Suffix Array"
author: Benjamin Qi
description: "Quickly Sorting Suffixes of a String (and Applications)"
prerequisites:
 - Gold - Hashing
frequency: 1
---

import { Problem } from "../models";

export const metadata = {
  problems: {
    sample: [
      new Problem("YS", "Suffix Array", "suffixarray", "Easy", false, [], ""),
    ],
    lcpSam: [
      new Problem("YS", "# of Substrings", "number_of_substrings", "Easy", false, [], ""),
    ],
    lcp: [
      new Problem("Plat", "Standing Out from the Herd", "768", "Hard", false, [], ""),
      new Problem("CF", "Two Prefixes", "contest/1090/problem/J", "Hard", false, [], ""),
    ],
    burSam: [
      new Problem("CSES", "String Transform", "1113", "Easy", false, [], ""),
    ],
    runSam: [
      new Problem("YS", "Run Enumerate", "runenumerate", "Hard", false, [], ""),
    ]
  }
};

## Resources

<resources>
  <resource source="CF" title="Suffix Array" url="edu/course/2/lesson/2" starred>Videos & Practice Problems</resource>
  <resource source="cp-algo" title="Suffix Array - Definition & Construction" url="suffix-array.html" starred></resource>
  <resource source="CPC" title="11 - Strings (Suffix Array)" url="11_strings"></resource>
</resources>

## Suffix Array

<problems-list problems={metadata.problems.sample} />

### Implementations

<resources>
  <resource source="Benq" title="Suffix Array w/ LCP" url="https://github.com/bqi343/USACO/blob/master/Implementations/content/strings%20(14)/Light/SuffixArray%20(14.4).h">$O(N\log N)$</resource>
</resources>

(recommend that you also test against brute force for many small strings)

## LCP Array

<problems-list problems={metadata.problems.lcpSam} />

Quickly compute longest common prefix of two suffixes.

<problems-list problems={metadata.problems.lcp} />

## Inverse Burrows-Wheeler

<resources>
  <resource source="GFG" title="Inverting Burrows-Wheeler Transform" url="inverting-burrows-wheeler-transform">could be simpler?</resource>
</resources>

CSES Guide?

<problems-list problems={metadata.problems.burSam} />

## Run Enumerate

<resources>
  <resource source="cp-algo" title="Finding repetitions" url="main_lorentz.html">could be simpler?</resource>
</resources>

(describe how to do easily w/ suffix array)

<problems-list problems={metadata.problems.runSam} />

