CS181 Lecture 2 -- Fall 2026, UCLA
Overview
Eli Jaffe completes the discussion of data representation by showing how prefix-free binary encodings let separate values be concatenated and decoded, then uses Boolean circuits to formalize simple computational steps. The lecture defines specifications and circuit evaluation, builds majority and XOR functions from AND, OR, and NOT gates, and explains how a DAG’s topological ordering enables evaluation.
Key takeaways
- Duplicating each bit and appending 01 turns an ordinary encoding into a prefix-free code that can be decoded while scanning concatenated values.
- Concatenating prefix-free encodings produces a decodable encoding of a list, but the resulting list encoding is not guaranteed to remain prefix-free.
- The simple bit-duplication conversion roughly doubles encoding length, while Jaffe notes an alternative with only about 2 log n plus two extra bits for an encoding of length n.
- A three-input majority function can be implemented as (A AND B) OR (B AND C) OR (A AND C), using only AND and OR gates.
- Three-bit parity is computed compositionally as XOR2(XOR2(A, B), C), reusing a two-input XOR circuit as a subcomponent.
- Topological ordering of a Boolean-circuit DAG gives an evaluation schedule: compute inputs first, then evaluate gates in successive layers.
Chapters
- Eli Jaffe directs students to the course page on Bruin Learn, Gradescope, and EdStem for course materials and recordings.
- All three exams are in person; the first two occur during lecture, while the final is scheduled in another room.
- The lecture finishes binary data representation before introducing Boolean circuits as a formal model of computation.
- Jaffe corrects the previous lecture’s claim that a rational-number encoding was invalid.
- The scheme prefixes the numerator’s binary encoding with one zero per numerator bit, followed by a one delimiter, then encodes the denominator.
- A decoder counts the leading zeros, reads that many bits as the numerator, and treats the remaining bits as the denominator.
- The more reusable scheme duplicates each bit of an integer’s binary encoding and appends the tag 01.
- A decoder scans two-bit blocks: duplicated blocks are 00 or 11, while 01 marks the end of the encoded integer.
- For example, the integer 3 has binary encoding 011, which becomes 00111101 under this prefix-free scheme.
- An encoding E is prefix-free when, for distinct objects X and Y, E(X) is not a prefix of E(Y).
- The ordinary natural-number binary encodings of 3 and 6 are 11 and 110, so they are valid but not prefix-free.
- Concatenated values need unambiguous boundaries; the duplicated-bit encoding supplies them with its 01 terminator.
- Given a prefix-free encoding P, Jaffe defines a list encoding by concatenating P(X1), P(X2), through P(Xk).
- The concatenated list encoding is valid, though it is not necessarily itself prefix-free.
- Prefix-freeness prevents a decoder from mistaking the beginning of a longer codeword for a complete shorter codeword.
- The decoder advances through the input bits, testing progressively longer prefixes until one is a valid P-encoding.
- When a complete codeword is found, it decodes and stores that object, then resumes at the next bit.
- The method avoids the 11-versus-110 ambiguity of ordinary binary encodings because prefix-free codewords cannot contain one another as prefixes.
- For any existing encoding E, Jaffe constructs a prefix-free version by duplicating every output bit and appending 01.
- This general method works for objects beyond integers, unlike the leading-zero rational-number scheme.
- Repeatedly applying the conversion allows encodings to be composed into nested lists.
- A list of integers can be encoded by concatenating prefix-free integer codes; prefix-free encoding that result enables lists of lists.
- Jaffe models a video as a list of images, with each image represented as a list of numbers, and gives libraries of books as another nested-list example.
- Duplicating every bit costs about twice the original encoding length plus two tag bits; a more efficient scheme adds roughly 2 log of the original length plus two bits.
- Jaffe’s course-level conclusion is that ordinary finite binary strings can represent countable data, but not every real number.
- Georg Cantor’s uncountability result establishes that the real numbers cannot be mapped one-to-one into the natural numbers, and finite bit strings are countable.
- Cantor’s methods will return later when the course studies problems that cannot be computed.
- After a short break, Jaffe treats reasonable inputs as arbitrary-length bit strings and turns to computation on those inputs.
- He introduces an algorithm informally as a sequence of simple steps that solves a problem.
- The formal definition must clarify both what counts as a simple step and what it means to solve a problem.
- Jaffe connects the historical idea of algorithms to Al-Khwarizmi’s procedures for solving quadratic equations.
- A specification describes the required input-output behavior, while an implementation gives the steps used to produce that behavior.
- Multiplication can be specified as a function taking two natural numbers and returning their product, with the numbers encoded as bit strings.
- Jaffe introduces Boolean circuits as a first formal model for defining simple computational steps.
- AND outputs 1 only when both input bits are 1; OR outputs 0 only when both inputs are 0.
- NOT takes one bit and flips it, providing three basic operations for constructing more complex functions.
- The majority function takes bits A, B, and C and outputs 1 when at least two inputs are 1.
- Jaffe implements majority as (A AND B) OR (B AND C) OR (A AND C).
- The example shows how an implementation can be checked against the function’s input-output specification.
- Two-bit XOR outputs 1 when its inputs differ and 0 when they match.
- The implementation combines the cases A AND NOT B and NOT A AND B with OR.
- Three-bit XOR outputs 1 exactly when the inputs contain an odd number of ones.
- Three-bit XOR can be computed as XOR2(XOR2(A, B), C).
- The intermediate XOR result records whether A and B contain an odd number of ones; XOR with C updates the parity.
- Jaffe emphasizes reusing a completed XOR2 circuit as a subcomponent rather than rebuilding its gates from scratch.
- A Boolean circuit is represented as a directed acyclic graph, or DAG, with no directed cycles.
- Circuit vertices perform operations such as AND, OR, and NOT, while directed edges carry bit values between gates.
- Jaffe draws the XOR implementation as interconnected gates and then composes copies of that circuit to build XOR3.
- Jaffe’s formal circuit definition uses n input vertices, s computation vertices, and m designated output bits.
- Input vertices are labeled x0 through x(n−1); AND and OR gates have two incoming edges, and NOT gates have one.
- Possible physical implementations of Boolean operations include transistors, vacuum tubes, chemical reactions, DNA-based systems, and marbles.
- A DAG has a topological layering in which every edge goes from a lower-numbered layer to a higher-numbered layer.
- Jaffe proposes placing circuit inputs in layer zero and evaluating gates one layer at a time.
- This ordering ensures the values needed by a gate have already been computed before that gate is evaluated.
- A circuit with n input bits and m output bits computes a function f when C(x) = f(x) for every possible input x.
- The circuit is the implementation, while f is the specification describing the required behavior.
- Jaffe closes by previewing a discussion of why AND, OR, and NOT are chosen and whether other operations could serve the same purpose.
Transcript excerpt
0:02 Wow. All right. Uh, hi everybody. Hopefully you can hear me better now. I fixed the microphone. I fixed the projector. Everything's fixed. Hopefully nothing will ever break again. Um, I wanted to get a quick check on how everybody's day is going. In my classes, I usually do this thing called a thermometer. This means I'm doing great. This means worst day ever. I'm like here. How's everybody doing? All right, that's pretty solid for a 6 PM in the evening class. Pretty good. Okay, so this we can get a little bit of a better uh first of all, I can look at you guys more because I'm not looking at
0:49 the trajectory for you guys. Just a couple quick logistical notes before we get started on material. Um the class web page is live now on Brew andLearn. So you can go there for all of the syllabus information. Make sure you join the grade scope class if you're not automatically enrolled and join EdStemp because that's where all the recordings go. That's where all the lecture notes go. So if you have any problems getting there, let me know. Um, and just one click quick clarification because I realized I might have said this confusingly last time. All your exams in this class are in person. There's no take-home exams. It's just that the final exam is going to be in a different room. So, all of your exams are in person. The first two are in this room
1:37 during lecture and the third will be in some random room. Just want to make that clear. Okay. So, last time uh we talked about how to represent some basic objects. We talked about our goals for the class which is first to show how we can represent data and then to show what
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Eli Jaffe.