liveBook · Manning

Pseudocode

As explained in How Computers Make Books

Pseudocode is an informal notation resembling programming languages that expresses an algorithm without requiring the syntax of a specific language.

Pseudocode lets an algorithm be written clearly without committing to a particular programming language. It keeps only the notation needed for the task, so attention can stay on the instructions rather than punctuation or language-specific rules. section 4.2

A word search can begin by defining search with a position parameter, checking that the word still fits in the text, comparing at that position, printing a match, and moving forward one character. A separate compare algorithm tests characters until it reaches the word’s end or finds a mismatch. section 4.2

Small conventions make the instructions readable:

  • Use keywords such as define, if, then, return, print, and length for actions with fixed meanings. section 4.2
  • Use a parameter such as pt to track a changing value, here the current text position. section 4.2
  • Indent instructions that happen only when a condition is true. section 4.2
Listing 4.9 The whole program
1 define compare pt pw 
2   if pw = length W then return true 
3   if T[pt] = W[pw] then compare (pt + 1) (pw + 1) 
4   return false 
5 
6 define search pt 
7   if pt + length W <= length T then 
8     if compare pt 0 then print pt 
9     search (pt + 1)

This complete listing joins the search and comparison routines into one compact word-search algorithm. section 4.2

How How Computers Make Books covers it

How deep it goes
Works through definitions, parameters, conditions, character comparison, and self-calls, while initially deferring comparison implementation.
Examples
Demonstrates finding “horses” in “houses and horses and hearses” with search and compare listings.
What it assumes
Introduces programming keywords, parameters, conditions, and indentation from a simple search problem.
What you can do after
Build it from scratch as pseudocode for a position-by-position word search.
How it connects
Connects algorithms with parameters, conditional statements, string length, character comparison, and recursion.

Also explained in

Compare how 6 books explain pseudocode →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of How Computers Make Books. The section links point to the parts of the book it draws on.