Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Google Applied CS - Day 3
Search
Harsh Vakharia
March 30, 2016
Education
58
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Google Applied CS - Day 3
Day 3:
Ghost game using ArrayList and Trie
Harsh Vakharia
March 30, 2016
More Decks by Harsh Vakharia
See All by Harsh Vakharia
Google Applied CS - Day 4
harshjv
0
48
Google Applied CS - Introduction
harshjv
0
46
Google Applied CS - Day 1
harshjv
0
140
Other Decks in Education
See All in Education
人間関係に取り組む、その時に / step away to make space
spring_aki
0
140
新入社員を「あの子」と呼ばない運動 -PBL その前に- / Stop Calling New Hires "Kids"
aokiplayer
2
930
ちいかわを読め
uchi8977
1
410
子どものためのプログラミング道場『CoderDojo』〜法人提携例〜 / Partnership with CoderDojo Japan
coderdojojapan
PRO
4
19k
【ainiチャット操作ガイド】
ainischool
0
120
BRIEF OUTLINE OF IMPORTANT PLANT CONSTITUENTS
pawan_pharm
0
210
Adobe Express
matleenalaakso
2
8.4k
Design Guidelines and Models - Lecture 5 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.7k
aini school小中等部説明会資料
ainischool
0
180
CSS3 and Responsive Web Design - Lecture 5 - Web Technologies (1019888BNR)
signer
PRO
1
3.5k
TISSUE
pawan_pharm
0
280
25-26 CBT Library top items
cbtlibrary
0
360
Featured
See All Featured
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
800
Discover your Explorer Soul
emna__ayadi
2
1.3k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
620
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Ethics towards AI in product and experience design
skipperchong
2
430
The Pragmatic Product Professional
lauravandoore
37
7.5k
Navigating Team Friction
lara
192
16k
Into the Great Unknown - MozCon
thekraken
41
2.8k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
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?