CS110A Week 9 Day 2 lesson on 10/15/2026
Watch on YouTube →
Overview
In CS110A, Indika Walimuni models a four-digit number reversal using modulo 10, floor division, positional place values, and a function that returns its result. The lesson then introduces lossless and lossy compression through dictionaries, Huffman coding, JPEG quantization, and video frames, reviews relational database tables and primary keys, and begins an interview-style clock-angle problem.
Key takeaways
- A digit can be extracted without strings by shifting it into the ones place with floor division and then applying modulo 10.
- For 1234, reversing the digits requires the positional sum 1000 × 4 + 100 × 3 + 10 × 2 + 1; a function should return this result instead of printing it internally.
- Dictionary-based LZ-style compression and Huffman coding are lossless when the required decoding information is available, while JPEG quantization discards information and is lossy.
- Huffman coding saves space by assigning shorter bit sequences to frequent symbols, including repeated pixel values in image data.
- Relational database primary keys uniquely identify records and allow related tables, such as inventory and order history, to be connected.
- For ambiguous interview problems such as the clock-angle exercise, diagrams and test cases like 3:00 and 3:30 help reveal the intended input, output, and general rule.
Chapters
- The task is to reverse a positive integer, with 1234 expected to produce 4321.
- The solution must avoid strings, text manipulation, and imported modules, including math modules.
- Indika Walimuni recommends adapting code from the earlier first-and-last-digit swapping exercise.
- For input 1234, the reversed digits are assembled as 4 × 1000 + 3 × 100 + 2 × 10 + 1.
- The key subproblem is isolating each digit, then placing it in the corresponding position in the result.
- The earlier digit-swapping exercise provides a starting point because both problems require repeated digit extraction.
- Applying 1234 % 10 yields 4, the least significant digit in the ones place.
- Modulo 10 generalizes to any positive integer for finding its rightmost digit.
- The instructor frames the example as a way to identify a reusable pattern rather than solve only one input.
- For 1234, integer division by 1000 isolates the leading digit 1.
- The divisor depends on the digit's place: 10,000 is used to reach the leading digit of a five-digit number.
- For an interior digit, first shift it to the ones place with floor division, then use modulo 10 to extract it.
- To isolate 2 from 1234, floor-divide by 100 to get 12, then take 12 % 10.
- To isolate 3, floor-divide by 10 to get 123, then take 123 % 10.
- The extraction pattern keeps modulo 10 fixed while the floor-division divisor changes with the target digit's position.
- The four extracted digits are combined as 1000 × first + 100 × second + 10 × third + fourth.
- The plan calls for calculating each digit, constructing the reversed value, and returning it from the function.
- Indika emphasizes that a function should return a computed result rather than print it internally.
- The English-language plan is translated directly into Python, with a public interface that describes the function's purpose and input.
- Test calls include 5678, which should return 8765, and 1234, which should return 4321.
- Testing belongs in the main program, while a final evaluation step considers correctness and possible improvements such as speed or memory use.
- Compression reduces the space needed for large data and can make internet transfers and processing faster.
- A camera image described as 4 MB can be compressed to 1 MB, allowing more images to fit in limited storage.
- PNG and JPEG are introduced as familiar image formats associated with compressed image data.
- A dictionary maps keys to values, such as 1 to “department,” so repeated words can be represented by short codes.
- The phrase “department of redundancy department” is represented using dictionary entries and the sequence 1, 2, 3, 1.
- The LZ-style example compresses repeated phrases such as “hello” and “my friend”; the encoded data and dictionary together must be retained for decompression.
- The lesson describes the example as lossless because decoding with the same dictionary recovers the original text exactly.
- Huffman coding assigns shorter bit sequences to more frequent symbols and longer sequences to less frequent ones.
- The instructor identifies English letters such as E as frequent examples and Q as a comparatively rare example.
- Students practice decoding dictionary-based text and bit sequences, then choose the shortest Huffman code for the most frequent pixel value.
- Students are asked to complete a course evaluation survey available through the Canvas dashboard.
- A procrastination-strategies lesson is played, though the transcript provides little detail from its contents.
- The midterm is described as requiring about 10 hours; students are encouraged to distribute the work across a week, for example by writing one essay paragraph per day.
- The instructor notes that the previous Tuesday's Zoom lesson was not recorded and says it will be re-recorded.
- JPEG is expanded as Joint Photographic Experts Group, the name of the group associated with the image format.
- Huffman coding can reduce image data by assigning short bit patterns to frequent pixel values; the example contrasts a two-bit code with an eight-bit binary value.
- Repeated pixel values across an image can be encoded compactly, reducing the amount of data needed to represent the image.
- Quantization reduces image detail by dropping or rounding parts of RGB values, such as changing 255, 64, and 231 to coarser values.
- The discarded values cannot be recovered exactly, so quantization is lossy even if an approximate value is reconstructed.
- Video is described as rapidly displayed still frames, commonly around 25 or 30 frames per second.
- Video compression can encode individual frames using image techniques such as JPEG; the lesson notes that lossy compression does not preserve the full original.
- A relational database stores information in tables organized into rows and columns.
- A column is a field, while a row of related values is a record.
- The inventory-table example has five columns and three data records, separate from its header row.
- A primary key uniquely identifies each record, unlike a field such as quantity that may repeat.
- Student IDs and inventory item numbers are offered as examples of possible primary keys.
- A shared key can connect an inventory table to an order-history table and support database joins.
- The next exercise is presented as a concise interview problem whose ambiguity tests communication as well as coding.
- Students must interpret the relationship between the hour hand and the faster-moving minute hand.
- The input is described as an angle alpha representing the hour hand's position from midnight, so the clock's geometry and domain knowledge matter.
- Indika recommends drawing an analog clock and working through sample positions before attempting a formula.
- Students consider the 360-degree circle and how far the minute hand moves during one hour.
- Testing whole-hour, half-hour, and quarter-hour cases helps clarify the relationship between the hands.
- The goal is to infer a general formula from the clock-hand relationship rather than count rotations individually.
- The class checks reasoning against known times to see whether a proposed rule gives the expected minute-hand angle.
- The discussion focuses on relating the input hour-hand angle to the minute hand's position within the current hour.
- The function is expected to take alpha, the hour hand's angle from midnight, and return the minute-hand angle.
- At 3:00, alpha is 90 degrees and the minute hand is at 12, giving an output angle of 0 degrees.
- The example is used to clarify that the output concerns the minute hand, not the hour hand.
- At 3:30, the minute hand points to 6, or 180 degrees from 12.
- Students are asked to test a proposed rule with alpha = 330 degrees and check whether it produces the expected 180-degree minute-hand position.
- The assignment is to draw a clock diagram, develop and test the pattern, and bring the problem back for discussion the following Tuesday.
Transcript excerpt
0:00 Morning guys. So let's um begin. [clears throat] So this is our agenda today. Um take a look guys. We have a talk. Look at the audience going down by the day. So only we have three now. Okay. So, um uh take a look. Today we have a talk at this um from Stanford research actually. Um yeah, make sure to attend like guys.
0:50 Okay. So, uh so let's do let's solve that problem. So, um the reverse number problem, right? So, okay. All right. So, and this one is uh uh kind of similar to what we did, right? So, I recommend like, you know, um taking that code and and then um um um the the Tuesday code. Okay. So, I'm going to um copy this and then this is my code. Yeah. So, I'm going to take this code
1:39 and and change. Okay. So, uh kind of um I don't need this understand, right? So, I'm going to replace it. Okay. And then um Okay. Okay. So what is the input? This 40 positive integer, right? So this is the input. What is the vocabulary recognizing the input? What is it? >> Good morning. What what is the vocabulary of um recognizing input? Yeah. Word word given, right? All right. So,
2:30 okay. All right. So, um and then then output is basically reverse number. Okay. Yeah. Reverse number. This the output. Okay. So, do we have restriction for this one? Yeah. Right. So all of these without using strings text manipulation or importing any modules including math modules. So don't use right. All right. So that those are the restrictions. All right guys, we are solving this problem. Okay. Um reverse a number. Okay.
3:21 All right. Let me grab this into here. Okay. All right. So, I'm going to uh remove this
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
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, indika walimuni.