Algorithm Basics: How to Trace and Analyze Simple Algorithms
A
What is an algorithm?An algorithm is a finite, ordered set of instructions for completing a task or solving a problem. A recipe is a familiar example: it takes ingredients as input and gives you a finished dish as output. In computer science, the instructions need to be precise enough that a computer can follow them without guessing.Algorithms can be written in plain language, pseudocode, or a programming language. The language may change, but the underlying steps—and their logic—are what matter.A useful way to describe an algorithm is:Atlas · Scribe AI
Subject deep dives · November 7, 2026
- Input: the information it receives
- Process: the steps it follows
- Output: the result it produces
[4, 9, 2, 7]. One approach is to remember the largest value seen so far:textlargest = first value
for each remaining value:
if value > largest:
largest = value
return largestTrace the variables one step at a time:| Value checked | Largest before | Largest after |
|---|---|---|
| Start at 4 | — | 4 |
| 9 | 4 | 9 |
| 2 | 9 | 9 |
| 7 | 9 | 9 |
9. The trace table makes the logic visible: largest changes only when the current value is greater.When tracing an unfamiliar algorithm, write down each variable and update it after every instruction. This is often more reliable than trying to hold the whole process in your head.Three building blocks to recognizeMost introductory algorithms combine three basic structures:1. Sequence: instructions run in order.
2. Selection: a condition chooses between paths, often with if and else.
3. Iteration: a loop repeats instructions while a condition holds or for each item in a collection.In the largest-value example, the comparison is selection and the repeated check is iteration. If you can mark these structures in pseudocode, you can often predict what the algorithm will do before running it.Common misconceptions“An algorithm is the same thing as a program.” An algorithm is the method; a program is an implementation of that method in a programming language. Different programs can implement the same algorithm.“If it works on one example, it is correct.” A single test may miss edge cases. For the largest-value algorithm, test a one-item list, a list of negative numbers, and a list where the largest value appears first or last.“Fewer lines means a faster algorithm.” Code length does not reliably tell you how much work the computer performs. A short loop nested inside another loop can do far more operations than a longer sequence of simple steps.“Big O tells the exact running time.” Big O describes how the amount of work grows as input size grows, not a stopwatch result for every computer. If a method checks each of n items once, its work grows roughly in proportion to n, written O(n).A 20-minute practice planMinutes 1–5: Identify the structure. Take a short pseudocode example and label its sequence, selection, and loops.Minutes 6–12: Trace it. Make a table for the variables. Test a typical input and then a boundary case, such as an empty or one-item input where appropriate.Minutes 13–17: Explain it. In two or three sentences, state the input, output, and why the steps produce that output. If you cannot explain a condition, inspect it closely.Minutes 18–20: Estimate the work. Count how often the main operation runs as the input grows. Does doubling the list roughly double the checks, or does it create many more?Try this routine with searching, counting, or finding a minimum. If your notes are in a PDF or document, Scribe can help turn them into practice questions—but tracing the steps yourself is what builds the skill.