Bölüm 5 · Simülatör

Trie, Suffix Array & Suffix Trie Basics

← Bölüm 5

Trie

Ready.

Trie, Suffix Array & Suffix Trie Basics

Build a trie from words, inspect prefix queries, and compare suffix-array ordering with suffix-trie storage.

How to use

  • Trie: enter comma-separated words (up to 10 words, 12 letters each) and a prefix, then press Build / Search Prefix. The search path is highlighted; filled nodes mark the end of a word.
  • Suffix: enter a text of up to 16 characters and press Build Suffix Structures. The suffix array is listed on the left and the naive suffix trie is drawn on the right.
  • Click a row of the suffix array to highlight that suffix's path in the suffix trie. Enter in an input field also rebuilds.

Trie

Each edge stores one character; all words with a common prefix share the same path from the root. A prefix query walks down at most |p| edges, so it takes O(|p|) time regardless of how many words are stored.

Suffix array and LCP

Suffix arrays keep sorted suffix starting positions. The LCP column gives the length of the longest common prefix of a suffix and the one before it in sorted order. Suffixes are compared character by character (code-point order).

Suffix trie

The suffix trie stores every suffix as a path from the root; a naive suffix trie can require O(n²) space. A filled node marks the end of a suffix. Suffix trees compress single-child chains to reach O(n) space.

Complexity

StructureBuildSpaceQuery
TrieO(total length)O(total length)O(|p|)
Suffix array (naive sort)O(n² log n)O(n)O(|p| log n)
Suffix trie (naive)O(n²)O(n²)O(|p|)