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
Harsh Vakharia
March 30, 2016
Education
0
44
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
32
Google Applied CS - Introduction
harshjv
0
32
Google Applied CS - Day 1
harshjv
0
110
Other Decks in Education
See All in Education
AI教育の未来『おもしろい』を作れる人材の育て方 #東京AI祭
o_ob
1
360
6 занятие. Четыре тактики метода "8 кубиков"бизнес-модели #ideaNN 1.03.2024.
karlov
0
150
LinkedIn
matleenalaakso
0
1.1k
前期教育実習事前指導0221
naradai
0
130
【潔能講堂】永續環境、擁抱綠能 太陽能光電發展現況與產業製程解析
learnenergy2
0
120
HCL Notes 14.0 「スタイルの変更」で「3 設定の確認」を深掘り
harunakano
0
2k
第1回全国商業高校Webアプリコンテスト総括
asial_corp
0
410
Virtual and Augmented Reality - Lecture 8 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.2k
わたしのメタ学習 / My Own Meta Learning #shinjukurb
expajp
0
120
執筆テーマの決め方
sapi_kawahara
1
180
week3@tcue2024
nonxxxizm
0
470
Avoin jakaminen ja Creative Commons -lisenssit
matleenalaakso
0
1.1k
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
Fantastic passwords and where to find them - at NoRuKo
philnash
37
2.5k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
104
6.6k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
21
1.6k
Become a Pro
speakerdeck
PRO
11
4.5k
Producing Creativity
orderedlist
PRO
337
39k
A designer walks into a library…
pauljervisheath
200
23k
Agile that works and the tools we love
rasmusluckow
325
20k
The MySQL Ecosystem @ GitHub 2015
samlambert
243
12k
Product Roadmaps are Hard
iamctodd
44
9.7k
The Mythical Team-Month
searls
216
42k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
2
3.4k
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?