A lightweight and efficient Trie (Prefix Tree) data structure implemented in TypeScript, suitable for applications like autocomplete, dictionary search, and prefix-based lookups.
- 🧠 Autocomplete based on prefixes
- ➕ Insert words efficiently
- 🔍 Search for complete words or prefixes
- 🧹 Clean and easy-to-read TypeScript code
- ✅ Minimal and extensible design
- 📄 Ready for integration in larger TypeScript applications
- Command or code suggestion tools
- Search engine prefix matching
- Spell checking or correction systems
- Efficient string matching for AI/NLP tools
Clone the repo and install dependencies:
git clone https://github.com/pujansrt/trie-ts.git
cd trie-ts
npm install
import { Trie } from './trie';
const trie = new Trie();
// Insert words
trie.insert("apple");
trie.insert("app");
trie.insert("ape");
// Search
console.log(trie.search("app")); // true
console.log(trie.search("apricot")); // false
// Autocomplete
console.log(trie.autoComplete("ap")); // ["apple", "app", "ape"]
Trie of 100,000 Unique words, it took 23 ms to retrieve one.
Contributions are welcome! Please open an issue or submit a pull request.
MIT License — free for personal and commercial use.
Developed and maintained by Pujan Srivastava, a mathematician and software engineer with 18+ years of programming experience.