Strings, grids and bits
Finding a pattern in a text without repeating work, finding routes across a grid with breadth-first search and A*, and working directly on the bits of a number.
About 10 hours of study
Learning objectives
- Build an lps table and search with KMP
- Find shortest paths on a grid
- Explain how A* uses a guess
- Test, set and clear bits, and list subsets with a mask
Lessons
- 1
String matching: naive search and KMP Advanced
Find every place a pattern appears in a text: the simple O(n·m) method, and Knuth–Morris–Pratt, which never moves backwards in the text.
- 2
Searching grids: BFS and A* Advanced
Treat a grid as a graph to find shortest paths through mazes and maps with BFS, then reach the goal faster with A*'s distance guess.
- 3
Bit manipulation Intermediate
Use AND, OR, XOR and shifts to test, set and clear single bits, list every subset, and solve classic problems with no extra memory.
Module practice
- Find the first matchEasy
- Find every matchMedium
- The repeating unit of a wordHard
- How far can the paint spread?Easy
- Shortest way through a mazeMedium
- Distance to the nearest exitHard
- The number without a partnerEasy
- Repair the bit tricksMedium
- The two numbers without partnersHard