String Matching: Brute Force, KMP, Rabin-Karp
Find a substring inside a larger string. It sounds trivial — just scan through, checking each position. That's the brute-force approach, and it's O(n × m) where n is the text leng…
String Algorithms and Complexity Theory covers: String Matching, Tries, Suffix Arrays, and Suffix Trees, P, NP, and the Question That's Been Open Since 1971, NP-Completeness and Reductions, Approximation and Randomised Algorithms. Year 1, Quarter 4. Includes 17 exercises and 1 projects.
This course unlocks once you've finished its prerequisite. Open prerequisite →
Complete prerequisites first to enroll.
Find a substring inside a larger string. It sounds trivial — just scan through, checking each position. That's the brute-force approach, and it's O(n × m) where n is the text leng…
The previous lesson taught algorithms that match a single pattern in a single text. What if you need to query the same text many times — "is X a prefix of any word in my dictionar…
Some problems we can solve quickly. Sorting a billion numbers: a few seconds. Finding the shortest path between two cities: milliseconds. Routing data packets: nanoseconds.
In 1972, Richard Karp published a paper showing that 21 different problems — graph colouring, travelling salesman, vertex cover, Hamiltonian cycle, knapsack, set cover, and 15 oth…
The previous two lessons established that NP-complete problems can't be solved in polynomial time (we believe). But businesses still need to route delivery trucks, schedule classe…
- [ ] Implement Trie (Prefix Tree) (#208) — NC/LC — Insert, search, startsWith methods - [ ] Single Number (#136) — NC/LC — XOR all elements, duplicate cancels out - [ ] Number of…
- [ ] Design Add and Search Words (#211) — NC/LC — Trie with wildcard DFS - [ ] Implement KMP string matching in Ruby — Build failure function, O(n+m) matching - [ ] Implement Rab…
- [ ] Word Search II (#212) — NC/LC — Trie + DFS on grid, prune branches - [ ] Prove that 3-SAT is NP-complete (written proof) — Reduction from SAT - [ ] Implement a suffix array …
- [ ] Build a text search engine in Ruby — construct a trie from a corpus of documents, support prefix search and autocomplete, implement KMP for exact phrase matching, rank resul…
Build a trie-based autocomplete system in Ruby. Load a dictionary of 100K+ words, support prefix search returning top-10 suggestions ranked by frequency. Implement KMP for exact s…
- [ ] What is a trie? What operations does it support and what are their time complexities? - [ ] Explain the KMP string matching algorithm. What is the failure function? - [ ] Wh…
- [ ] Course 4.1 knowledge check passed - [ ] Course 4.2 knowledge check passed - [ ] Course 4.3 knowledge check passed - [ ] Course 4.4 knowledge check passed - [ ] Smart Text Ed…
Complete all of the following. There is no time limit on the overall assessment, but individual items have targets.
13 lessons. Read in order; spiral back when you need to. By the end you'll have used the core ideas twice — once on the abstract, once on something you'll meet at work next week.