COMPSCI110 · Introduction to Computer Systems
Algorithms & Pseudocode
Module 5 of University of Auckland COMPSCI110 steps back from hardware to the idea of a computation itself: what an algorithm formally is, and how to express one in pseudocode before writing real code, using just three building blocks — sequence, selection and iteration. Important assessment note: Module 5 is examined only in the mid-semester test — it is NOT on the final exam. So learn it thoroughly for the test, then know you can de-prioritise it during final-exam revision.
What this chapter covers
- 01The formal definition of an algorithm: a well-ordered collection of unambiguous, effectively computable operations that produces a result and halts in finite time
- 02Pseudocode's role: between natural language (ambiguous) and a programming language (fussy); it designs algorithms and is not executed
- 03The three primitive constructs — Sequential (one task at a time), Conditional/Selection (if-then-else on a True/False test), Iterative/Loop (while: a continuation condition + a body)
- 04while vs do/while: while may run the body zero times; do/while runs the body at least once
- 05Assignment uses ← (an arrow); = is reserved for comparison — a common trap in trace questions
- 06Desk-checking pseudocode with a trace table: track each variable's value line by line to predict the output
- 07ASSESSMENT NOTE: Module 5 appears only in the mid-semester test (Teleform MCQ, restricted book), not on the final exam
Trace a factorial loop by hand
input n · fact ← 1 · i ← 1 · while i ≤ n { fact ← fact × i · i ← i + 1 } · output fact
- +1Initialise before the loop: read n = 4, set fact ← 1 and i ← 1. Note ← is assignment, not comparison.
- +1Iterations 1–2: i=1, condition 1 ≤ 4 true → fact = 1 × 1 = 1, i ← 2. i=2, 2 ≤ 4 true → fact = 1 × 2 = 2, i ← 3.
- +1Iterations 3–4: i=3, 3 ≤ 4 true → fact = 2 × 3 = 6, i ← 4. i=4, 4 ≤ 4 true → fact = 6 × 4 = 24, i ← 5.
- +1Loop guard now: i = 5, condition 5 ≤ 4 is false → exit the loop and output fact = 24. That is 4! = 24. ✓
Key terms
- Algorithm
- A well-ordered collection of unambiguous and effectively computable operations that, when executed, produces a result and halts in a finite amount of time. All four properties matter: well-ordered (definite step order), unambiguous/computable, produces an observable result, and terminates (no infinite loop).
- Pseudocode
- A structured, language-neutral notation for describing algorithms that sits between natural language and a real programming language. It is precise enough to be unambiguous but is meant to be read and reasoned about, not compiled or run.
- Sequence
- The simplest control structure: operations carried out one after another, in order — a computation, an input or an output at each step. Everything else is built by nesting selection and iteration around sequences.
- Selection (conditional)
- The if-then-else structure: evaluate a True/False condition and take one branch or the other. It lets an algorithm make decisions, and it is one of the three primitive constructs from which any algorithm can be built.
- Iteration (loop)
- Repeating a body of operations. A while loop tests its continuation condition before each pass, so the body can run zero times; a do/while tests after, so the body always runs at least once. Getting the boundary condition right is the crux of trace questions.
- Assignment (←)
- Storing a value in a variable, written with a left arrow: x ← 5 puts 5 into x. It is deliberately distinct from = , which pseudocode reserves for comparison (testing equality). Confusing the two is a frequent source of trace-table errors.
Algorithms & Pseudocode FAQ
Is Module 5 on the final exam?
No. Algorithms & pseudocode (Module 5) is assessed only in the mid-semester test, not on the final exam — the final's per-module breakdown covers Modules 1–4 and 6–11 and omits Module 5 entirely. So study it fully for the test, but during final-exam revision you can safely spend that time on the heavier exam modules such as Operating Systems and Compilers. Always confirm the current split on Canvas.
What are the three control structures, and why only three?
Sequence (do steps in order), selection (if-then-else — choose a branch on a condition) and iteration (loop — repeat a body while a condition holds). These three are provably enough to express any algorithm, which is why pseudocode needs no more than them. Programs in real languages are just these constructs nested and combined, with concrete syntax added.
Can AI help me with algorithms and pseudocode in COMPSCI110?
Yes, as a study aid. Sia can build a trace table with you row by row, explain why a loop runs n times rather than n−1, and turn an English description into clean pseudocode using the three constructs. Use it to learn the method and rehearse for the mid-semester test — it explains and checks your reasoning but does not sit the test for you, and the University of Auckland's academic-integrity rules apply to that controlled assessment.
What's the difference between a while loop and a do/while loop?
A while loop checks its condition first, so if the condition is false at the start the body never runs (zero iterations are possible). A do/while runs the body once and then checks, so the body always executes at least once. In a trace question, spot which one you have before you start: it changes whether the first pass is guaranteed and can change the final answer.
What makes a set of steps an actual algorithm?
It must satisfy the formal definition: the steps are well-ordered (their sequence is definite), each is unambiguous and effectively computable, the process produces an observable result, and it halts in a finite time. A recipe that could loop forever, or that contains an ambiguous 'do it nicely' step, fails the definition — termination and unambiguity are the properties students most often overlook.
Exam move
Because Module 5 is test-only, front-load it: master it before the mid-semester test and don't carry it into final-exam revision. The examinable skill is desk-checking, so practise trace tables until they're mechanical — one variable per column, update one line at a time, and always re-test the loop condition after each pass. Drill the boundary cases that trip people up: i ≤ n versus i < n, and while (test-first, possibly zero passes) versus do/while (test-after, at least one pass). Keep the notation straight — ← assigns, = compares — because MCQ distractors are built on that confusion. Memorise the four properties of the formal algorithm definition (well-ordered, unambiguous/computable, produces a result, halts) as they're a favourite short-answer item, and rehearse turning a plain-English task into pseudocode using only sequence, selection and iteration.
Working through Algorithms & Pseudocode in COMPSCI 110? Sia is AskSia’s AI Computer Science tutor — ask any COMPSCI 110 Algorithms & Pseudocode question and get a clear, step-by-step explanation grounded in how COMPSCI 110 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.