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
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
Chapitre_2_-_Partie_3.pdf
bernhardsvt
0
150
HyRead2526
cbtlibrary
0
200
Going over the Edge
jonoalderson
0
340
【洋書和訳:さよならを待つふたりのために】第1章 出会いとメタファー
yaginumatti
0
240
SJRC 2526
cbtlibrary
0
200
【旧:ZEPメタバース校舎操作ガイド】
ainischool
0
790
1125
cbtlibrary
0
170
Chapitre_2_-_Partie_2.pdf
bernhardsvt
0
160
HCI Research Methods - Lecture 7 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.3k
RGBでも蛍光を!? / RayTracingCamp11
kugimasa
2
380
CSS3 and Responsive Web Design - Lecture 5 - Web Technologies (1019888BNR)
signer
PRO
1
3.1k
多様なメンター、多様な基準
yasulab
PRO
5
19k
Featured
See All Featured
Visualization
eitanlees
150
17k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
New Earth Scene 8
popppiees
1
1.5k
Designing Powerful Visuals for Engaging Learning
tmiket
0
230
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Deep Space Network (abreviated)
tonyrice
0
48
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
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?