TL;DR
This paper explores efficient in-memory data structures for indexing n-grams, crucial for tasks like plagiarism detection and DNA sequence comparison. The authors propose and evaluate several structures, highlighting the ternary search tree (TST) and introducing optimizations to improve its performance, particularly for large datasets.
What Problem Does This Paper Address?
Indexing and searching through large collections of n-grams (sequences of words or characters) presents a significant computational challenge. Applications like plagiarism detection, spam filtering, and bioinformatics (e.g., DNA sequence analysis) rely on efficiently finding patterns within massive text datasets. Traditional data structures can become prohibitively slow and memory-intensive when dealing with gigabytes of n-gram data. The core problem is to find data structures that offer fast search times while minimizing memory footprint, especially when dealing with the sheer volume of data encountered in real-world applications.
Methods
The paper investigates several data structures for n-gram indexing:
- Hash Tables: Explored for their potential speed, but with considerations for hash collisions and potential reallocation overhead.
- B+ Trees: A standard choice for disk-based indexing, evaluated for its in-memory performance.
- Ternary Search Trees (TSTs): The paper focuses heavily on TSTs, describing their structure and how they can be used for n-gram indexing. They propose two key improvements:
- Hybrid AVL Tree: Combining TSTs with self-balancing AVL tree properties to mitigate performance degradation from unbalanced trees.
- Double Ternary Search AVL Tree: A novel approach that separates indexing of individual words from the n-grams themselves. This involves two TSTs: one for mapping words to unique numerical IDs and another for indexing these IDs to form n-grams. This aims to reduce redundancy and improve efficiency.
Datasets
The paper uses collections of n-grams for testing. Specifically, they mention using:
- WebIT 5-gram corpus: A large dataset containing over 88GB of data, from unigrams to 5-grams.
- PROTEIN-10M, PROTEIN-100M, and PROTEIN-1G: Datasets used in prior work for demonstrating double indexing.
- Google WebIT and English Gigaword corpus: Used to show the speed of TSTs.
- 3-grams²: A collection derived from "Random lines extracted from Web 1T 5-gram, 10 European Languages Version 1 collection" to analyze the depth of binary trees within TSTs.
- 1,000,000 n-grams: A specific collection size used for the main comparison tests, with sub-collections for 2-grams, 3-grams, 4-grams, and 5-grams.
Key Insights and Ideas
- TSTs are promising but can be unbalanced: While TSTs are conceptually well-suited for n-grams, their performance can suffer if the tree becomes unbalanced, leading to search times closer to linear.
- Self-balancing is crucial: Integrating self-balancing mechanisms (like AVL properties) into TSTs significantly improves their robustness and search performance, especially with unordered data.
- Separating word and n-gram indexing is key for space efficiency: The "Double Ternary Search AVL Tree" approach, which first indexes individual words and then uses these indices to build n-grams, dramatically reduces memory consumption. This is because common words are only stored once.
- Hash tables excel at raw search speed but lack wildcard support: For exact matching, hash tables offer the fastest search times, but they are not well-suited for queries involving wildcard characters.
- N-gram size impacts performance: As n-gram size increases, the performance differences between data structures become more pronounced, particularly for insertion and search times.
Key Results
- Insertion Time: Ternary tree data structures (including hybrid and double variants) showed significantly longer insertion times compared to hash tables and B+ trees, potentially due to balancing operations.
- Search Time: Hash tables generally provided the best search performance for exact matches. Hybrid AVL trees offered up to 29% better search speed than standard TSTs, and Double Hybrid AVL trees achieved up to 40% better speed than Double Ternary AVL trees, with comparable results to B+ trees. B+ tree search time increased significantly with n-gram size.
- Memory Consumption: Ternary AVL trees and Hybrid AVL trees showed high memory requirements, especially for larger n-grams. The Double Ternary AVL tree demonstrated significantly lower memory consumption (about 40% smaller than hash tables and B+ trees). The paper also notes that separate indexing of words and n-grams reduced the space complexity of 5-grams to 25% of the original ternary tree's requirement.
Limitations and Future Work
- Limitations:
- The paper acknowledges that the "huge difference" in insertion times for ternary trees might be improved by using other self-balanced trees like red-black trees.
- Hash table reallocation overhead, though stated as negligible, can still impact performance.
- The B+ tree's search time increase with n-gram size is noted as a potential issue.
- Future Work:
- Further research into data structures for indexing words and n-grams separately.
- Testing data structures that support wildcard searches.
- Exploring data structures for indexing multidimensional data.
- Investigating other self-balanced tree types (e.g., red-black trees) for ternary tree implementations.
Summary updated