Skip to content

Cross-Week Review (2): Which Lecture Material Each of the Twelve Projects Uses | Harvard CS50 AI Topic Guide

Aug 30, 20261 min
TL;DRThe twelve projects side by side: which functions each has you write, which lecture section it uses, and what example the spec page gives you to check against; which projects share a method (enumeration, search, Markov chains, learning from data) and which need something the lectures do not teach. Includes three worked examples and five self-check questions. The course gives no difficulty ratings or hour estimates, and neither does this post.

🌏 中文版

Video status: Official entry or recording index only. This post is this site's cross-week review, not any week's lecture, and there is no official video for it; the weekly lecture recordings do not introduce the projects, whose specs and implementations are in the second half of each weekly guide. Source details

⚠️ Version note: Project specs, distribution code, and check50 slugs follow the 2026 course site; the Week 6 projects are Parser and Attention.

TL;DR

None of the twelve projects starts from a blank file: the course provides distribution code and you fill in the functions the spec names. This post puts them side by side to answer three questions:

  • What each project has you write, which lecture section it uses, and what example the spec page gives to check against (the table below).
  • Which projects are really the same method (this site's summary).
  • Which projects need something the lectures do not teach, so you learn it from the spec page.

How to tell the two kinds of content apart in this post: "what you write" and "checkpoints on the spec page" come from the official specs; "lecture sections it uses" link to the weekly guides; anything marked "this site's summary" or "made up for this post" is what this site worked out after putting the projects side by side. Each project's distribution code, reference implementation, and run results are in the weekly guides and are not repeated here.

The official spec pages give no difficulty rating and do not say how long each project takes; this series has not measured how long a beginner needs, so this post does not rank difficulty or estimate hours.

The twelve projects compared

ProjectWhat you writeLecture sections it usesCheckpoints on the spec page
Degreesshortest_pathNodes, the frontier, and the generic search loop, DFS and BFSSample output: Emma Watson to Jennifer Lawrence is 3 degrees
Tic-Tac-ToeSeven functions, ending with minimax; alpha-beta pruning is optionalMinimax, alpha-beta pruningWith optimal play on both sides the game is a tie, so you should never be able to beat your own AI
KnightsKnowledge bases for four puzzlesPropositional logic, model checking, knowledge engineeringThis one must be 100% correct to pass; other projects pass at 70%
MinesweeperFour methods of Sentence, three methods of MinesweeperAIDeriving new facts from known ones (the sentence form is the project's own)The spec notes the AI will not always win: without enough information it has to guess
Heredityjoint_probability, update, normalizeBayesian networks, inference, joint probability and normalizationOne joint-probability example (0.0026643247488) and the full expected output for family0.csv
PageRanktransition_model, sample_pagerank, iterate_pagerankMarkov chainsA transition_model example (0.05, 0.475, 0.475); returned values must sum to 1
CrosswordEight functions in generate.pyConstraint satisfaction problems, AC-3, backtracking search, heuristicsThe run command and how to output an image; a hint that the heuristics can wait
Shoppingload_data, train_model, evaluateNearest neighbor, the scikit-learn runThe 17 evidence values of the first row; sample output of 41.02% and 90.55%
NimFour methods of NimAIQ-learning and ε-greedy, the Nim demonstrationThe Q-learning update formula and the three rewards (−1, 1, 0)
Trafficload_data, get_model, plus a README.mdConvolution, pooling and CNNs, handwriting.pyNo accuracy threshold; the sample output on the spec page shows 0.9535
ParserThe NONTERMINALS grammar, preprocess, np_chunkContext-free grammarThree sentences in the hints that should be accepted and two that should not
AttentionThree functions in mask.py, plus analysis.mdAttention, self-attention and multi-headed attentionThree predictions for each of the two opening example sentences; the color for 0.25 may be 63 or 64

"Checkpoints on the spec page" lists only examples or requirements stated on the spec page. This series did not run check50 (it has you log in with a GitHub account), so what check50 actually tests is not listed.

How the projects relate to one another

The grouping in this section is this site's summary; the course does not group the projects this way. Each group is followed by the reason for it, and the reasons themselves can be traced to a source.

Going through every possibility: Knights, Heredity. Once Knights has the puzzles written as knowledge bases, it hands them to model_check in logic.py, which enumerates every truth assignment of the propositional symbols. Heredity's official main walks through every combination of who has the trait, who has one copy of the gene, and who has two, and your joint_probability computes the probability of each. In both projects you do not write the enumeration itself; you write how one case is described or computed. The lectures' verdict on this approach is that it is correct but slows down as variables are added (the limit of model checking, inference); both projects are small enough to enumerate completely.

Searching a tree or a graph: Degrees, Tic-Tac-Toe, Crossword. Degrees uses BFS to find a shortest path in the graph of actors and movies; Tic-Tac-Toe uses Minimax over the whole game tree; Crossword uses backtracking search, assigning one variable at a time. All three apply Week 0's search framework, which the Week 3 lecturer makes explicit when he fits a CSP into the format of a search problem (A CSP as a search problem).

Two ways to compute on one Markov chain: PageRank. The spec describes a surfer clicking links at random as a Markov chain. sample_pagerank samples step by step from the transition model, which the lectures teach; the iterative formula used by iterate_pagerank is not taught in the lectures and is given on the spec page.

Learning from data or experience: Shopping, Nim, Traffic. Shopping and Traffic are supervised learning, with labeled data; Nim is reinforcement learning, where the AI learns from winning and losing in self-play. The official main in both Shopping and Traffic uses train_test_split to hold out 40% as a test set.

Hand-written rules: Knights, Parser. In both projects you write human knowledge as formal rules and hand them to an existing program to do the reasoning: Knights to model_check, Parser to NLTK's ChartParser. In Week 6 the lecturer says hand-written grammar rules never end, which is why the lecture turns to statistics; Parser lets you run into that limit yourself, since the spec wants a grammar that parses ten sentences without being loose enough to accept "Holmes sat in the the armchair."

Using a trained model: Attention. It is the only one of the twelve that uses a model someone else trained: it loads a pre-trained BERT and observes its outputs and attention. BERT is not mentioned in the lectures; the spec page introduces it.

Projects and the lectures' demonstration programs. Nine projects can be set directly against a program demonstrated in lecture or a definition given in lecture; this was compiled from the specs and the weekly guides:

ProjectLecture demonstrationRelationship
Degreesmaze.pyThe project's util.py is the lecture's Node, StackFrontier, QueueFrontier (stated on the spec page)
Tic-Tac-ToeThe lecture defines Minimax using tic-tac-toeThe player, actions, result, terminal, and utility the lecture defines have the same names as the functions the project has you write
Knightslogic.pyThe logic.py shipped with the project is nearly identical to the lecture's
PageRankchain/model.pyThe lecture draws 50 states from the weather Markov chain; sample_pagerank does the same thing
Crosswordschedule0.pyThe lecture uses it to demonstrate backtracking search
ShoppingThe scikit-learn run on banknote authenticationThe lecture uses the same KNeighborsClassifier
NimThe lecturer's own Nim AIThe same 10,000 games of self-play and the same opening of 1, 3, 5, 7
Traffichandwriting.pyThe spec's hint says the lecture source code will help; the official main follows nearly the same steps
Parsercfg0.py, cfg1.pyThe spec's hint says the lecture's rules are deliberately simplified and that you should modify them

Things the lectures do not teach and you learn from the spec page. This series could not find the following in the lecture transcripts; the project sections of the weekly guides explain them from the spec pages:

  • Minesweeper's sentence form (a set of cells plus a mine count) and the subset inference.
  • Heredity's inheritance rules and mutation probability.
  • PageRank's iterative formula and the damping factor.
  • Shopping's sensitivity and specificity.
  • Attention's BERT and the masked language model.

Example 1: how many joint probabilities Heredity computes

The loop structure of the official main is taken from heredity.py, and the data is the official family0.csv; the counts were computed for this post.

Setup. family0.csv has three people: Harry, James, and Lily. James is known to have the trait, Lily is known not to, and Harry is unknown. The loops in main are:

  1. For every combination of who has the trait (all subsets of the three people), skip those that contradict the known traits.
  2. For every combination of who has one copy of the gene.
  3. For every combination of who, among the rest, has two copies, call joint_probability once.

Computation. Level 1: James must be in and Lily must be out, so only Harry can go either way, leaving 2 combinations. Levels 2 and 3 together amount to each person independently having 0, 1, or 2 copies: 3 × 3 × 3 = 27 combinations. So there are 2 × 27 = 54 calls in all.

If the traits of all three were unknown, level 1 would be 2 × 2 × 2 = 8 combinations, for 8 × 27 = 216 calls.

What the result means. Each additional person multiplies the gene combinations by 3, and by another 2 if the trait is unknown. Three people give 216; ten people with unknown traits give 6 to the 10th power, about sixty million. This is what the Week 2 lecture's "exact but slow" looks like in practice; the project's families are small, so the enumeration finishes. Known evidence reduces the combinations to compute: family0.csv knows two people's traits, which brings 216 down to 54.

Example 2: why Shopping does not report accuracy

The row counts come from the Week 4 guide's check of shopping.csv; the "always predict no purchase" classifier is the spec page's own example, worked out below with the actual counts.

Setup. shopping.csv has 12,330 rows, of which 1,908 ended in a purchase and 10,422 did not. Suppose a classifier looks at no data at all and always answers "no purchase".

Computation.

accuracy    = correct ÷ all                        = 10,422 ÷ 12,330 ≈ 84.5%
sensitivity = share of buyers identified correctly     = 0 ÷ 1,908       = 0
specificity = share of non-buyers identified correctly = 10,422 ÷ 10,422 = 1

What the result means. An accuracy of 84.5% does not look bad, but this classifier identifies not a single buyer. Only when accuracy is split into sensitivity and specificity does that become visible. The Week 4 guide ran its reference implementation (nearest neighbor with k = 1) inside the official files, and neither number came out as 0 or 1: it does identify some of the buyers, at the cost of getting some non-buyers wrong. The number of runs and the ranges are in the Shopping section of the Week 4 guide and are not copied here.

Example 3: PageRank's transition model

The corpus is the official corpus0 and the formula follows the spec page; the numbers for this page were computed for this post.

Setup. corpus0 has four pages: 1.html links to 2.html; 2.html links to 1.html and 3.html; 3.html links to 2.html and 4.html; 4.html links to 2.html. The damping factor d is 0.85. The surfer is on 2.html; what is the probability of each page being next?

Computation. The spec's rule: with probability d, choose at random among the links on the current page; with probability 1 − d, choose at random among all pages.

  • Every page first gets (1 − 0.85) ÷ 4 = 0.0375.
  • 2.html has two links, each of which gets another 0.85 ÷ 2 = 0.425.

So 1.html and 3.html are each 0.0375 + 0.425 = 0.4625, and 2.html and 4.html are each 0.0375. The four sum to 0.4625 × 2 + 0.0375 × 2 = 1.

What the result means. This row is the "today on 2.html" row of a Week 2 transition model table, with the states changed from two kinds of weather to four web pages. transition_model computes one such row for each page, and together they are the whole table; sample_pagerank does what the lecture does when it draws 50 states from the weather Markov chain, except that it draws 10,000 and counts the share of each page.

Self-check

All five questions were made up for this post; the first, fourth, and fifth need material from more than one week.

Check yourself. Write your answer down before opening the fold. Puzzle 3 of Knights uses six propositional symbols (A, B, and C each have "is a Knight" and "is a Knave"). At most how many truth assignments does model_check have to check? Heredity's family0.csv takes 54 joint-probability computations. Why does neither project have to worry about the lectures' "enumeration is too slow"?

Answer

2 to the 6th power: 64.

Both projects are small: 64 assignments and 54 computations finish instantly. The problem the lectures describe appears as variables are added: each extra propositional symbol doubles the assignments, and each extra person with an unknown trait in Heredity multiplies the count by 6. The projects are sized so that you can first get "how one case is described and computed" right without dealing with efficiency.

Relevant sections: model checking, the limit of model checking, the Heredity project

Check yourself. Write your answer down before opening the fold. With the corpus0 of example 3 and d = 0.85, the surfer is on 1.html (which links only to 2.html). What is the probability of each of the four pages being next?

Answer

Every page first gets 0.15 ÷ 4 = 0.0375. 1.html has a single link, so all of 0.85 goes to 2.html. So 2.html is 0.0375 + 0.85 = 0.8875 and the other three pages are 0.0375 each. The sum is 0.8875 + 0.0375 × 3 = 1.

Relevant sections: Markov chains, the PageRank project

Check yourself. Write your answer down before opening the fold. On the data of example 2, a classifier identifies 800 of the 1,908 buyers and gets 9,422 of the 10,422 non-buyers right. What are its accuracy, sensitivity, and specificity? Compared with "always predict no purchase", which number got worse?

Answer

Accuracy = (800 + 9,422) ÷ 12,330 = 10,222 ÷ 12,330 ≈ 82.9%. Sensitivity = 800 ÷ 1,908 ≈ 41.9%. Specificity = 9,422 ÷ 10,422 ≈ 90.4%.

Accuracy drops from 84.5% to 82.9% and specificity from 1 to 0.904, but sensitivity rises from 0 to 0.419. Looking at accuracy alone you would think it is worse than "always predict no purchase", when it is the only useful one of the two.

Relevant sections: the Shopping project

Check yourself. Write your answer down before opening the fold. Of the twelve projects, which use a method that has a demonstration program or a definition in the lecture recordings to compare against? Pick one and name the program, or say what the lecture defines. Which project uses a model the lectures never mention?

Answer

This post identified nine: Degrees (the frontier classes of maze.py), Tic-Tac-Toe (the player, actions, result, terminal, and utility the lecture defines using tic-tac-toe), Knights (logic.py), PageRank (chain/model.py), Crossword (schedule0.py), Shopping (the scikit-learn run on banknotes), Nim (the lecturer's Nim AI), Traffic (handwriting.py), and Parser (cfg0.py, cfg1.py). Naming any one of them together with its program or the lecture's definition counts as correct (Tic-Tac-Toe is matched to a definition, not a program).

The BERT used by Attention is not mentioned in the lectures. The lecture teaches the architecture of attention and the Transformer; BERT is introduced on the spec page.

Relevant sections: the maze program, handwriting.py, the Attention project

Check yourself. Write your answer down before opening the fold. In Nim only one pile is left, with 2 objects, and it is your turn (whoever removes the last object loses). First use Week 0's Minimax idea: score "you win" as 1 and "you lose" as −1. What is the value of each of the two actions, and which should you choose? Then look at Week 4: after the Nim project trains with Q-learning for 10,000 games, the run in the Week 4 guide found Q-values of 1.0 and close to −1 for the two actions in this state. Do the two methods choose the same action? What does each need?

Answer

By Minimax: after you take 1, one object remains and the opponent has a single action, taking the last object, so the opponent loses and this action is worth 1. Taking 2 means you take the last object yourself, worth −1. Take the maximum: choose to take 1.

Q-learning learned Q-values of 1.0 and close to −1, and choosing the action with the highest Q-value also means taking 1. The two methods choose the same action.

The difference is in what they need. Minimax needs to know the rules and has to play the continuations out to the end of the game, with no experience of past games; the Tic-Tac-Toe project uses this. Q-learning does not search ahead; it corrects its estimates from the rewards of many games, one at a time, and the estimates are off when there have been too few games; the Nim project uses this. Setting the two projects side by side like this is this post's doing; the lecture does not solve Nim with Minimax.

Relevant sections: Minimax, letting an AI teach itself Nim, the Nim project

Where each project most often goes wrong

This table is compiled from the project sections of the weekly guides: some entries are explicit requirements in the spec, others are errors hit when the code was run inside the official files. The details and a runnable way to write each project are in the weekly guides.

ProjectSymptomCause
DegreesThe return format is wrongThe spec wants a list of (movie_id, person_id) pairs, and None when there is no path
Tic-Tac-ToeThe board changes mid-computationresult modified the board passed in. The spec requires the original board to be left unmodified and suggests a deep copy first
KnightsPuzzle 3 cannot determine anyone's identity"Which sentence A said" was not itself written as a sentence
MinesweeperThe loop in add_knowledge never endsYou rewrote Sentence and dropped __eq__, so the same sentence keeps being added to the knowledge base
MinesweeperA safe cell gets marked as a mineKnown mines were not subtracted from count when building the new sentence
HeredityThe numbers do not match the spec pagePeople without parents use the unconditional probability; people with parents use the pass probabilities (0.99, 0.5, 0.01)
PageRankThe pages do not sum to 1A page with no links must be treated as linking to every page; the first sample in sampling counts as one
CrosswordIt fails as soon as it runs inside the official filesThe keys of overlaps are pairs of variables; neighbors is a method and must be called
Shoppingmain fails when calling predicttrain_model must return the model itself
NimAccessing self.q raises an errorThe state is a list and must be converted to a tuple first. The rule is that whoever removes the last object loses
TrafficAccuracy stays around 0.055Pixel values were not scaled to 0–1; in the Week 5 guide, 5 of the 13 runs without scaling ended this way
ParserIt accepts a sentence it should notThe grammar is too loose, for example allowing determiners to repeat
AttentionImporting TFBertForMaskedLM failsThe packages are too new. The combination the Week 6 guide found to work on 2026-10-13 is transformers 4.44.2, tensorflow 2.21.0, tf-keras 2.21.0

Do the projects in week order. The only things known for certain that affect scheduling are these: Week 3 has a single project, Crossword, with eight functions to write; Traffic's dataset is a separate download; Attention downloads the model on first run; and the spec pages state that the latest Python to use in this course is 3.12.

Course video sources

This post is a cross-week review written by this site; it corresponds to no particular week and embeds no video. None of the seven lecture recordings introduces that week's project assignments (Week 4 demonstrates Nim but does not mention the assignment); the project content here comes from the spec pages on the course site and the officially released code. The official CS50 YouTube playlist (8 videos: an introduction plus the Week 0–6 lectures) was checked live on 2026-10-10.

Course and recording entries:

Checked: 2026-10-10.

Update Log

  • 2026-10-10: Added explicit video status and checked recording sources and access notes.
  • 2026-10-10: Rechecked video status. The official playlist was checked live; no recording corresponds to this post, so the status stays official entry only.
  • 2026-10-13: Brought the Week 6 projects in line with the current course: the twelfth project is Attention (previously the 2020 edition's Questions), and the Parser notes now describe what the spec actually asks for — a CFG grammar, preprocess, and np_chunk (previously CYK and sentence generation).
  • 2026-10-13: Rewritten from scratch against the official distribution code, the spec pages, and the rewritten weekly guides, with its role changed to a cross-week review. Removed unsupported content: the estimated line counts per project, the star difficulty ratings, the hour estimates and the "60–100 hours" total, the "check50 key verification" column (this series did not run check50), and the skill transfer map. Corrected wrong project descriptions: Heredity enumerates every combination and normalizes (previously likelihood-weighting sampling); Shopping has no StandardScaler (previously "MUST use"); Nim has no discount parameter (previously γ=1); add_constraints, forward_check, count_conflicts, and structure3.txt do not exist in Crossword's official files; in Traffic you write load_data yourself and the spec has no accuracy threshold (previously: check50 loads traffic_model.h5, threshold around 95%); alpha-beta pruning in Tic-Tac-Toe is optional. New content: each project linked to the lecture sections it uses, six kinds of relationship between projects and nine lecture demonstrations to compare against, three examples worked to the end, and five self-check questions with answers. The scope label in the title changed from "Course Overview" to "Topic Guide", and the topic half now says what the post actually does.
  • 2026-10-13: Fixes from independent review: example 2 no longer copies the run count and ranges from the Week 4 guide and links there instead; Tic-Tac-Toe and PageRank were added to the projects with a lecture demonstration to compare against, nine in all; Attention's checkpoint is two example sentences; "neither trains nor reasons" became "uses a model someone else trained"; the PageRank row no longer links to the Bayesian-network sampling section; the account needed for check50 is now consistently a GitHub account; the tags difficulty and portfolio were removed.
  • 2026-10-14: Fixes from re-review: the fourth self-check question and its criterion now cover "a definition given in lecture", since Tic-Tac-Toe is matched to a definition, not a program. The tag comparison was also removed.

References