Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 08 · DSA · Worked problems, in English · about 18 min to read

Play it as a journeyTutor comes with a plan

Clinic #24: Word Search II

Pattern: Trie + backtracking · LC 212

Algorithm Design Patterns
Algorithm Design Patterns · Open board

Among its panels is a search drawn as a branching tree, with most of the branches crossed out before anyone walks them. This clinic is that crossing-out, done by a word list that knows when to give up.

Before you start. You need the tree of letters from Trees (BST, balancing, heaps, tries): every word is one path down from the top, one letter per step, and words that start the same way share their first steps; Clinic #23: Implement Trie builds one in code. You also need the move from Algorithm Design Patterns‘s chess queens: make a choice, go deeper, and undo the choice the moment it cannot work.

Lesson 63 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1973: Boggle, sixteen dice and a three-minute timer
  • By hand: four words on a four-by-four board
  • The wrong first idea: hunt for each word on its own
  • The thumb in the dictionary: a prefix tells you when to stop
  • The trie: the word list rebuilt as a tree of letters
  • Backtracking: step onto a square, and give it back on the way out
  • Pruning: cross a word off the moment you find it
  • The problem as LeetCode states it
  • The ladder: three solutions, same answer
  • Measured: a random board and real words
  • Measured: the board where pruning matters
  • The worst case, as arithmetic
  • Two bugs that pass LeetCode’s example
  • The route in an interview
  • The ladder for this pattern

Terms it explains: LC 212, prefix, trie, node, backtracking, pruning, all, list, grid, once, brute force, constraint satisfaction, divide & conquer, dynamic programming, exchange argument, greedy, Master theorem, the meta-method.

Lab

Grabbing the biggest coin that fits gives the fewest coins with 1, 5, 10 and 25. Does it with any coins?

Pick 1, 3, 4 under The coins, set The amount to make to 6, and watch Coins greedy wasted.

Open The greedy bet

Review DSA