Collection Kit

SuffixTree

Tree

A SuffixTree is a compressed trie containing all the suffixes of a given string, allowing for fast substring queries and pattern matching.

Import Statement
import { SuffixTree } from "collection-kit";

Key Features

  • Efficient Substring Queries: Allows for quick searches of substrings.
  • Space Optimization: Compresses common prefixes to save space.

Common Operations

Insert
Add a new string to the suffix tree.
Search
Check if a substring exists in the tree.
Delete
Remove a substring from the tree.

Example Code

import { SuffixTree } from "collection-kit";

const suffixTree = new SuffixTree("banana");

console.log(suffixTree.search("ana"));    // true
console.log(suffixTree.search("nan"));    // true
console.log(suffixTree.search("apple"));  // false