Computer Algorithms II Lecture Notes

18 December 2007 • Tries


Outline

A Problem

Solutions

Analysis

Digit Indexing

So What?

N-ary Trees

Tries

Trie Search

Find'

(node, node, int) 
find'(parent, root, key, dno)

  if root = nil
    return (parent, root, dno)

  if root isa data-node
    return (parent, 
            root.data = key ? root : nil, 
            dno)

  return find'(root, 
               root.children[key[dno]], 
               key, 
               dno + 1)

Find

Trie Insertion

Insert


insert(root, key)

  (parent, root, dno) = 
    find'(nil, root, key, 0)

  if root = nil
    parent.children[key[dno]] = 
      new data-node(key)

Trie Deletion

Delete

delete(root, key)

  (parent, root, dno) =
    find'(nil, root, key, 0)

  if root ≠ nil
    while root.parent ≠ nil
      parent = root.parent
      free root
      parent.children[key[--dno]] = nil
      if parent.child_count() ≠ 0, break
      root = parent

Other Operations

Some Refinements

Variable-Length Keys

Explicit Ends

Branch-Data Nodes

Some Refinements

Space Efficient Branch Nodes

Child Linked Lists

Child BSTs

Explicit Child Links

Child Link Hashing

No-Information Nodes

Compressed Tries

Binary Tries

References


This page last modified on 24 February 2006.

This work's CC license.