Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CS253: Tries (2019)
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Jinho D. Choi
October 07, 2019
Technology
290
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
170
CS253: Shortest Path (2019)
jdchoi77
0
180
CS253: Topological Sort (2019)
jdchoi77
0
190
CS253: Minimum Spanning Trees (2019)
jdchoi77
0
240
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
「待ち時間」の消滅と「自我消耗」の加速:生成AI時代のエンジニアを救うメンタル・リソース管理
poropinai1966
0
400
[しろおび夏祭り2026] チャットするAIから、作業するAIへ - 使われ方の変化と、その裏側で起きていること
kk0n
0
730
AIQAのナレッジ構築について
qatonchan
1
140
なぜ、あなたのAPIは使われないのか? AX時代の設計原則、ガードレール、運用体制
yokawasa
1
1.2k
データと地図で読む 大井町の「かわるもの、かわらないもの」
yoshiyama_hana
0
900
[MIRU26] To What Extent Does MLLM-as-a-Judge Exhibit Cross-Model Preference Bias?
keio_smilab
PRO
0
100
DevOps Agentで運用判断をチーム資産にする~Agent InstructionsとAgent Skillを継続的に育てる~
fujioka6789
0
180
BigQuery を検索ソースとした AI Agent の作り方って 〇〇 通りあんねん
satohjohn
0
150
A Bag-of-Documents Model for Query Specificity
dtunkelang
0
190
運用を犠牲にせずコストを制御し事業成長を支える B2B SaaS ID管理基盤におけるS3 Tableのログストレージ活用
kaminashi
1
130
脱Jenkins、インターン生が挑んだCIツールGitHubActions移行
mixi_engineers
PRO
1
300
CloudWatchから始めるAWS監視
butadora
0
310
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
230
Testing 201, or: Great Expectations
jmmastey
46
8.2k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
For a Future-Friendly Web
brad_frost
183
10k
Darren the Foodie - Storyboard
khoart
PRO
3
3.5k
Scaling GitHub
holman
464
140k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Unsuck your backbone
ammeep
672
58k
Odyssey Design
rkendrick25
PRO
2
740
The agentic SEO stack - context over prompts
schlessera
0
860
Leo the Paperboy
mayatellez
8
2k
Navigating Weather and Climate Data
rabernat
0
430
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