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
IHLヘルスケアリーダーシップ研究会17期説明資料
ihlhealthcareleadership
0
880
The World That Saved Me: A Story of Community and Gratitude
_hashimo2
3
510
Design Guidelines and Models - Lecture 5 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.3k
【洋書和訳:さよならを待つふたりのために】第2章 ガン特典と実存的フリースロー
yaginumatti
0
230
ロータリー国際大会について~国際大会に参加しよう~:古賀 真由美 会員(2720 Japan O.K. ロータリーEクラブ・(有)誠邦産業 取締役)
2720japanoke
1
770
【dip】「なりたい自分」に近づくための、「自分と向き合う」小さな振り返り
dip_tech
PRO
0
230
HTML5 and the Open Web Platform - Lecture 3 - Web Technologies (1019888BNR)
signer
PRO
2
3.2k
Web Search and SEO - Lecture 10 - Web Technologies (1019888BNR)
signer
PRO
2
3.1k
AIで日本はどう進化する? 〜キミが生きる2035年の地図〜
behomazn
0
110
✅ レポート採点基準 / How Your Reports Are Assessed
yasslab
PRO
0
280
The Next Big Step Toward Nuclear Disarmament
hide2kano
0
220
【ZEPホスト用メタバース校舎操作ガイド】
ainischool
0
170
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
240
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Odyssey Design
rkendrick25
PRO
1
490
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Testing 201, or: Great Expectations
jmmastey
46
8k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
120
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
430
Fireside Chat
paigeccino
41
3.8k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
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?