Loading

Quipoin Menu

Learn • Practice • Grow

data-structure-with-java / Trie Introduction
tutorial

Trie Introduction

Imagine you have a dictionary and you want to find all words starting with a prefix quickly. A trie (pronounced "try") is a tree data structure that stores strings, enabling fast prefix search. Each node represents a character, and paths from root to leaf form words. It's used in autocomplete, spell checkers, and IP routing.

A trie node typically contains:
  • An array of child nodes (size 26 for lowercase letters).
  • A boolean flag to mark if a node is the end of a word.

Java implementation of a TrieNode:


public class TrieNode {
TrieNode[] children = new TrieNode[26];
boolean isEndOfWord;
}
The root node is empty. Inserting a word walks down the tree, creating nodes as needed.
Two Minute Drill
  • Trie is a tree for storing strings with fast prefix search.
  • Each node has an array of children (26 for letters).
  • Path from root to node forms a prefix; a boolean marks word end.
  • Time O(L) for insert/search (L = word length).
  • Used in autocomplete, dictionary, pattern matching.

Need more clarification?

Drop us an email at career@quipoinfotech.com