Nov 23, 20255 min read

CS50 Lecture 0 — Scratch: Understanding How Computers Think

My notes from CS50 Lecture 0 covering how computers process data, binary, abstraction, algorithms, and pseudocode—the foundations of computer science.

Angga Wisman Nugraha H F · Computer Science · cs50 · computer-science · scratch

Lecture 0 — Scratch

These are my personal notes from CS50 Lecture 0. Rather than simply summarizing the lecture, I try to explain the concepts in my own words and connect them with how I understand computers.


How Computers Process Data

At its core, programming is simply about taking an input, processing it, and producing an output to solve a problem.

Imagine I want to count how many people attend an event.

For every person who arrives, I raise one finger. This is actually a counting system called unary (base-1) because every object is represented directly by one symbol.

The computer follows the same principle, but instead of fingers it uses transistors.

A transistor acts like a tiny electrical switch:

  • ON → 1
  • OFF → 0

These two states are known as binary digits, or simply bits.

By combining billions of these tiny switches together, computers can represent numbers, text, images, videos, and even entire operating systems.

Much like:

  • Morse Code
  • Afrikaans click consonants
  • Whistling languages

binary doesn't carry meaning by itself.

Instead, meaning comes from patterns.


Hardware Perspective

If we look deeper into how hardware works:

  • The CPU contains billions of transistors connected together through logic gates such as:
    • AND
    • OR
    • NOT
    • NAND
    • NOR
    • XOR
  • These logic gates determine whether electricity should continue flowing or stop.

The faster a CPU can switch these transistors, the faster it can perform computations.

RAM

RAM temporarily stores data that the CPU is currently using.

Instead of recalculating everything repeatedly, the CPU retrieves information from RAM whenever necessary.

However, communication between the CPU and RAM introduces latency.

To reduce this delay, modern processors include CPU Cache, which is built using SRAM (Static Random Access Memory).

Cache memory is:

  • Much faster than RAM
  • Much smaller
  • Located directly inside or extremely close to the CPU

Both RAM and Cache are volatile memory, meaning they only retain data while power is supplied.

For permanent storage, data must eventually be written to long-term storage devices such as:

  • SSD
  • HDD

Binary and Bytes

Computers use the base-2 number system, called binary.

One binary digit is called a bit.

Eight bits form one byte.

Example:

11111111

Equals:

255

which is the largest number that can be represented using one unsigned byte.


The Real Question

Understanding binary is only the beginning.

The more important question is:

How do we design algorithms that solve problems efficiently?


Abstraction

Between input and output, there is a hidden layer called abstraction.

This abstraction is what we call an algorithm.

An algorithm describes the sequence of steps required to transform input into the expected output.

Between input and output lies an abstraction called an algorithm—a step-by-step process that describes how to solve a problem efficiently.


Example: Finding Harry's Phone Number

Suppose you want to call someone named Harry, and you only have a printed phone book.

There are several possible algorithms.

Start from the first page.

Turn pages one by one until you find Harry.

Complexity:

n

because in the worst case you may need to inspect every page.


Option 2 — Two Pages at a Time

Turn two pages each time.

Although faster in some situations, it may accidentally skip the correct page.

This is not a reliable algorithm.


A much better approach.

  1. Open the phone book in the middle.
  2. Compare Harry's name with the page.
  3. Eliminate half of the remaining pages.
  4. Repeat.

Complexity:

log₂ n

Instead of searching every page, each step removes approximately half of the remaining possibilities.

This is dramatically faster for large datasets.


Why Binary Search Is Faster

Suppose there are 1,024 pages.

Linear Search:

Worst case:
1024 checks

Binary Search:

1024
512
256
128
64
32
16
8
4
2
1

Only about 10 checks are required.

This illustrates one of the most important ideas in computer science:

Choosing a better algorithm often matters more than using faster hardware.


Pseudocode

Before writing code, programmers often describe their algorithm using pseudocode.

Pseudocode focuses on logic rather than programming language syntax.

It allows developers, managers, designers, and other stakeholders to discuss how a solution works before implementation.

Example:

1  Pick up phone book
2  Open to middle of phone book
3  Look at page
4  If person is on page
5      Call person
6  Else if person is earlier in book
7      Open to middle of left half of book
8      Go back to line 3
9  Else if person is later in book
10     Open to middle of right half of book
11     Go back to line 3
12 Else
13     Quit

Notice that pseudocode is easy to understand regardless of the programming language eventually used.


Key Takeaways

  • Programming is about transforming input into output.
  • Computers process information using billions of transistors.
  • Binary uses only two states: 0 and 1.
  • Eight bits make one byte.
  • Hardware speed matters, but choosing the right algorithm matters even more.
  • Abstraction helps us focus on solving problems without getting distracted by unnecessary implementation details.
  • Pseudocode bridges human thinking and actual programming.

References

Related articles