Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CS253: Tries (2019)
Search
Jinho D. Choi
October 07, 2019
Technology
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CS253: Tries (2019)
https://github.com/emory-courses/cs253
Jinho D. Choi
October 07, 2019
More Decks by Jinho D. Choi
See All by Jinho D. Choi
CS253: Dynamic Programming (2019)
jdchoi77
0
260
CS253: Network Flows (2019)
jdchoi77
0
180
CS253: Shortest Path (2019)
jdchoi77
0
180
CS253: Topological Sort (2019)
jdchoi77
0
190
CS253: Minimum Spanning Trees (2019)
jdchoi77
0
250
CS253: Balanced Binary Search Trees (2019)
jdchoi77
0
300
CS253: Binary Search Trees (2019)
jdchoi77
0
170
CS253: Distribution-based Sort (2019)
jdchoi77
0
160
CS253: Divide & Conquer Sort (2019)
jdchoi77
0
200
Other Decks in Technology
See All in Technology
Genieを崇めよ
kameitomohiro
0
140
事業課題から技術的負債に向き合う
sansantech
PRO
2
1.9k
AgentCore Runtime上にAgentic Coding基盤を構築・展開する際の設計ポイントと限界点 / Design considerations and limitations when building an agentic coding platform on AgentCore Runtime
har1101
2
130
aws-iot-platform-architecture-use-cases.pdf
ma2shita
0
190
すぐできる衛星通信対応 あとは山奥に行くだけ
tatetate55
0
130
人間はどの意思決定を手放せるのか
kawasima
14
7k
2026-09-11 【Snowflake World Tour Tokyo 2026】Snowflakeを起点に、AI Agentが自律稼働し続ける未来へ / Driving AI Agents with Snowflake
civitaspo
0
600
ソフトウェアDNAとクラウドエージェントのススメ
cloudace
0
110
CLIライブラリ開発を支える技術
htnabe
0
120
アプリをもっと"iOSアプリっぽく"する小さな工夫 / Small Touches That Make Your App Feel More Like an iOS App
matsuji
1
910
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
22
14k
AI 時代のスタートアップエコシステ厶から考究する技術的負債との向き合い方
m3m0r7
PRO
2
2.1k
Featured
See All Featured
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
520
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
570
A designer walks into a library…
pauljervisheath
211
25k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
500
Leo the Paperboy
mayatellez
10
2.3k
Six Lessons from altMBA
skipperchong
29
4.5k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
700
It's Worth the Effort
3n
188
29k
Transcript
Tries Data Structures and Algorithms Emory University Jinho D. Choi
https://github.com/emory-courses/cs253
None
{"she", "shell", "see", "shore", "selling", "sell"}
None
public class TrieNode<T> { private Map<Character, TrieNode<T>> children; private TrieNode<T>
parent; private boolean end_state; private char key; private T value; public TrieNode(TrieNode<T> parent, char key) { children = new HashMap<Character, TrieNode<T>>(); setEndState(false); setParent(parent); setKey(key); setValue(null); } <T> value end_state
TrieNode.java public TrieNode<T> getChild(char key) { return children.get(key); } public
TrieNode<T> addChild(char key) { TrieNode<T> child = getChild(key); if (child == null) { child = new TrieNode<T>(this, key); children.put(key, child); } return child; } public TrieNode<T> removeChild(char key) { return children.remove(key); } get() add() remove()
Trie.java public class Trie<T> { private TrieNode<T> root; public Trie()
{ root = new TrieNode<>(null, (char) 0); } public T get(String key) { TrieNode<T> node = find(key); return (node != null && node.isEndState()) ? node.getValue() : null; } public TrieNode<T> find(String key) { char[] array = key.toCharArray(); TrieNode<T> node = root; for (int i = 0; i < key.length(); i++) { node = node.getChild(array[i]); if (node == null) return null; } return node; } (char)0 find()
Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"}
Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅
Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅
Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅
Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s ∅
Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s ∅ h
∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ h ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅ 2
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅ 2
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅ 2
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅ 2 o ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅ 2 o ∅ r ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅ 2 o ∅ r ∅ e ∅
e ∅ Trie - Put 2 {“she”,”shell”,"see","shore","selling","sell"} ∅ ∅ s
∅ 0 h ∅ l ∅ l ∅ 1 e ∅ e ∅ 2 o ∅ r ∅ e ∅ 3
public T put(String key, T value) { char[] array =
key.toCharArray(); TrieNode<T> node = root; for (int i = 0; i < key.length(); i++) node = node.addChild(array[i]); node.setEndState(true); return node.setValue(value); }
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 e ∅ e 2 o ∅ r ∅ e ∅ 3
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 e ∅ e 2 o ∅ r ∅ e ∅ 3 “see”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 e ∅ e 2 o ∅ r ∅ e ∅ 3 “see”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 e ∅ o ∅ r ∅ e ∅ 3 “see”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 o ∅ r ∅ e ∅ 3 “see”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 o ∅ r ∅ e ∅ 3 “see” ”she”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 o ∅ r ∅ e ∅ 3 “see” ”she”
Trie - Remove 3 e 0 ∅ ∅ s ∅
∅ h ∅ l ∅ l 1 o ∅ r ∅ e ∅ 3 “see” ”she”
Trie - Remove 3 e 0 ∅ ∅ s ∅
∅ h ∅ l ∅ l 1 o ∅ r ∅ e ∅ 3 “see” ”she” ”shell”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 o ∅ r ∅ e ∅ 3 “see” ”she” ”shell”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ l 1 o ∅ r ∅ e ∅ 3 “see” ”she” ”shell”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ l ∅ o ∅ r ∅ e ∅ 3 “see” ”she” ”shell”
Trie - Remove 3 e 0 ∅ ∅ s ∅
h ∅ o ∅ r ∅ e ∅ 3 “see” ”she” ”shell”
public boolean remove(String key) { TrieNode<T> node = find(key); if
(node == null || !node.isEndState()) // node doesn't exist return false; if (node.hasChildren()) { // node to be removed as children node.setEndState(false); return true; } TrieNode<T> parent = node.getParent(); while (parent != null) { // remove iteratively parent.removeChild(node.getKey()); if (parent.hasChildren() || parent.isEndState()) // another word break; else { node = parent; parent = parent.getParent(); } } return true; }
None