🐻
berkeley
  • #Despair
  • 16A/B
    • Thevenin and Norton Equivalence
    • Resistive Touchscreen
    • Trilateration and Correlation
    • RC Circuits & Transient Analysis
  • 61B
    • Testing
    • References in Java
    • Linked Lists in Java
    • Implementation Inheritance
    • Comparables and Iterators
    • Casting
    • Lists and Sets
    • Asymptotics
    • Trees
    • Hashing
    • PriorityQueue and Heap
    • Graphs, Tree Traversals
    • Tries
    • Sorting
  • Discrete Mathematics
    • Sets + Mathematical Notation
    • Logic and Proofs
    • Induction
    • Cryptography/RSA
    • Modular Arithmetic
    • Discrete Probability
  • Linear Algebra
    • Linear Equations
    • Matrix Algebra
    • Determinants
    • Vector Spaces
    • Eigenvectors and Eigenvalues
    • Projections and Orthogonality
    • SVD/PCA
  • Math 275 — Ordinary Differential Equations
    • Math 275 — Overview
    • Modeling via Differential Equations
    • Linear Systems
  • INTEGBI 35AC
    • Humans Came From Fish
    • Evolution's History
    • Typology
    • The Human Diaspora
  • 170
    • Basics
    • Divide and Conquer
    • Fast Fourier Transform
    • Graphs
    • Greedy
  • 61C
    • Pointers and Memory
    • Floating Point
    • Compliation, Assembly, Linking, Loading
    • RISC-V, Assembly
Powered by GitBook
On this page
  • Implementation
  • Runtime
  • Alternate DataIndexedCharacterMaps

Was this helpful?

  1. 61B

Tries

Tries are a way that we can store string keys in a map. A trie is a tree with the following properties.

  • Each node in the tree contains a letter.

  • Each node can be stored by multiple keys.

  • Each node stores whether it is the end of a key or not.

When finding keys in a trie, we just go letter by letter until we're out of letters in the key we are inquiring — hitting a blue node at the end is a hit, while falling off the tree or ending on a white node is a miss.

Implementation

The basic trie implementation from lecture is as follows.

public class TrieSet {
    private static final R = 128;
    private Node root;
    private static class Node {
        private boolean isBlue; //Whether this is the end of a key
        private DataIndexCharmap next;
        private node (boolean isBlue, int R) {
            this.isBlue = isBlue;
            next = new DataIndexedCharMap<Node>(R); 
        }
    }
}

Runtime

Runtime is independent of the number of keys!

Alternate DataIndexedCharacterMaps

The goal is to make our DataIndexedCharMap as efficient and space efficient as possible. For example, we can use a HashTable, or a balanced BST.

PreviousGraphs, Tree TraversalsNextSorting

Last updated 4 years ago

Was this helpful?