Lecture W5M1: Schedule Update, Due Dates, Where We Are, and HW2 Hints
September 21, 2026

| Date | Was | Now |
|---|---|---|
| Mon 9/21 | AVL trees | Binary trees, part 1 (today) |
| Wed 9/23 | Heaps and priority queues | Binary trees, part 2: AVL trees |
| Mon 9/28 | Breadth-first search | Binary heaps and priority queues |
| Wed 9/30 | DFS and topological sort | Graph search: BFS, DFS, and topological sort |
| Mon 10/5 | Greedy and MST | Greedy and MST (unchanged) |
BFS and DFS share one session on the 30th; they pair naturally, and the reading (CLRS 20.1 to 20.4) is unchanged. From October 5 on, every date in the syllabus is exactly as it was, including the midterm on Wednesday, October 14.
| Date | What |
|---|---|
| Wed 9/23, 9:59 PM | HW2 due (extended) |
| Fri 9/25 | Project teams set |
| Wed 9/30, 9:59 PM | HW3 due; HW4 assigned |
| Mon 10/5 | Project proposal due; last day to elect CR/NC (5 PM) |
| Mon 10/12 | HW4 due; midterm review |
| Wed 10/14 | Midterm exam, in class |
A free, 10-week virtual hackathon in which student teams build real agentic AI applications alongside students from universities across Oregon, Washington, and the Bay Area.

(a) Insert the keys \(A = [18, 83, 26, 39, 91, 85, 84]\), in order, into a hash table of size \(7\) with \(h(k) = (5k + 3) \bmod 7\). Each slot holds a linked list; later insertions are appended to the end. Draw the table after all seven insertions.
(b) Now let \(h(k) = ((5k + 3) \bmod c) \bmod 7\) for a positive integer \(c\). Find the smallest \(c\) such that no collisions occur when inserting the keys of \(A\), and show the slot of each key for that \(c\).
\(2n\) campers, \(n\) cabins; each camper is assigned by hashing a self-chosen badge ID (a positive integer below \(u \gg 2n\)). The family \(\mathcal{H}\) is published before IDs are chosen; one function is drawn at random after. For each family, either show Wren and Ivy can pick IDs that guarantee a shared cabin, or prove they cannot and find the best probability they can achieve.
(a) \(h_{ab}(k) = (ak + b) \bmod n\), with \(a, b \in \{0, \ldots, n-1\}\), \(a \neq 0\).
(b) \(h_a(k) = \left(\lfloor kn / u \rfloor + a\right) \bmod n\), with \(a \in \{0, \ldots, u-1\}\).
(c) \(h_{ab}(k) = ((ak + b) \bmod p) \bmod n\) for a fixed prime \(p > u\): the universal family from lecture.
The question that decides everything: can Wren and Ivy pick two IDs that every function in the family treats identically?
Sort \(n\) vinyl records efficiently (asymptotically faster correct algorithms earn more) and justify the running time, when the key is:
(a) a catalog code: exactly \(8 \lceil \log_{64}(n^2) \rceil\) symbols from a \(64\)-symbol alphabet, one byte each;
(b) the pressing year, within the last \(150\) years;
(c) the playing time, a rational \(m / n^2\) minutes in \([0, 90]\) with \(m\) an integer;
(d) warmth, which no meter measures, but any two records can be compared by ear in \(O(1)\) time.
Ask one question per scenario: are the keys integers, and how large are they compared with \(n\)?
Along an \(n\)-foot wall stand \(n\) one-foot bins; bin \(i\) holds a known positive integer \(b_i\) grams, and no two bins hold the same amount. Let \(B = (b_0, \ldots, b_{n-1})\). A customer orders exactly \(r\) grams. Beatrix wants to know whether some nearby pair of bins, meaning \(|i - j| < n/8\), fills the order, meaning \(b_i + b_j = r\).
(a) Given \(B\) and \(r\), describe an expected \(O(n)\)-time algorithm that decides whether a nearby filling pair exists.
(b) Now suppose \(r < n^2\). Describe a worst-case \(O(n)\)-time algorithm for the same question.
The anagram window count of \(B\) in \(T\) is the number of contiguous substrings of \(T\) that are anagrams of \(B\) (lowercase letters only). Example: \(T\) = redocsrocdecoderacedar, \(B\) = coder gives \(3\): redoc, rocde, coder.
(a) Given \(T\) and \(k\), a data structure built in \(O(|T|)\) time that, for any \(B\) with \(|B| = k\), returns the count in \(O(k)\) time.
(b) Given \(T\) and \(n\) length-\(k\) strings, an \(O(|T| + nk)\)-time algorithm returning every count.
(c) Implement (b) as count_anagram_windows(T, S) in the provided file (ord(c) is \(O(1)\); tests included).
tuple of \(26\) ints is a valid dict key; ord(c) - ord('a') is the index.Recomputing the count vector from scratch for every window is \(O(|T| \cdot k)\). It passes every provided test and fails the running-time requirement, which is where \(25\) of the \(40\) points live. Sorting each window (\(O(|T| \cdot k \log k)\)) has the same problem. Slide.
Common to every problem this week: the answer is short once you name the right tool. Spend your time choosing, then write it down cleanly.
| Minutes | What |
|---|---|
| 25 | This deck: announcements, where we are, HW2 problem by problem |
| 10 | The semester project: what it is and how to start (deck W5M2) |
| 50 | Binary trees, part 1, ending with HW3 (deck W5M3) |
The project and lecture slides are separate decks (W5M2 and W5M3).
