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
Google Applied CS - Day 3
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Harsh Vakharia
March 30, 2016
Education
0
53
Google Applied CS - Day 3
Day 3:
Ghost game using ArrayList and Trie
Harsh Vakharia
March 30, 2016
Tweet
Share
More Decks by Harsh Vakharia
See All by Harsh Vakharia
Google Applied CS - Day 4
harshjv
0
42
Google Applied CS - Introduction
harshjv
0
41
Google Applied CS - Day 1
harshjv
0
130
Other Decks in Education
See All in Education
都市の形成要因と 「都市の余白」のあり方
sakamon
0
160
HyRead2526
cbtlibrary
0
200
AIで日本はどう進化する? 〜キミが生きる2035年の地図〜
behomazn
0
110
【ベテランCTOからのメッセージ】AIとか組織とかキャリアとか気になることはあるけどさ、個人の技術力から目を背けないでやっていきましょうよ
netmarkjp
2
2.7k
1125
cbtlibrary
0
170
子どもが自立した学習者となるデジタルの活用について
naokikato
PRO
0
180
国際卓越研究大学計画|Science Tokyo(東京科学大学)
sciencetokyo
PRO
0
47k
外国籍エンジニアの挑戦・新卒半年後、気づきと成長の物語
hypebeans
0
730
Flinga
matleenalaakso
2
15k
TinyGoをWebブラウザで動かすための方法+アルファ_20260201
masakiokuda
1
210
令和エンジニアの学習法 〜 生成AIを使って挫折を回避する 〜
moriga_yuduru
0
240
AWS re_Invent に全力で参加したくて筋トレを頑張っている話
amarelo_n24
2
120
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
1
750
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
410
Music & Morning Musume
bryan
47
7.1k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
830
My Coaching Mixtape
mlcsv
0
48
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
The Pragmatic Product Professional
lauravandoore
37
7.1k
Claude Code のすすめ
schroneko
67
210k
Rails Girls Zürich Keynote
gr2m
96
14k
How to build a perfect <img>
jonoalderson
1
4.9k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
170
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Transcript
Google Applied CS with Android
High Time
Ghost
How-to 1. Build dictionary 2. Set button click listeners 3.
Decide the turn
Decide the turn if (user's turn) { listen to onKeyUp
-> (k) { if k is a valid letter { append it to TextView } else ignore } } else { if word is of length 4 or more && it is a valid word { Computer wins } else { put next character } }
Put next character It should form a valid word because
this is a computer!
Ta-da ! while (low < high) { mid = (low
+ high) / 2; t = words.get(mid); if(t.startsWith(prefix)) { return t; } else if(prefix.compareTo(t) > 0) { // LHS is bigger low = mid + 1; } else { // RHS is bigger high = mid - 1; } }
Best case: O(1) Average/Worst case: O(log n)
None
None
Tri ! re(tri)eval
Basics 1. HashMap<Character, TrieNode> children 2. root.add(word) 3. root.isWord(word) 4.
root.getAnyWordStartingWith(word)
Add a word to Trie void add(String s, int position)
{ if (position >= s.length()) return; char c = s.charAt(position); TrieNode n = children.get(c); if (n == null) { n = new TrieNode(); children.put(c, n); } if (position == s.length() - 1) { n.isWord = true; } n.add(s, position + 1); }
And a bit of method overloading
void add(String s) { add(s, 0) } void add(String s,
int position) { ... }
Same logic, different application 1. root.isWord(word) 2. root.getAnyWordStartingWith(word)
Fast Dictionary ! An efficient lookup structure
This is it for today
Any doubts?