Step 1 of 6 in Computer Science
Computation & Abstraction
What a computation is, and why abstraction is the field's core move. Citation needed
The whole, before the parts
A computation is the transformation of input into output by rules so explicit that nothing is left to judgment — rules a clerk, a machine, or a child could follow without understanding them. The single idea that carries this topic, and the whole field after it, is abstraction: once a procedure works, you seal it behind an interface, forget how it works, and build the next layer on top. Everything a computer does is layers of procedures each trusting the one below, and the discipline of computer science is largely the discipline of drawing those layer boundaries well. Citation needed
Terminology and core concepts
-
Computation as rule-following
A computation is a sequence of small steps, each completely determined by the current state — the total information the process holds at an instant — and a fixed rule; no step requires insight, only obedience. Citation needed
- What determines the next step of a computation?
- the current state and the fixed rule Citation needed
- What is the state of a computation?
- all the information the process holds at that instant Citation needed
- Why can a machine run a computation without understanding it?
- every step is fixed by rule, none by judgment Citation needed
- Is long division by hand a computation?
- yes — fixed rules transform input digits to output digits Citation needed
- Does a computation need electronics?
- no — any rule-follower can run one Citation needed
-
The algorithm
An algorithm is a computation's recipe: finite in description, unambiguous at every step, and guaranteed to halt with the right answer on every valid input — which separates it from a mere heuristic, a rule of thumb that usually helps but promises nothing. Citation needed
- What must an algorithm do on every valid input?
- halt with a correct answer Citation needed
- What does a heuristic lack that an algorithm has?
- a guarantee of correctness Citation needed
- Why must an algorithm's description be finite?
- an infinite recipe could never be communicated or run Citation needed
- Is "stir until it looks right" a step of an algorithm?
- no — it is ambiguous, needing judgment Citation needed
- Can one problem have many algorithms?
- yes — differing in cost, not in answers Citation needed
-
Everything is encoding
Machines manipulate only symbols, so every object a computation touches must first be encoded — written as symbols under an agreed convention; the smallest symbol is the bit, a single two-way distinction, and n bits distinguish 2ⁿ cases. Citation needed
- What is a bit?
- one two-way distinction: 0 or 1 Citation needed
- How many cases can 8 bits distinguish?
- 256 Citation needed
- How many bits are needed to distinguish 1000 cases?
- 10, since 2¹⁰ = 1024 Citation needed
- What makes a string of bits mean a number rather than a letter?
- the agreed encoding convention, nothing in the bits Citation needed
- Why must data be encoded before it is computed on?
- rules operate on symbols, not on things Citation needed
-
Abstraction and the interface
Abstraction is deliberate forgetting: a component exposes an interface — what it promises — and hides its implementation — how it delivers; callers who depend only on the promise survive any change to the insides. Citation needed
- What does an interface state?
- what a component promises, not how it works Citation needed
- What is an implementation?
- the hidden mechanism that delivers the promise Citation needed
- When can an implementation be swapped without breaking callers?
- when callers depend only on the interface Citation needed
- What goes wrong when code depends on hidden detail?
- any internal change can break it Citation needed
- Why is abstraction called deliberate forgetting?
- it lets you use a part while ignoring its insides Citation needed
-
Layers
Systems are built as towers of abstraction, each layer implemented in terms of the one below and presenting a cleaner interface to the one above; this is why a programmer can be productive knowing almost nothing about electrons. Citation needed
- What does each layer in a tower of abstractions rely on?
- the interface of the layer just below Citation needed
- Why can a programmer ignore the physics of the machine?
- lower layers hide it behind stable interfaces Citation needed
- What is a leaky abstraction?
- a layer whose hidden detail still shows through Citation needed
- What is the cost of adding a layer?
- some overhead, paid for in simplicity above Citation needed
-
Procedures and composition
A procedure is a named, reusable piece of computation with its own inputs and output; composition — feeding one procedure's output to another — is how small correct parts become large correct wholes. Citation needed
- What does naming a procedure buy?
- reuse without restating the steps Citation needed
- What is composition of procedures?
- one procedure's output becomes another's input Citation needed
- Why does composition preserve correctness?
- each part meets its interface, so the whole meets its spec Citation needed
- What is decomposition?
- splitting a problem into procedures solved separately Citation needed
-
Recursion
A recursive procedure solves a problem by calling itself on a smaller instance, and it is sound for the same reason induction is: a base case anchors it, and each call strictly shrinks toward that base. Citation needed
- What anchors a recursive procedure?
- a base case solved without further calls Citation needed
- What must each recursive call do to guarantee halting?
- strictly shrink toward the base case Citation needed
- What proof technique justifies recursion?
- induction Citation needed
- What happens to a recursion with no base case?
- it never halts Citation needed
- What is factorial of n, written recursively?
- n × factorial(n - 1), with factorial(0) = 1 Citation needed
-
Programs are data
Because an algorithm's description is itself a finite string of symbols, it can be encoded and handed to another program as input; an interpreter is a program that reads such a description and runs it, which is why one machine can run every program. Citation needed
- Why can a program be input to another program?
- its description is a finite string of symbols Citation needed
- What does an interpreter do?
- reads a program's description and carries out its steps Citation needed
- What makes a general-purpose computer general?
- it interprets any encoded program, needing no rebuild Citation needed
- What single idea do interpreters rest on?
- programs are data Citation needed
Problems that prove it
-
Encode the number 45 in binary, then decode it back.
Drills: encoding as convention — bits mean nothing until read by the rule that wrote them.
Derivation steps
- Repeatedly divide by 2, keeping remainders: 45 → 22 r1, 22 → 11 r0, 11 → 5 r1, 5 → 2 r1, 2 → 1 r0, 1 → 0 r1.
- Read remainders last-to-first: 101101.
- Decode by place value: 32 + 0 + 8 + 4 + 0 + 1 = 45. ✓
- Note the convention did the work: the same bits under a different encoding would mean something else entirely.
Citation needed
-
Run Euclid's procedure for the greatest common divisor on 252 and 105, by hand.
Drills: following an algorithm purely by rule — state, step, repeat until the halting condition.
Derivation steps
- Rule: replace the pair (a, b) with (b, a mod b); halt when the second number is 0.
- State (252, 105): 252 mod 105 = 42, so next state is (105, 42).
- State (105, 42): 105 mod 42 = 21, so (42, 21).
- State (42, 21): 42 mod 21 = 0, so (21, 0). Halt.
- Answer: 21. Check: 252 = 21 × 12 and 105 = 21 × 5. ✓
- It halts because the second number strictly shrinks — the same shrinking argument that justifies recursion.
Citation needed
-
Trace the recursive factorial of 4 down to its base case and back.
Drills: the descend-then-return shape of every recursion.
Derivation steps
- factorial(4) = 4 × factorial(3) — suspended, waiting.
- factorial(3) = 3 × factorial(2); factorial(2) = 2 × factorial(1); factorial(1) = 1 × factorial(0).
- Base case: factorial(0) = 1. The descent stops.
- Return upward: 1 × 1 = 1, then 2 × 1 = 2, then 3 × 2 = 6, then 4 × 6 = 24.
- Answer: 24. Each shrinking call was anchored by the base case, as induction demands.
Citation needed
-
A procedure promises: "given a sorted list, return whether x is in it." A caller passes an unsorted list and gets a wrong answer. Whose defect is it?
Drills: reading an interface as a contract with obligations on both sides.
Derivation steps
- The interface states a precondition: the list is sorted.
- The implementation's promise is conditional on that precondition.
- The caller broke the precondition, so the promise was never in force.
- The defect is the caller's; the implementation owes nothing on invalid input.
- Moral: an interface binds both sides — the promise and the preconditions are equally part of it.
Citation needed
-
How many bits does a code need to give every one of 26 letters, 10 digits, and 20 punctuation marks its own pattern?
Drills: sizing an encoding with the 2ⁿ rule.
Derivation steps
- Count the cases: 26 + 10 + 20 = 56 symbols.
- Find the least n with 2ⁿ ≥ 56.
- 2⁵ = 32 is too few; 2⁶ = 64 suffices.
- Answer: 6 bits, with 8 patterns to spare.
Citation needed
Sources
- Harold Abelson and Gerald Jay Sussman, Structure and Interpretation of Computer Programs — abstraction, composition, and programs-as-data as the heart of the field.
- Donald Knuth, The Art of Computer Programming, Volume 1 — the careful definition of what an algorithm is.
- Charles Petzold, Code: The Hidden Language of Computer Hardware and Software — encoding and layered abstraction told from the bit upward.
Learning path
Continue through Computer Science in order, using the concepts above to connect this topic to the next.