Algorithms - Pseudocode

From Dev Wiki
Jump to navigation Jump to search

Pseudocode is code that written in whatever expressive method is most clear and concise. Generally, pseudo code is meant for human reading rather than machine reading, and thus does not worry about "issues of software engineering", such as error checking, abstraction, modularity, etc.

This makes pseudocode useful for trying to share and convey ideas, and test theory, as opposed to more standardized languages which are better for full implementation.

Writing Pseudocode

Pseudocode may vary from place to place, but for the purposes of this wiki, we'll define that pseudocode will follow guidelines as written in the book "Introduction to Algorithms, Third Edition" by "Thomas H Cormen". To summarize:

  • Code shall generally be Python-esque, when possible.
  • Assignment will be done with the ← sign.
    • Thus, to assign a variable with a value of 5, we would write my_var ← 5.
  • Equality comparison will be done with a single = sign.
    • Thus, checking equality between two variables would be written as if my_var = a_var.

For a basic example of a pseudocode snippet, see Algorithms - Primitive Operations.