About this book
Algorithms + Data Structures = Programs was published by Prentice-Hall in 1976. Its author, Niklaus Wirth, was a professor at the Swiss Federal Institute of Technology in Zurich, known as ETH, and the designer of the programming language Pascal. The book grew out of his teaching. It was meant as a textbook for students who already knew how to write simple programs and needed to learn how to build them well.
The title is the thesis. A program, Wirth argues, is not a sequence of instructions with some data attached. It is the union of two things that must be designed together: the algorithms that describe what is done, and the data structures that describe what it is done to. Choose the data structure badly and no algorithm will rescue the program. Choose an algorithm without thinking about the data and the program will be slow, clumsy or wrong. The two are halves of one design.
This may sound obvious now. In the early 1970s it was a needed correction. Much teaching of programming focused on control flow, on how to arrange statements and loops, and treated data as a matter of declaring variables. Wirth, along with C. A. R. Hoare and others, insisted that the organisation of data deserved as much care as the organisation of steps, and that the two shaped each other at every point.
The book also embodies a method. Wirth had argued in a 1971 paper that programs should be developed by stepwise refinement: begin with a plain statement of the task, then refine it gradually, replacing each abstract step with more concrete ones, until the program is complete. At every stage the programmer decides not only what to do next but how to represent the data involved. Algorithms + Data Structures = Programs shows this method at work across many problems.
All the examples are written in Pascal, which Wirth had designed partly for teaching. Pascal's clear syntax and its rich facilities for defining data types made it well suited to the book's aims. Readers who do not know Pascal can read the code almost as structured pseudocode, since the language was built to be read.
The intended reader is a student or programmer ready for a second course: someone who can write programs and wants to understand the fundamental structures and methods on which serious software rests. The book is compact and dense. It assumes some mathematical maturity, especially in its analysis of how long algorithms take, but it does not assume advanced mathematics.
The question the book sets out to answer is this: what are the basic ways of organising data and computation, how do they relate, and how should a programmer choose among them? Its answer is given not as a catalogue but as a demonstration, problem after problem, of design decisions made with care.
The author
Niklaus Wirth was born in 1934 in Winterthur, Switzerland, and died in 2024. He studied electronic engineering at ETH Zurich, then went to North America, earning a master's degree at Laval University in Quebec and a doctorate at the University of California, Berkeley, in 1963. He taught at Stanford for several years before returning to ETH in 1968, where he spent the rest of his career.
Wirth's life's work was the design of programming languages and systems. He worked on Euler and then ALGOL W, a refinement of ALGOL 60 that was proposed as its successor but not adopted by the committee, which chose a far more complex design instead. Wirth's response was to design Pascal, released around 1970, a small, clean language for teaching and for practical programming. Pascal became one of the most widely taught languages in the world and, through compact implementations, spread to microcomputers in the late 1970s and 1980s.
He went on to design Modula and Modula-2, which added modules for building larger systems, and later Oberon, which he developed with Jurg Gutknecht together with an entire operating system of the same name. He also led the design of workstations at ETH, including the Lilith, built to run Modula-2. In 1984 he received the Turing Award, the highest honour in computer science, for his work on languages.
Through all of this ran a single conviction: simplicity is a condition of reliability. Wirth distrusted features added for their own sake, languages that tried to please everyone, and systems that grew without discipline. In a well-known essay of 1995, A Plea for Lean Software, he argued that software was growing bloated faster than hardware was growing fast. His books are written in the same spirit: short, exact and without padding.
Algorithms + Data Structures = Programs sits at the centre of this career. It came after Pascal and before Modula-2, and it shows Wirth at his most characteristic, teaching through carefully built examples that a small set of ideas, used well, is enough to construct substantial programs, including a compiler. He later reworked the book for Modula-2 in the 1980s under the title Algorithms and Data Structures, and again for Oberon.
The shape of the argument
The book moves from the simple to the complex in a deliberate order. It begins with the fundamental data structures that a language like Pascal provides directly: basic types, arrays, records, sets and sequential files. It explains what each is, how it is represented in a machine, and what operations it makes cheap or expensive. This opening establishes the vocabulary for everything that follows.
It then turns to sorting, which serves as an extended case study. Sorting is a single, well-defined problem with many solutions, and comparing them teaches how algorithms trade time against memory and simplicity, and how the structure of the data, whether held in memory as an array or stored on a sequential file, changes which methods are suitable.
Next comes recursion, both as a way of defining algorithms and as a way of thinking about problems whose structure is itself recursive. This leads naturally to backtracking, a method of searching for solutions by trying possibilities and retreating from dead ends.
The book then moves to dynamic data structures, built with pointers, which can grow and shrink while a program runs. Lists and trees appear here, along with methods for keeping trees balanced and for storing data on external devices, and techniques for finding items quickly by computing where they should be.
The final part turns to language structures and compilers. Wirth shows how a programming language can be described precisely by a grammar, how a program can recognise whether a text follows that grammar, and how a small compiler for a tiny language can be built from the methods developed earlier. This last part is the book's demonstration of its own thesis: a compiler, often thought of as a mysterious piece of software, turns out to be an ordinary program built from well-chosen algorithms and data structures.
The movement, then, is from static structures to dynamic ones, from single problems to general methods, and finally to a complete program that ties them together. Each part depends on what came before, and the closing compiler is both a capstone and a proof that the pieces fit.
A word on how the parts relate. The book is not a set of separate topics bound together. Each part prepares a tool that a later part uses. The basic types and their costs are needed to analyse sorting. Sorting introduces the habit of counting operations, which is needed to judge trees. Recursion is needed for trees, for backtracking and for the parser. The final compiler uses tables, recursion and careful data design all at once. A reader who skips the early parts will find the later ones harder than they need to be, and a reader who follows the order will find each part easier because of the last.
The book also teaches by its programs as much as by its prose. Wirth's code is compact and consistent, with names that say what things are and structures that mirror the refinement that produced them. Reading it closely is itself a lesson in how to write. Many readers have said that they learned more about programming style from Wirth's examples than from books devoted to style.
Algorithm and data structure are one design
The book's first and governing idea is the one in its title. An algorithm does not exist apart from the data it works on. The same task, such as finding a name in a list, can be done in very different ways depending on how the list is arranged. If the names are in no order, one must look at each in turn. If they are sorted, one can jump to the middle and halve the search at each step. If they are stored in a tree, or placed by a computed address, other methods become possible. The choice of arrangement decides which algorithms are available and how fast they run.
The reverse is also true. A data structure is only good or bad relative to the operations performed on it. A sorted array is excellent for searching and poor for inserting new items, since each insertion may require shifting many others. A linked list is excellent for inserting and poor for searching. There is no best structure in general, only better or worse fits to the work at hand.
A household comparison helps. A filing cabinet sorted alphabetically makes finding a file quick but adding one slow, since space must be made in the right place. A pile on a desk makes adding instant and finding slow. An office that receives many new documents and rarely looks them up might prefer the pile. One that rarely receives documents and looks them up constantly should sort. Neither choice is wrong in itself. Each is a design decision about the pattern of use.
Wirth's point is that this decision must be made consciously and together with the choice of algorithm. A programmer who writes the steps first and picks data structures as an afterthought will often be trapped. A programmer who asks from the start what operations matter, and how often, can choose a structure that makes those operations cheap and an algorithm that uses it well.
This idea is often confused with mere efficiency. It is broader. The right data structure also makes programs clearer, because the code that operates on well-organised data is simpler. And it makes them more reliable, because a structure that matches the problem leaves fewer special cases to get wrong. Where the idea leads is to the whole later practice of abstract data types and object-oriented design, in which data and the operations on them are packaged together.
Stepwise refinement
The method by which Wirth builds programs is stepwise refinement. The programmer begins with a statement of the task at a high level of abstraction, almost in plain language. Then each part of that statement is refined: replaced by a slightly more detailed description, in terms of simpler operations. Those are refined in turn, until every operation can be expressed directly in the programming language.
At each step, decisions about data are made alongside decisions about actions. When the programmer refines a step that says process each item, they must also decide how the items are stored, since that determines how to visit each one. The refinement of algorithm and data proceeds in parallel, which is the practical form of the book's central thesis.
An analogy from writing makes the method clear. A careful writer does not begin a long essay by composing the first sentence. They begin with an outline: the main points in order. Then each point is expanded into paragraphs, each paragraph into sentences. At every level the structure above guides the choices below. A program built by refinement has the same layered clarity. Its top level can be read as a summary, and each lower level explains how the step above is done.
The method has several benefits. It postpones detail until it is needed, so that early decisions are made with a clear view of the whole. It makes the program's structure visible, since the levels of refinement often correspond to procedures or modules. It makes errors easier to locate, since each refinement can be checked against the step it refines. And it encourages the programmer to consider alternatives at each level before committing.
Stepwise refinement is often confused with simple top-down programming in which a design is fixed at the top and filled in mechanically. Wirth's version is more flexible. A refinement may reveal that an earlier decision was poor, and the programmer then backs up and revises. The method is a discipline of thinking, not a rigid procedure. Where it leads is to structured design methods of the 1970s and, in a looser form, to the habits of most careful programmers today.
Knowing the basic structures and their costs
Before anything else, Wirth wants the reader to understand the basic structures that a language provides and what they cost. An array is a sequence of items of the same type, each reachable directly by its position, so that looking up any element takes the same time. A record groups items of different types under one name, such as a person's name, date of birth and address. A set holds a collection of distinct values from a small range and supports quick tests of membership. A sequential file holds items that can only be read in order, one after another, as on a magnetic tape.
Each structure has a typical representation in the machine's memory, and Wirth explains these representations plainly. An array is laid out as a block of consecutive cells, which is why indexing is fast. A record's fields sit at fixed offsets from its start. A set of small integers can be stored as a row of bits, one per possible member, which makes union and intersection operations very cheap. A file is read through a window that moves forward one item at a time.
Understanding representation matters because it explains cost. A programmer who knows that an array is a contiguous block will understand why inserting an element in the middle is expensive, since everything after it must move. A programmer who knows that a file can only be read forward will understand why some algorithms that work well on arrays are useless on files. Performance follows from structure, and structure follows from representation.
A comparison with transport is apt. A train runs on fixed tracks and is fast between stations but cannot leave the line. A taxi goes anywhere but is slower for long journeys and costs more per passenger. Knowing how each works tells you which to choose for a trip. Knowing how each data structure is represented tells you which to choose for a task.
This idea is sometimes dismissed as low-level detail that modern languages hide. But the costs are still there beneath the abstractions. A modern programmer who uses a list type without knowing whether it is an array or a linked structure underneath may write code that is mysteriously slow. Wirth's insistence on understanding representation remains a mark of a serious programmer, and it connects directly to Computer Systems: A Programmer's Perspective on this shelf, which teaches the machine-level view in depth.
Sorting as a school for algorithms
Sorting occupies a large part of the book, and Wirth explains why. It is a problem everyone understands, it arises constantly in practice, and it has an unusually rich range of solutions. Studying sorting is therefore a way to study algorithm design in general: how to measure cost, how to trade simplicity against speed, and how the nature of the data affects the choice.
Wirth divides the topic in two. Sorting arrays, where all the data fit in memory and any item can be reached directly, allows one set of methods. Sorting sequential files, where data must be read in order and may not fit in memory, requires another. For arrays he presents simple methods that are easy to understand but slow on large inputs, and then more advanced methods that are much faster, explaining for each why it works and how many comparisons and moves it needs. For files he presents methods based on merging, which combine ordered runs of data into longer ordered runs, and refinements that use several files cleverly to reduce the number of passes.
The lesson is not a list of methods to memorise. It is a way of thinking. For each method, Wirth asks how its cost grows as the input grows. A method whose work grows with the square of the number of items is fine for a hundred items and hopeless for a million. A method whose work grows only slightly faster than the number of items remains practical at large scale. He also notes that the best method in theory is not always best in practice, since constant factors, the order of the input and the cost of moving data all matter.
An analogy is sorting a deck of cards by hand. With a few cards you might just pick up each card and slide it into place among those already sorted. With a whole deck, a better strategy is to deal the cards into piles by suit, sort each pile, and combine them. With a warehouse of cards that will not fit on any table, you would sort batches separately and merge them. The best method depends on the size of the task and on what you can hold at once.
Sorting is sometimes regarded as a solved problem not worth studying, since every library provides a sort routine. Wirth's point is not that programmers should write their own sorts. It is that sorting teaches how to reason about algorithms, and that reasoning applies everywhere. Where it leads is to the analysis of algorithms as a discipline, developed most fully in Donald Knuth's multi-volume work, which Wirth draws on and recommends.
How cost grows
Running through the sorting chapters and beyond is a method of analysis that deserves its own attention. Wirth does not judge algorithms by timing them on one machine with one input. He asks how many basic operations they perform, such as comparisons and moves, as a function of the size of the input. This gives a measure that does not depend on the machine and that shows how the algorithm will behave as problems grow.
The key idea is that the shape of growth matters more than the exact count. If one method needs about n squared steps for n items and another needs about n times the logarithm of n, the second will win for large inputs no matter how fast the machine running the first. Doubling the input quadruples the work of the first and only slightly more than doubles the work of the second. For a million items, the difference is enormous.
Wirth also distinguishes the best, worst and average cases. Some algorithms are fast on typical inputs but slow on particular ones, such as data that are already sorted or sorted in reverse. Knowing which inputs trigger the worst case lets a programmer guard against it. He shows how some methods can be adjusted to make the worst case unlikely.
An everyday parallel is the cost of a journey. A route through town may be quickest at night and slowest at rush hour. A planner who only tested it at night would be misled. A careful planner asks how the journey time changes with traffic, not just what it was once. Algorithm analysis asks the same question of programs: how does the cost change as the load changes?
This idea is often confused with micro-optimisation, the tuning of individual instructions. Wirth's analysis works at a higher level and usually reveals that choosing a better algorithm matters far more than polishing a poor one. This links to the advice in The Elements of Programming Style, also on this shelf, to make code right first and then improve its speed by better design rather than by tricks.
Recursion and when to use it
Recursion is the technique of defining something in terms of a smaller version of itself. A recursive procedure calls itself, with simpler arguments, until it reaches a case simple enough to answer directly. Wirth treats recursion as a natural tool for problems whose structure is recursive: problems that can be broken into smaller problems of the same kind, or data such as trees that contain smaller copies of themselves.
He is also careful to show when recursion is not appropriate. Some textbook examples use recursion for problems that are naturally iterative, such as computing a simple sequence where each value depends only on the previous one. Done recursively, such computations may be wasteful or even absurdly slow, recomputing the same values many times. Wirth's advice is to use recursion where the problem or data are genuinely recursive, and to prefer a plain loop where they are not.
An analogy helps. Russian nesting dolls are naturally recursive: each doll contains a smaller doll of the same form, until the smallest. To describe how to open the set, it is natural to say open this doll and then do the same for the one inside. A row of coins on a table is not recursive in the same way. To count them, you simply move along the row. Describing the count as count the first coin, then count the rest by the same method is possible but awkward. The structure of the problem should guide the structure of the solution.
Wirth shows that recursion can always be replaced by iteration with an explicit stack, and that understanding this equivalence helps one see what recursion costs. Each recursive call uses memory to remember where it was, so very deep recursion can exhaust memory. Knowing this, a programmer can decide when recursion's clarity is worth its cost.
This idea is often confused with a general preference for recursion as more elegant. Wirth's position is balanced. Recursion is elegant when it matches the problem and clumsy when it does not. Where it leads is to the treatment of recursive data structures later in the book, and to the recursive descent method used in the compiler.
Backtracking and systematic search
A particular use of recursion that Wirth develops carefully is backtracking. Many problems ask for an arrangement that satisfies some constraints: placing pieces on a board so that none attack each other, finding a path through a maze, matching members of two groups according to preferences. Often there is no direct formula. One must search.
Backtracking organises the search. The algorithm builds a solution one step at a time. At each step it tries a possible choice. If the choice is consistent with the constraints so far, it moves on to the next step. If it leads to a dead end, the algorithm undoes the choice and tries the next possibility. If all possibilities at a step fail, it retreats further, undoing the previous step. In this way it explores the space of possible solutions systematically without repeating itself.
Wirth presents classic puzzles that illustrate the method and shows how the same pattern can be adapted to find one solution, all solutions, or the best solution according to some measure. He also shows how the choice of data structures for recording the partial solution and the constraints can make each check fast, so that the search remains practical.
A good analogy is solving a crossword. You fill in a word that fits the clue. Later a crossing word does not fit, and you realise the first word must be wrong. You erase it, try another, and continue. A careful solver does this methodically, keeping track of what has been tried, rather than guessing at random. Backtracking is the methodical solver written as an algorithm.
This idea is sometimes confused with brute force, which tries every possible complete arrangement. Backtracking is more economical because it abandons a partial arrangement as soon as it breaks a constraint, cutting off whole branches of the search. Where it leads is to search methods in artificial intelligence, constraint solvers and many modern tools that explore large spaces of possibilities.
Pointers and structures that grow
The static structures of the opening part have a fixed size, decided when the program is written. Many problems need structures that grow and shrink as the program runs: a list of customers that changes daily, a tree of words built as a text is read. For these, Wirth introduces pointers, values that refer to other items in memory, and shows how they can be used to build dynamic structures.
A linked list is the simplest such structure. Each item holds its data and a pointer to the next item. To add an item, you create it and adjust a pointer or two; nothing else needs to move. To remove one, you redirect the pointer that led to it. Lists make insertion and deletion cheap, at the cost of slower searching, since you must follow the pointers one by one.
Trees are more powerful. Each item may point to several others, typically two in a binary tree, arranged so that items in one branch are smaller and items in the other larger. Searching a well-shaped tree is fast, since each step discards about half of what remains. Wirth shows how to search, insert and delete in trees, and explains a crucial danger: if items arrive in an unlucky order, the tree can become lopsided and lose its speed. He then presents methods for keeping trees balanced as they change, so that their good performance is guaranteed.
He also treats structures designed for data stored on external devices, such as disks, where reading a block of data is far slower than working in memory. Here trees with many branches per node, so that each node fills a disk block, keep the number of slow reads small. Structures of this kind remain the foundation of most databases and file systems.
A family tree is a familiar analogy for pointers. Each person is recorded once, with links to their parents and children. Adding a new child means adding one record and a link, not rewriting the whole tree. Finding someone means following links from a known starting point. Dynamic data structures use pointers in just this way, and their power comes from the freedom to rearrange links without moving data.
This idea is sometimes confused with low-level pointer manipulation of the kind that causes crashes in some languages. Wirth's treatment is disciplined. Pascal's pointers are typed and restricted, and he uses them only to build well-defined structures with clear operations. Where this leads is to the safe references of modern languages, and to the many tree and graph structures that underlie data systems, discussed at length in Designing Data-Intensive Applications on this shelf.
Finding things by computing where they are
Alongside trees, Wirth presents another approach to fast lookup: computing an item's location directly from its key. The idea is to take a key, such as a name, and transform it by a fixed calculation into a position in a table. If the calculation spreads keys evenly, most lookups go straight to the right place in a single step, faster even than a balanced tree.
The difficulty is that different keys may compute to the same position, an event called a collision. Wirth discusses how to handle collisions, for example by trying a sequence of alternative positions until a free one is found, and how the choice of calculation and table size affects how often collisions occur. He also notes the costs: such tables do not keep keys in order, and they perform poorly if they become too full.
An everyday analogy is a cloakroom where each coat is hung on a peg numbered by the first letter of the owner's surname. Finding a coat is quick: go straight to the right peg. But if many guests share a letter, their coats crowd together and the attendant must search among them. A better rule for assigning pegs would spread the coats more evenly.
This technique, now usually called hashing, is among the most widely used in all of computing. It underlies the dictionaries and maps built into modern languages, many database indexes and countless caches. Wirth's treatment shows how a simple idea, combined with careful attention to its failure modes, produces a structure of great practical power.
A compiler built from the same parts
The book's final part is its most distinctive. Wirth turns to the structure of programming languages and shows how to build a compiler, a program that translates text written in a programming language into instructions a machine can run. He does this for a deliberately small language, PL/0, which has just enough features to be interesting: constants, variables, procedures, assignments, conditions and loops.
He begins with grammar. A language can be described exactly by rules saying how its sentences are built from smaller parts, in much the way a grammar of English describes sentences in terms of phrases and words. Wirth uses a notation for such rules and shows how they can be drawn as syntax diagrams, easy to read and easy to translate into code.
From the grammar he derives a parser, the part of the compiler that reads a program and checks its structure. He uses the method of recursive descent, in which each rule of the grammar becomes a procedure that recognises the corresponding part of the language and calls other procedures for its sub-parts. Because the grammar is recursive, for example an expression may contain another expression in parentheses, the parser is naturally recursive too. Here the book's earlier lesson on recursion pays off directly.
He then extends the parser to detect and recover from errors, so that a mistake in the input does not stop the compiler from checking the rest, and to generate code for a simple imaginary machine, whose behaviour is defined by a small interpreter. The whole compiler is short enough to read in a sitting and complete enough to run real programs in the toy language.
The effect on a student is liberating. Compilers had a reputation as large, mysterious systems built by specialists. Wirth shows that a working compiler is an ordinary program built from the structures and methods already studied: tables to record names, recursive procedures to follow grammar, simple data to represent instructions. The book's title is proved in its last chapter.
The compiler also shows the value of a small, regular language. Because PL/0 was designed with a grammar that can be read one symbol at a time without looking far ahead, the parser can be simple. Wirth designed Pascal on similar principles. Language design and compiler design are linked: a language that is easy for people to read tends also to be easy for a program to analyse.
This idea is sometimes taken to mean that real compilers are this simple. They are not; production compilers handle large languages, optimise code and target complex machines. But the core structure Wirth demonstrates is the same, and many students who later built compilers started by working through PL/0. Where it leads is to the long tradition of small teaching compilers and to Wirth's own later book on compiler construction.
Language design as a tool of thought
Although the book is not mainly about language design, Wirth's views on it shape every page. The examples are in Pascal, and Pascal was designed to support exactly the style of programming the book teaches. Its type system lets programmers define new data types that match the problem: records for structured items, enumerations for small sets of named values, subranges for numbers that must lie within limits. Its control structures support stepwise refinement. Its pointers are restricted to prevent the worst errors.
The lesson for the reader is that the language one uses affects how one thinks. A language that makes it easy to define the right data structure encourages programmers to think about data. A language that offers only arrays and numbers pushes them to encode everything awkwardly. Wirth chose and designed languages to make good design natural.
An analogy from music fits. A composer writing for a string quartet thinks differently from one writing for a brass band, because the instruments make some textures easy and others hard. The instruments shape the music. Programming languages shape programs in the same way, and a designer who understands this will choose tools that make good structure easy.
This view is sometimes confused with the claim that one language is best for all purposes. Wirth did not hold that view. He designed different languages for different aims and revised them over time. His consistent position was that a language should be as simple as possible while supporting the structures its users need, and that features should be added only when they pay for their complexity.
Types as a way of describing the problem
An idea that runs quietly under the whole book is that data types are a language for describing problems. In Pascal, as Wirth uses it, a programmer does not simply store numbers and characters. They declare new types that name the things the problem is about: a type for days of the week, a type for a card with a suit and a rank, a type for a node in a tree. The declarations become a short, exact description of the problem's world before any algorithm is written.
This has several effects. It makes the program easier to read, because the names in the code are the names of the problem. It lets the compiler catch errors, since a value of one type cannot silently be used where another is expected. And it guides the design of algorithms, because once the shape of the data is written down, the operations needed on it become clearer.
Wirth builds types by combining simpler ones. A record groups fields; an array repeats an element; a set collects values; a pointer links one item to another. From these few constructors, very rich structures can be built, just as a few kinds of joint and beam can build many kinds of building. The lesson is that a small, well-chosen set of building blocks, combined freely, is more powerful than a large set of special-purpose features.
A useful comparison is a well-designed form. A paper form with labelled boxes for name, date and amount tells the person filling it in what is expected and makes mistakes visible: a date in the amount box looks wrong at once. A blank sheet of paper offers no such help. Types do for programs what labelled boxes do for forms.
This idea is sometimes confused with mere bureaucracy, as if declaring types were paperwork demanded by the compiler. Wirth's view is the opposite. Declaring types is thinking about the problem, done in a form the machine can check. Where it leads is to the strong type systems of many modern languages and to the practice, described in Domain-Driven Design on this shelf, of making the code's vocabulary match the vocabulary of the problem domain.
Reasoning about correctness
Wirth belonged to a group of computer scientists who believed that programs should not merely be tested but understood well enough to be argued correct. The book does not present formal proofs at length, but its explanations often take the form of reasoning about what is true at each point in an algorithm. When a loop runs, what remains the same on every pass? When it ends, what must then be true? These questions, asked carefully, often reveal both why an algorithm works and where a careless version would fail.
The central tool is the invariant: a statement about the program's data that holds before each pass through a loop and is preserved by each pass. In a sorting method, for example, an invariant might say that a certain part of the array is already in order. Each pass extends the ordered part by one item while keeping it ordered. When the loop ends, the ordered part is the whole array, and the sort is done. The invariant turns a sequence of steps into an argument.
This kind of reasoning has a practical side. It helps the programmer write the loop correctly in the first place, choosing its boundaries and its exit condition to match the invariant. It helps the reader check the code, since the invariant states what the code is trying to maintain. And it helps when something goes wrong, since a failure can be traced to the step that broke the invariant.
An everyday parallel is balancing a chequebook. After each entry, the running balance should equal the starting balance plus deposits minus withdrawals so far. That rule holds at every line. If at some line it fails, you know the error lies in that entry. A loop invariant is the same kind of running check, built into the design of the algorithm.
This idea is often thought to belong only to academic work on proof. Wirth shows that it is a working tool. Where it leads is to assertions in code, to the specification of preconditions and postconditions, and to modern tools that check properties of programs automatically.
Economy of means
A last idea is less a topic than a quality of the whole book: economy. Wirth uses the smallest set of concepts that will do the job and builds everything from them. The book is short for its range. Its programs are short for what they accomplish. Its language, Pascal, is small for its power. This economy is not an accident of style. It is an argument.
The argument is that complexity is the main enemy of reliable software. Each additional feature, special case or mechanism adds ways for things to go wrong and adds to what a reader must understand. A designer who keeps the means few and well understood produces systems that can be grasped as a whole, checked, and changed without fear. A designer who adds whatever seems useful at the moment produces systems no one fully understands.
Wirth applied this conviction throughout his career. His later Oberon system, built with a colleague, provided a complete operating system, compiler and user interface in an amount of code small enough to be described in a single book. It was meant as proof that software need not be vast to be useful.
A comparison with good cooking helps. A skilled cook can make a fine meal from a few good ingredients handled well. A poor cook adds more and more ingredients hoping to fix the taste and produces a muddle. The skill lies in knowing what to leave out.
This idea is often confused with minimalism for its own sake, or with refusal to provide useful features. Wirth's view was that every feature must pay for its cost in complexity, and that many do not. Where it leads is to the long debate about bloat in software, to the Unix tradition of small tools, and to modern writing on simplicity in design, such as John Ousterhout's book on this shelf.
Where this book sits in a programmer's education
It helps to see where this book fits among the things a programmer must learn. A first course teaches a language: how to write statements, loops and procedures, and how to make a small program run. A programmer at that stage can solve problems, but often by brute force, with whatever structures come to hand. Wirth's book is aimed at the next stage, where the programmer learns that there are standard ways of organising data and computation, that these ways have known costs, and that choosing among them is the central skill of design.
After this stage come others: building large systems from modules, working in teams, understanding the machine and the operating system, designing for many users and much data. Other books on this shelf address those stages. But each of them assumes the foundation Wirth provides. A programmer who does not know why a balanced tree is faster than a list, or how a hash table can fail, will struggle to understand a database index, a cache or a distributed store.
This is why the book has stayed in use for so long despite its age and its language. The specific code is old. The foundation it lays is the same one that every serious programmer still needs, and few books lay it as cleanly or as briefly.
The tradition around it
The book belongs to the structured programming movement of the late 1960s and 1970s, associated with Edsger Dijkstra, C. A. R. Hoare, Ole-Johan Dahl and Wirth himself. Their shared aim was to make programming a discipline in which programs could be understood, reasoned about and shown correct. Dijkstra emphasised control structure and proof. Hoare wrote influential notes on structuring data. Wirth brought these strands together in a textbook that showed them working on real problems.
It also drew on Donald Knuth's The Art of Computer Programming, whose first volumes had appeared from 1968 and which set the standard for the analysis of algorithms. Wirth's book is much shorter and less encyclopedic, aimed at teaching rather than reference, but it shares Knuth's insistence on understanding cost precisely.
Within this shelf, The Elements of Programming Style by Kernighan and Plauger shares Wirth's concern with clarity and his view that the arrangement of data shapes the clarity of code, though it works at the level of individual routines rather than fundamental structures. The UNIX Programming Environment by Kernighan and Pike presents a different but related philosophy of small, simple tools. The Psychology of Computer Programming by Gerald Weinberg addresses the human side that Wirth leaves aside.
Later books on the shelf build on Wirth's foundations. Computer Systems: A Programmer's Perspective by Bryant and O'Hallaron explains in depth the machine-level representation of data that Wirth sketches, and why memory layout affects speed. Designing Data-Intensive Applications by Martin Kleppmann treats the storage structures, including balanced trees and hashing, that underlie modern databases, scaled up to distributed systems. Design Patterns by Gamma and colleagues and Domain-Driven Design by Eric Evans continue the theme of shaping software around the right structures, at the level of objects and business domains. A Philosophy of Software Design by John Ousterhout carries forward Wirth's preference for simplicity and deep, clean interfaces.
Wirth's own later versions of the book, for Modula-2 and Oberon, show how the material evolved. The compiler chapter moved into a separate book on compiler construction, and some topics were updated. The core thesis remained unchanged.
Questions and criticisms
The most obvious dated element is Pascal. Few programmers write Pascal today, and some of its features, such as its handling of strings and arrays of fixed size, now seem restrictive. Readers must translate the examples into the languages they use. Because Pascal reads much like structured pseudocode, this is usually easy, but some details, especially those tied to Pascal's file handling, belong to their time.
Some of the material reflects the hardware of the 1970s. The extensive treatment of sorting sequential files assumes data on magnetic tapes, which are now rare in everyday programming. The underlying ideas, about merging and about minimising passes over slow storage, still apply to large data sets on disks and across networks, but the specific techniques are mostly of historical interest.
The book's style is dense. Wirth wastes no words, which is a virtue, but it also means that some explanations are compressed and require effort from the reader. Students without a teacher sometimes find parts hard going. Later textbooks have offered gentler introductions, often with more diagrams and exercises.
Some critics argue that the book underplays abstraction. It shows data structures in their concrete representation, with the code that manipulates them visible everywhere. Later practice, influenced by work on abstract data types and object-oriented design, prefers to hide representations behind interfaces, so that the rest of the program depends only on the operations, not on how they are implemented. Wirth's own later languages, with their modules, move in this direction, and the reader of this book should see it as a foundation on which abstraction is built, not as the last word.
The coverage of algorithms is selective. Graph algorithms, for example, receive less attention than in later textbooks, and much work on algorithms after 1976 is of course absent. Readers who want a comprehensive reference will need other books.
What has held up is the core argument and the method. The link between data structure and algorithm is as fundamental as ever. Stepwise refinement remains a sound way to approach a hard problem. The analysis of how cost grows with input is still the first tool of any serious programmer. And the PL/0 compiler remains one of the clearest demonstrations ever written that compilers are understandable programs.
One more caution concerns the analysis itself. Counting comparisons and moves was a good model of cost on the machines of the 1970s. On modern machines, with caches and deep memory hierarchies, the pattern in which data are accessed can matter as much as the number of operations. An algorithm that touches memory in order may beat one that does fewer operations but jumps around. Wirth's method of analysis remains the right starting point, but a modern reader should add this layer, which Computer Systems: A Programmer's Perspective explains well.
Why it is on this shelf
This shelf gathers books that explain how systems are built from simple parts, whether the parts are concepts, numbers or instructions. Algorithms + Data Structures = Programs belongs here because it shows, with unusual economy, how a small set of structures and methods can be combined to build programs of real size, up to a compiler. It teaches structure before syntax, and the habit of asking how things are arranged before asking what they do.
A reader of Vedanta will recognise a method of analysis that proceeds from the gross to the subtle and shows how complex appearances rest on simple principles. A reader of Jyotish, which depends on precise calculation and careful tables, will appreciate the discipline of representing data exactly and computing from it reliably. A reader of science will find in the analysis of algorithms a clean example of reasoning about how quantities grow. A reader of economics will see trade-offs everywhere: time against memory, simplicity against speed, general methods against specialised ones.
For anyone who builds technology, the book offers something that does not age with frameworks or fashions. Tools change every few years. The relationship between how data are arranged and what can be done with them efficiently does not. A programmer who has absorbed this book will make better decisions in any language.
We keep it beside The Elements of Programming Style and The Psychology of Computer Programming because together they cover the structure, the style and the human context of programs. Wirth's is the most demanding of the three and, for many readers, the one that most changes how they think about code.
How to read it
Begin with the opening part on fundamental data structures. Read it carefully even if the structures seem familiar, paying attention to how each is represented in memory and what that means for cost. Translate the Pascal declarations into your own language as you go.
Then read the part on sorting, but not all at once. Take the array sorting methods first. For each, work through a small example by hand with a pencil, sorting eight or ten numbers on paper and counting the comparisons and moves. Then read Wirth's analysis and check it against your counts. This is the single most useful exercise in the book. On a first pass, skim the section on sorting sequential files, noting the idea of merging and leaving the more elaborate methods for later.
Read the part on recursion next, slowly. Trace the backtracking examples by hand on small cases until you can predict what the algorithm will do. If possible, implement one of them in a language you know and watch it run.
Move on to dynamic structures. Draw lists and trees on paper, with boxes for items and arrows for pointers, and work through insertions and deletions step by step. The balanced tree methods are the hardest part of the book; take them at the slowest pace and do not worry if they need a second reading. The section on computing addresses from keys can be read more quickly.
Then go to the final part on language structures and the PL/0 compiler. Read the grammar first and draw the syntax diagrams yourself. Then read the parser, matching each procedure to its rule. If you can, type in or obtain a version of the compiler and run it on small programs. Many readers find this the most rewarding part of the book, and it repays every hour spent on it.
Pace yourself. This is a book for weeks, not days. A chapter a week, with exercises, is a good rhythm for a serious reader.
Keep a notebook beside the book. For each structure you meet, write one line on what it makes cheap and one line on what it makes expensive. By the end you will have a one-page guide to choosing data structures that is entirely your own, and it will be more useful to you than any summary. Return to it whenever a program you are writing feels slow or tangled, and check first whether the structure fits the work.
From this shelf, read next Computer Systems: A Programmer's Perspective by Bryant and O'Hallaron, to understand the machine beneath the data structures. Then Designing Data-Intensive Applications by Martin Kleppmann, to see these structures at the scale of modern data systems. For the design philosophy that grew from Wirth's preference for simplicity, read A Philosophy of Software Design by John Ousterhout.
Questions to carry
- For the program I am writing now, which operations matter most, and does my data structure make them cheap?
- If I changed how the data are arranged, which parts of my code would become simpler?
- Can I state the task in one sentence, and then refine it in clear steps?
- How does the cost of this algorithm grow if the input doubles, or grows a thousandfold?
- What input would trigger the worst case here, and could it really occur?
- Is this problem genuinely recursive, or would a simple loop be clearer?
- Where in this search could I abandon a partial solution early?
- What does this structure look like in memory, and what does that imply about its speed?
- When I use a built-in collection type, do I know how it is implemented underneath?
- If keys collide in this table, what happens, and how full can it safely get?
- Could I write a grammar for the input my program accepts?
- Which feature of my language encourages good structure, and which encourages bad?
- What would I remove from this design to make it simpler without losing what matters?
Words to know
- Algorithm: a precise, finite description of the steps needed to solve a problem.
- Data structure: a way of organising data in memory so that certain operations can be performed efficiently.
- Stepwise refinement: building a program by starting from a general statement of the task and repeatedly replacing steps with more detailed ones.
- Pascal: the programming language designed by Wirth around 1970, used for all examples in the book.
- Array: a fixed-size sequence of items of the same type, each reachable directly by its index.
- Record: a structure that groups named fields of possibly different types into one item.
- Set: a collection of distinct values from a small range, supporting fast membership tests.
- Sequential file: a sequence of items that can be read only in order from beginning to end.
- Sorting: arranging items in order by some key, used in the book as a case study in algorithm design.
- Merging: combining two or more ordered sequences into one ordered sequence.
- Complexity: a measure of how an algorithm's cost in time or memory grows with the size of its input.
- Worst case: the input for which an algorithm performs the most work.
- Recursion: defining a procedure or structure in terms of a smaller instance of itself.
- Backtracking: a search method that builds a solution step by step and retreats from choices that lead to dead ends.
- Pointer: a value that refers to the location of another item in memory, used to build dynamic structures.
- Linked list: a sequence of items, each holding a pointer to the next, allowing cheap insertion and deletion.
- Binary tree: a structure in which each item points to at most two others, often arranged so that searching is fast.
- Balanced tree: a tree kept in a shape that guarantees fast searching even as items are added and removed.
- B-tree: a tree with many branches per node, designed for data stored on disks, widely used in databases.
- Hashing: computing an item's position in a table directly from its key; Wirth calls this key transformation.
- Collision: the case in hashing where two different keys compute to the same position.
- Grammar: a set of rules that define exactly which texts belong to a language.
- Syntax diagram: a drawing of a grammar rule, showing the allowed sequences of parts.
- Recursive descent: a parsing method in which each grammar rule becomes a procedure that may call itself or others.
- PL/0: the small teaching language for which Wirth builds a complete compiler in the book.
A note on this edition
This is a study edition written for this shelf in our own words. It describes and discusses Algorithms + Data Structures = Programs but does not reproduce its programs, analyses or exercises. The book itself is still in copyright. It is compact, demanding and rewarding, and it can be found through a library or a bookshop.