Skip to content

Midterm 1, Section 01, Problem 4: Streaming with O(1) State

Midterm 1, Section 01, problem 4 of 5 · Length: 10:06 · Exercises: 12c_wc (Week 5), with 11c_cat (Week 5) · Exam: Section 01 (PDF) · Answer key: Solutions (PDF)

Four parts, worked on pages 8 and 9: (a) count_fd traced over three reads; (b) in_word moved inside the loop: the counts it gives, and why wc's tests miss it; (c) how many times cat_fd calls read and write_all for two file sizes; (d) longest_line, built on count_fd's pattern: the options for its two boxes, checked on the example. The answer key's handwriting is written onto the exam page as each step is worked.

Download the video (MP4, 15 MB) · Captions (WebVTT) · All five problems