Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Google Applied CS - Day 3

Google Applied CS - Day 3

Day 3:

Ghost game using ArrayList and Trie

Harsh Vakharia

March 30, 2016
Tweet

More Decks by Harsh Vakharia

Other Decks in Education

Transcript

  1. 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 } }
  2. 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; } }
  3. 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); }