HOME

TheInfoList



OR:

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 practical disciplines (includin ...
, 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 problems or to perform a computation. Algorithms are used as specifications for performing ...
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 l ...
, 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 declarations and language-specific code. The programming language is augmented 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 languag ...
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 mathe ...
. 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, sc ...
to document algorithms and in planning of software and other algorithms. No broad standard for pseudocode syntax 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.
Flowchart A flowchart is a type of diagram that represents a workflow or process. A flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-step approach to solving a task. The flowchart shows the steps as boxes of va ...
s, 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 ( 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 now a ...
bridge the gap between pseudocode and code written in programming languages.


Application

Textbooks and scientific publications 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 practical disciplines (includin ...
and numerical computation 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 A computer programmer, sometimes referred to as a software developer, a software engineer, a programmer or a coder, is a person who creates computer programs — often for larger computer software. A programmer is someone who writes/creates ...
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 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++,
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 mo ...
,
Lisp A lisp is a speech impairment in which a person misarticulates sibilants (, , , , , , , ). These misarticulations often result in unclear speech. Types * A frontal lisp occurs when the tongue is placed anterior to the target. Interdental lispi ...
, 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 th ...
. 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
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 Playe ...
):


Mathematical style pseudocode

In numerical computation, 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 mathe ...
, typically from set 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'' (franchi ...
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 languag ...
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 problems or to perform a computation. Algorithms are used as specifications for performing ...
s. For example, the sum operator ( capital-sigma notation) or the product operator ( capital-pi notation) 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 ...
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 ...
is used for the mathematical equations, for example by means of markup languages, such as TeX 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 We ...
, 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 th ...
'' (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 A lisp is a speech impairment in which a person misarticulates sibilants (, , , , , , , ). These misarticulations often result in unclear speech. Types * A frontal lisp occurs when the tongue is placed anterior to the target. Interdental lispi ...
''.


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, Lingo,
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, 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 to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constructs of a computer program ...
, 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 languages include set theory notation using special characters. Examples are: * Z notation *
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 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 Mathcad is computer software for the verification, validation, documentation and re-use of mathematical calculations in engineering and science, notably mechanical, chemical, electrical, and civil engineering. Released in 1986 on DOS, it introduce ...
.


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 implementa ...
* Drakon-chart *
Flowchart A flowchart is a type of diagram that represents a workflow or process. A flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-step approach to solving a task. The flowchart shows the steps as boxes of va ...
* Literate programming *
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 *
Structured English Structured English is the use of the English language with the syntax of structured programming to communicate the design of a computer program to non-technical users by breaking it down into logical steps using straightforward English words. Stru ...


References


Further reading

*


External links


A pseudocode standardACM">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