Prefix Operations and Tries

10/16/2020

Tries

Abstract Data Types vs. Specific Implementations

BST and Hash Table Set Runtimes

Special Case 1: Character Keyed Map

public class DataIndexedCharMap<V> { private V[] items; public DataIndexedCharMap(int R) { items = (V[]) new Object[R]; } public void put(char c, V val) { items[c] = val; } public V get(char c) { return items[c]; } }

Special Case 2: String Keyed Map

Sets of Strings

Tries: Search Hits and Misses

Trie Maps

Tries

Trie Implementation and Performance

Very Basic Trie Implementation

public class TrieSet { private static final int R = 128; // ASCII private Node root; // root of trie private static class Node { private char ch; // Actually don't need this variable private boolean isKey; private DataIndexedCharMap next; private Node(char c, boolean b, int R) { ch = c; isKey = b; next = new DataIndexedCharMap<Node>(R); } } }

Trie Performance in Terms of N

Alternate Child Tracking Strategies

DataIndexedCharMap Trie

Alternate Idea #1: The Hash-Table Based Trie

Alternate Idea #2: The BST-Based Trie

The Three Trie Implementations

Performance of the DataIndexedCharMap, BST, and Hash Table

Trie Performance in Terms of N

Trie String Operations

String Specific Operations

Collecting Trie Keys

Usages of Tries

Autocomplete

The Autocomplete Problem

A More Efficient Autocomplete

Even More Efficient Autocomplete

Trie Summary

Tries

Domain Specific Sets and Maps

Discussion Summary: Tries