Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Pseudocode
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Mathematical style pseudocode== In [[numerical computation]], pseudocode often consists of [[mathematical notation]], typically from [[matrix (mathematics)|matrix]] and [[set 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]]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: {{nowrap|Return <math>\sum_{k\in S} x_k</math>}} Normally non-[[ASCII]] [[typesetting]] is used for the mathematical equations, for example by means of markup languages, such as [[TeX]] or [[MathML]], or proprietary [[formula editor]]s. 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 (programming language)|Pascal]]'', ''pidgin [[C (programming language)|C]]'', and ''pidgin [[Lisp (programming language)|Lisp]]''. ===Common mathematical symbols=== <!-- Copied from Wikipedia:WikiProject_Computer_science/Manual_of_style#Algorithms --> {| class="wikitable" ! Type of operation || Symbol || Example |- | Assignment || β or := ||<code>''c'' β 2Ο''r''</code>, <code> ''c'' := 2Ο''r''</code> |- | Comparison || =, β , <, >, β€, β₯ || |- | Arithmetic || +, β, Γ, /, mod || |- | Floor/ceiling || β, β, β, β || <code>''a'' β β''b''β + β''c''β</code> |- | Logical | '''and''', '''or''' | |- | Sums, products | Ξ£ Ξ | <code>''h'' β Ξ£<sub>''a''β''A''</sub> 1/''a''</code> |} ===Example=== The following is a longer example of mathematical-style pseudocode, for the [[FordβFulkerson algorithm]]: <!-- Same example as in Wikipedia:WikiProject_Computer_science/Manual_of_style#Algorithms --> '''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<sub>(u,v)</sub> is the flow from node u to node v, and c<sub>(u,v)</sub> is the flow capacity from node u to node v)'' '''for each''' edge (''u'', ''v'') '''in''' ''G''<sub>''E''</sub> '''do''' ''f''<sub>(''u'', ''v'')</sub> β 0 ''f''<sub>(''v'', ''u'')</sub> β 0 '''while''' there exists a path ''p'' from ''s'' to ''t'' '''in''' the residual network ''G''<sub>''f''</sub> '''do''' let ''c''<sub>''f''</sub> be the flow capacity of the residual network ''G''<sub>''f''</sub> ''c''<sub>''f''</sub>(''p'') β min{''c''<sub>''f''</sub>(''u'', ''v'') | (''u'', ''v'') '''in''' ''p''} '''for each''' edge (''u'', ''v'') '''in''' ''p'' '''do''' ''f''<sub>(''u'', ''v'')</sub> β ''f''<sub>(''u'', ''v'')</sub> + ''c''<sub>''f''</sub>(''p'') ''f''<sub>(''v'', ''u'')</sub> β β''f''<sub>(''u'', ''v'')</sub> '''return''' ''f''
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)