In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, pseudocode is a
plain language
Plain language is writing designed to ensure the reader understands as quickly, easily, and completely as possible. Plain language strives to be easy to read, understand, and use. It avoids verbose, convoluted language and jargon. In many countr ...
description of the steps in an
algorithm
In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
or another system. Pseudocode often uses structural conventions of a normal
programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming ...
, but is intended for
human
Humans (''Homo sapiens'') are the most abundant and widespread species of primate, characterized by bipedalism and exceptional cognitive skills due to a large and complex brain. This has enabled the development of advanced tools, culture, ...
reading rather than machine reading. It typically omits details that are essential for machine understanding of the algorithm, such as
variable declaration
In computer programming, a declaration is a language construct specifying identifier properties: it declares a word's (identifier's) meaning."A declaration specifies the interpretation and attributes of a set of identifiers. A ''definition'' of ...
s and language-specific code. The programming language is
augment
Augment or augmentation may refer to:
Language
*Augment (Indo-European), a syllable added to the beginning of the word in certain Indo-European languages
* Augment (Bantu languages), a morpheme that is prefixed to the noun class prefix of nouns ...
ed with
natural language
In neuropsychology, linguistics, and philosophy of language, a natural language or ordinary language is any language that has evolved naturally in humans through use and repetition without conscious planning or premeditation. Natural languages ...
description details, where convenient, or with compact
mathematical notation
Mathematical notation consists of using symbols for representing operations, unspecified numbers, relations and any other mathematical objects, and assembling them into expressions and formulas. Mathematical notation is widely used in mathem ...
. The purpose of using pseudocode is that it is easier for people to understand than conventional programming language code, and that it is an efficient and environment-independent description of the key principles of an algorithm. It is commonly used in textbooks and
scientific publications
: ''For a broader class of literature, see Academic publishing.''
Scientific literature comprises scholarly publications that report original empirical and theoretical work in the natural and social sciences. Within an academic field, scient ...
to document algorithms and in planning of software and other algorithms.
No broad standard for pseudocode
syntax
In linguistics, syntax () is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure ( constituency) ...
exists, as a program in pseudocode is not an executable program; however, certain limited standards exist (such as for academic assessment). Pseudocode resembles
skeleton programs, which can be
compiled
In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
without errors.
Flowcharts,
drakon-charts and
Unified Modelling Language
The Unified Modeling Language (UML) is a general-purpose, developmental modeling language in the field of software engineering that is intended to provide a standard way to visualize the design of a system.
The creation of UML was originally m ...
(UML) charts can be thought of as a graphical alternative to pseudocode, but need more space on paper. Languages such as
HAGGIS
Haggis ( gd, taigeis) is a savoury pudding containing sheep's pluck (heart, liver, and lungs), minced with onion, oatmeal, suet, spices, and salt, mixed with stock, and cooked while traditionally encased in the animal's stomach though n ...
bridge the gap between pseudocode and code written in programming languages.
Application
Textbooks and
scientific publication
: ''For a broader class of literature, see Academic publishing.''
Scientific literature comprises scholarly publications that report original empirical and theoretical work in the natural and social sciences. Within an academic field, scient ...
s related to
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
and
numerical computation
Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of numerical methods th ...
often use pseudocode in description of algorithms, so that all programmers can understand them, even if they do not all know the same programming languages. In textbooks, there is usually an accompanying introduction explaining the particular conventions in use. The level of detail of the pseudocode may in some cases approach that of formalized general-purpose languages.
A
programmer who needs to implement a specific algorithm, especially an unfamiliar one, will often start with a pseudocode description, and then "translate" that description into the target programming language and modify it to interact correctly with the rest of the program. Programmers may also start a project by sketching out the code in pseudocode on paper before writing it in its actual language, as a
top-down
Top-down may refer to:
Arts and entertainment
* " Top Down", a 2007 song by Swizz Beatz
* "Top Down", a song by Lil Yachty from ''Lil Boat 3''
* "Top Down", a song by Fifth Harmony from ''Reflection'' Science
* Top-down reading, is a part of ...
structuring approach, with a process of steps to be followed as a refinement.
Syntax
Pseudocode generally does not actually obey the
syntax
In linguistics, syntax () is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure ( constituency) ...
rules of any particular language; there is no systematic standard form. Some writers borrow style and syntax from control structures from some conventional programming language, although this is discouraged.
[Invitation to Computer Science, 8th Edition by Schneider/ Gersting, "Keep statements language independent" as quote]
in this stackexchange question
/ref> Some syntax sources include Fortran, Pascal, BASIC
BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
, C, C++
C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
, Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
, Lisp, and ALGOL
ALGOL (; short for "Algorithmic Language") is a family of imperative computer programming languages originally developed in 1958. ALGOL heavily influenced many other languages and was the standard method for algorithm description used by the ...
. Variable declarations are typically omitted. Function calls and blocks of code, such as code contained within a loop, are often replaced by a one-line natural language sentence.
Depending on the writer, pseudocode may therefore vary widely in style, from a near-exact imitation of a real programming language at one extreme, to a description approaching formatted prose at the other.
This is an example of pseudocode (for the mathematical game
A mathematical game is a game whose rules, strategies, and outcomes are defined by clear mathematical parameters. Often, such games have simple rules and match procedures, such as Tic-tac-toe and Dots and Boxes. Generally, mathematical games ne ...
fizz buzz
Fizz buzz is a group word game for children to teach them about division. Players take turns to count incrementally, replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz".
Play
Player ...
):
Mathematical style pseudocode
In numerical computation
Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of numerical methods th ...
, pseudocode often consists of mathematical notation
Mathematical notation consists of using symbols for representing operations, unspecified numbers, relations and any other mathematical objects, and assembling them into expressions and formulas. Mathematical notation is widely used in mathem ...
, typically from set
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
and matrix
Matrix most commonly refers to:
* ''The Matrix'' (franchise), an American media franchise
** ''The Matrix'', a 1999 science-fiction action film
** "The Matrix", a fictional setting, a virtual reality environment, within ''The Matrix'' (franchis ...
theory, mixed with the control structures of a conventional programming language, and perhaps also natural language
In neuropsychology, linguistics, and philosophy of language, a natural language or ordinary language is any language that has evolved naturally in humans through use and repetition without conscious planning or premeditation. Natural languages ...
descriptions. This is a compact and often informal notation that can be understood by a wide range of mathematically trained people, and is frequently used as a way to describe mathematical algorithm
In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
s. For example, the sum operator (capital-sigma notation
In mathematics, summation is the addition of a sequence of any kind of numbers, called ''addends'' or ''summands''; the result is their ''sum'' or ''total''. Beside numbers, other types of values can be summed as well: functions, vectors, mat ...
) or the product operator (capital-pi notation
Multiplication (often denoted by the cross symbol , by the mid-line dot operator , by juxtaposition, or, on computers, by an asterisk ) is one of the four elementary mathematical operations of arithmetic, with the other ones being additio ...
) may represent a for-loop and a selection structure in one expression:
Normally non-ASCII
ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because of ...
typesetting
Typesetting is the composition of text by means of arranging physical ''type'' (or ''sort'') in mechanical systems or ''glyphs'' in digital systems representing ''characters'' (letters and other symbols).Dictionary.com Unabridged. Random Ho ...
is used for the mathematical equations, for example by means of markup languages, such as TeX
Tex may refer to:
People and fictional characters
* Tex (nickname), a list of people and fictional characters with the nickname
* Joe Tex (1933–1982), stage name of American soul singer Joseph Arrington Jr.
Entertainment
* ''Tex'', the Italian ...
or MathML
Mathematical Markup Language (MathML) is a mathematical markup language, an application of XML for describing mathematical notations and capturing both its structure and content. It aims at integrating mathematical formulae into World Wide W ...
, or proprietary formula editor
A formula editor is a computer program that is used to typeset mathematical formulas and mathematical expressions.
Formula editors typically serve two purposes:
* They allow word processing and publication of technical content either for print ...
s.
Mathematical style pseudocode is sometimes referred to as pidgin code
In computer programming, pidgin code is a mixture of several programming languages in the same program, or pseudocode that is a mixture of a programming language with natural language descriptions. Hence the name: the mixture is a programming lan ...
, for example ''pidgin ALGOL
ALGOL (; short for "Algorithmic Language") is a family of imperative computer programming languages originally developed in 1958. ALGOL heavily influenced many other languages and was the standard method for algorithm description used by the ...
'' (the origin of the concept), ''pidgin Fortran'', ''pidgin BASIC
BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
'', ''pidgin Pascal'', ''pidgin C'', and ''pidgin Lisp''.
Common mathematical symbols
Example
Here follows a longer example of mathematical-style pseudocode, for the Ford–Fulkerson algorithm:
algorithm ford-fulkerson is
input: Graph ''G'' with flow capacity ''c'',
source node ''s'',
sink node ''t''
output: Flow ''f'' such that ''f'' is maximal from ''s'' to ''t''
''(Note that f(u,v) is the flow from node u to node v, and c(u,v) is the flow capacity from node u to node v)''
for each edge (''u'', ''v'') in ''G''''E'' do
''f''(''u'', ''v'') ← 0
''f''(''v'', ''u'') ← 0
while there exists a path ''p'' from ''s'' to ''t'' in the residual network ''G''''f'' do
let ''c''''f'' be the flow capacity of the residual network ''G''''f''
''c''''f''(''p'') ← min
for each edge (''u'', ''v'') in ''p'' do
''f''(''u'', ''v'') ← ''f''(''u'', ''v'') + ''c''''f''(''p'')
''f''(''v'', ''u'') ← −''f''(''u'', ''v'')
return ''f''
Machine compilation of pseudocode style languages
Natural language grammar in programming languages
Various attempts to bring elements of natural language grammar into computer programming have produced programming languages such as HyperTalk
HyperTalk is a discontinued high-level, procedural programming language created in 1987 by Dan Winkler and used in conjunction with Apple Computer's HyperCard hypermedia program by Bill Atkinson. Because the main target audience of HyperTalk ...
, Lingo
Lingo, a contraction of language, often refers to jargon, but in a less formal or technical sense.
Lingo may also refer to:
Technology
* Lingo (programming language), one of several unrelated programming languages
* Lingo (VoIP Service operator ...
, AppleScript
AppleScript is a scripting language created by Apple Inc. that facilitates automated control over scriptable Mac applications. First introduced in System 7, it is currently included in all versions of macOS as part of a package of system aut ...
, SQL, Inform
Inform is a programming language and design system for interactive fiction originally created in 1993 by Graham Nelson. Inform can generate programs designed for the Z-code or Glulx virtual machines. Versions 1 through 5 were released betw ...
, and to some extent Python
Python may refer to:
Snakes
* Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia
** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia
* Python (mythology), a mythical serpent
Computing
* Python (pro ...
. In these languages, parentheses and other special characters are replaced by prepositions, resulting in quite verbose code. These languages are typically dynamically typed
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer progra ...
, meaning that variable declarations and other boilerplate code can be omitted. Such languages may make it easier for a person without knowledge about the language to understand the code and perhaps also to learn the language. However, the similarity to natural language is usually more cosmetic than genuine. The syntax rules may be just as strict and formal as in conventional programming, and do not necessarily make development of the programs easier.
Mathematical programming languages
An alternative to using mathematical pseudocode (involving set theory notation or matrix operations) for documentation of algorithms is to use a formal mathematical programming language that is a mix of non-ASCII mathematical notation and program control structures. Then the code can be parsed and interpreted by a machine.
Several formal specification language
A specification language is a formal language in computer science used during systems analysis, requirements analysis, and systems design to describe a system at a much higher level than a programming language, which is used to produce the execu ...
s include set theory notation using special characters. Examples are:
* Z notation
The Z notation is a formal specification language used for describing and modelling computing systems. It is targeted at the clear specification of computer programs and computer-based systems in general.
History
In 1974, Jean-Raymond Abria ...
* Vienna Development Method
The Vienna Development Method (VDM) is one of the longest-established formal methods for the development of computer-based systems. Originating in work done at the IBM Laboratory Vienna in the 1970s, it has grown to include a group of techniques ...
Specification Language (VDM-SL).
Some array programming
In computer science, array programming refers to solutions which allow the application of operations to an entire set of values at once. Such solutions are commonly used in computational science, scientific and engineering settings.
Modern progr ...
languages include vectorized expressions and matrix operations as non-ASCII formulas, mixed with conventional control structures. Examples are:
* A programming language
APL (named after the book ''A Programming Language'') is a programming language developed in the 1960s by Kenneth E. Iverson. Its central datatype is the multidimensional array. It uses a large range of special graphic symbols to represent mo ...
(APL), and its dialects APLX
APLX is a cross-platform dialect of the programming language APL, created by British company MicroAPL, Ltd. APLX is intended for uses such as financial planning, market research, statistics, management information, and various kinds of scientific ...
and A+.
* MathCAD.
See also
* Concept programming
Christophe de Dinechin is a French computer scientist, with contributions in video games, programming languages and operating systems.
Programming languages
Dinechin contributed to C++, notably a high-performance exception handling implementati ...
* Drakon-chart
* Flowchart
* Literate programming
Literate programming is a programming paradigm introduced in 1984 by Donald Knuth in which a computer program is given as an explanation of its logic in a natural language, such as English, interspersed (embedded) with snippets of macros an ...
* Program Design Language Program Design Language (or PDL, for short) is a method for designing and documenting methods and procedures in software. It is related to pseudocode, but unlike pseudocode, it is written in plain language without any terms that could suggest the us ...
* Short Code
codes, or short numbers, are short digit sequences, significantly shorter than telephone numbers, that are used to address messages in the Multimedia Messaging System (MMS) and short message service (SMS) systems of mobile network operators ...
* Structured English
References
Further reading
*
External links
A pseudocode standard
ACM">Collected Algorithms of the Association for Computing Machinery, ACM
br>Pseudocode Guidelines
PDF file.
{{Authority control
Articles with example pseudocode
Source code
Algorithm description languages