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 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 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 ...
, 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, cultu ...
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 augmented with natural language 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, scienti ...
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 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 tha ...
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 ...
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 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 Applied science, practical discipli ...
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 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.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 Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Frenc ...
, BASIC, 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, and ALGOL. 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 (mathematics), 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 wor ...
):


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 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'' (franchi ...
theory, mixed with the control structures of a conventional programming language, and perhaps also natural language 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 W ...
, or proprietary formula editors. Mathematical style pseudocode is sometimes referred to as pidgin code, for example ''pidgin ALGOL'' (the origin of the concept), ''pidgin Fortran'', ''pidgin BASIC'', ''pidgin
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Frenc ...
'', ''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 HyperTal ...
,
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, 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 betwe ...
, 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, 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 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 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 scientific and engineering settings. Modern programming languages that ...
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 m ...
(APL), and its dialects APLX and A+. * MathCAD.


See also

* Concept programming *
Drakon-chart DRAKON is a free and open source algorithmic visual programming and modeling language developed within the Buran space project following ergonomic design principles. The language provides a uniform way to represent flowcharts of any comp ...
*
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 ...
*
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 * 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. Struc ...


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