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
2025-10-30 社会と情報2025 #05 CC+の代わり
mapconcierge4agu
0
110
Evaluation Methods - Lecture 6 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.3k
1014
cbtlibrary
0
530
1021
cbtlibrary
0
400
外国籍エンジニアの挑戦・新卒半年後、気づきと成長の物語
hypebeans
0
730
俺と地方勉強会 - KomeKaigi・地方勉強会への期待 -
pharaohkj
1
1.6k
Chapitre_2_-_Partie_2.pdf
bernhardsvt
0
160
Introduction - Lecture 1 - Advanced Topics in Big Data (4023256FNR)
signer
PRO
2
2.2k
東大1年生にJulia教えてみた
matsui_528
7
12k
JavaScript - Lecture 6 - Web Technologies (1019888BNR)
signer
PRO
0
3.1k
心理学を学び活用することで偉大なスクラムマスターを目指す − 大学とコミュニティを組み合わせた学びの循環 / Becoming a great Scrum Master by learning and using psychology
psj59129
1
1.7k
Web 2.0 Patterns and Technologies - Lecture 8 - Web Technologies (1019888BNR)
signer
PRO
0
3k
Featured
See All Featured
Designing Experiences People Love
moore
144
24k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
320
Crafting Experiences
bethany
1
49
Faster Mobile Websites
deanohume
310
31k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.9k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Google's AI Overviews - The New Search
badams
0
910
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
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?