HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, pseudocode is a description of the steps in an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
using a mix of conventions of
programming languages A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their syntax (form) and semantics (meaning), usually defined by a formal language. Languages usually provide features ...
(like assignment operator, conditional operator, loop) with informal, usually self-explanatory, notation of actions and conditions. Although pseudocode shares features with regular
programming languages A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their syntax (form) and semantics (meaning), usually defined by a formal language. Languages usually provide features ...
, it is intended for
human Humans (''Homo sapiens'') or modern humans are the most common and widespread species of primate, and the last surviving species of the genus ''Homo''. They are Hominidae, great apes characterized by their Prehistory of nakedness and clothing ...
reading rather than machine control. Pseudocode typically omits details that are essential for machine implementation of the algorithm, meaning that pseudocode can only be verified by hand. The programming language is augmented with
natural language A natural language or ordinary language is a language that occurs naturally in a human community by a process of use, repetition, and change. It can take different forms, typically either a spoken language or a sign language. Natural languages ...
description details, where convenient, or with compact
mathematical notation Mathematical notation consists of using glossary of mathematical symbols, symbols for representing operation (mathematics), operations, unspecified numbers, relation (mathematics), relations, and any other mathematical objects and assembling ...
. The reasons for using pseudocode are 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 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 (constituenc ...
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 without errors. Flowcharts, drakon-charts and Unified Modelling Language (UML) charts can be thought of as a graphical alternative to pseudocode, but need more space on paper. Languages such as
HAGGIS Haggis ( ) is a savoury pudding containing sheep's offal, pluck (heart, liver, and lungs), Mincing, minced with chopped onion, oatmeal, suet, spices, and salt, mixed with Stock (food), stock, and cooked while traditionally encased in the anima ...
bridge the gap between pseudocode and code written in programming languages.


Application

Pseudocode is commonly used in textbooks and scientific publications related to
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
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 t ...
to describe algorithms in a way that is accessible to programmers regardless of their familiarity with specific programming languages. Textbooks often include an introduction explaining the conventions in use, and the detail of pseudocode may sometimes approach that of formal programming languages. Programmers frequently begin implementing an unfamiliar algorithm by drafting it in pseudocode, then translating it into a programming language while adapting it to fit the larger program. This top-down structuring approach often starts with a pseudocode sketch refined into executable code. Pseudocode is also used in standardization; for example, the
MPEG The Moving Picture Experts Group (MPEG) is an alliance of working groups established jointly by International Organization for Standardization, ISO and International Electrotechnical Commission, IEC that sets standards for media coding, includ ...
standards rely on formal C-like pseudocode, these standards cannot be understood without grasping the details of the code.


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 (constituenc ...
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. Some syntax sources include Fortran, Pascal,
BASIC Basic or BASIC may refer to: Science and technology * BASIC, a computer programming language * Basic (chemistry), having the properties of a base * Basic access authentication, in HTTP Entertainment * Basic (film), ''Basic'' (film), a 2003 film ...
, C, C++,
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
,
Lisp Lisp (historically LISP, an abbreviation of "list processing") is a family of programming languages with a long history and a distinctive, fully parenthesized Polish notation#Explanation, prefix notation. Originally specified in the late 1950s, ...
, 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 flexibility brings both major advantages and drawbacks: on the positive side, no executable programming language "can beat the convenience of inventing new constructs as needed and letting the reader try to deduce their meaning from informal explanations", on the negative, "untested code is usually incorrect".


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 t ...
, pseudocode often consists of
mathematical notation Mathematical notation consists of using glossary of mathematical symbols, symbols for representing operation (mathematics), operations, unspecified numbers, relation (mathematics), relations, and any other mathematical objects and assembling ...
, typically from
matrix Matrix (: matrices or matrixes) or MATRIX may refer to: Science and mathematics * Matrix (mathematics), a rectangular array of numbers, symbols or expressions * Matrix (logic), part of a formula in prenex normal form * Matrix (biology), the m ...
and
set theory Set theory is the branch of mathematical logic that studies Set (mathematics), sets, which can be informally described as collections of objects. Although objects of any kind can be collected into a set, set theory – as a branch of mathema ...
, mixed with the control structures of a conventional programming language, and perhaps also
natural language A natural language or ordinary language is a language that occurs naturally in a human community by a process of use, repetition, and change. It can take different forms, typically either a spoken language or a sign language. 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 Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
s. For example, the sum operator (
capital-sigma notation In mathematics, summation is the addition of a sequence 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, matrices, polyn ...
) or the product operator ( capital-pi notation) may represent a for-loop and a selection structure in one expression: Normally non-
ASCII ASCII ( ), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable character, printable and 33 control character, control c ...
typesetting Typesetting is the composition of text for publication, display, or distribution by means of arranging physical ''type'' (or ''sort'') in mechanical systems or '' glyphs'' in digital systems representing '' characters'' (letters and other ...
is used for the mathematical equations, for example by means of markup languages, such as
TeX Tex, TeX, TEX, may refer to: People and fictional characters * Tex (nickname), a list of people and fictional characters with the nickname * Tex Earnhardt (1930–2020), U.S. businessman * Joe Tex (1933–1982), stage name of American soul singer ...
or
MathML Mathematical Markup Language (MathML) is a pair of mathematical markup languages, an application of XML for describing mathematical notations and capturing both its structure and content. Its aim is to natively integrate mathematical formulae ...
, or proprietary formula editors. Mathematical style pseudocode is sometimes referred to as pidgin code, 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 or BASIC may refer to: Science and technology * BASIC, a computer programming language * Basic (chemistry), having the properties of a base * Basic access authentication, in HTTP Entertainment * Basic (film), ''Basic'' (film), a 2003 film ...
'', ''pidgin Pascal'', ''pidgin C'', and ''pidgin
Lisp Lisp (historically LISP, an abbreviation of "list processing") is a family of programming languages with a long history and a distinctive, fully parenthesized Polish notation#Explanation, prefix notation. Originally specified in the late 1950s, ...
''.


Common mathematical symbols


Example

The following is 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

Several 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, AppleScript, 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-machine, Z-code or Glulx virtual machines. Versions 1 through 5 were released ...
, and to some extent Python. 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'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usua ...
, meaning that variable declarations and other
boilerplate code In computer programming, boilerplate code, or simply boilerplate, are sections of code that are repeated in multiple places with little to no variation. When using languages that are considered ''verbose'', the programmer must write a lot of boile ...
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 exec ...
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 Specification Language (VDM-SL). Some
array programming In computer science, array programming refers to solutions that 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 program ...
languages include vectorized expressions and matrix operations as non-ASCII formulas, mixed with conventional control structures. Examples are: * A programming language (APL), and its dialects APLX and A+. * MathCAD.


See also

* Concept programming * Drakon-chart * Flowchart * Literate programming * Program Design Language * Short Code * Structured English


References


Further reading

* * * * * *


External links


A pseudocode standardCollected Algorithms
of the ACM
Pseudocode Guidelines
PDF file. {{Authority control Articles with example pseudocode Source code Algorithm description languages