Materials provided on Algorithms from QCAA
From the Digital Solutions syllabus:
Algorithmic design method
Pseudocode will be used as the formal method of representing algorithms in this syllabus. Pseudocode is a descriptive method used to represent an algorithm and is a mixture of everyday language and programming conventions.
Pseudocode implements the basic control structures of assignment, sequence, selection, condition, iteration and modularisation through the use of keywords associated with the constructs, and textual indentation. Used to show how a computing algorithm should and could work, it is often an intermediate step in programming between the planning stage and writing executable code. Pseudocode can also be useful for:
- demonstrating thinking that later can become comments in the final program
- describing how an algorithm should work
- explaining a computing process to less technical people
- generating code in collaboration with others.
Conventions for writing pseudocode
KEYWORDS are written in bold capitals and are often words taken directly from programming languages.
For example, IF, THEN and ELSE are all words that can be validly used in most languages. OUTPUT and COMPUTE are from the language COBOL and WRITE is from the language Pascal.
Keywords do not have to be valid programming language words as long as they clearly convey the intent of the line of pseudocode.
Statements that form part of a REPETITION LOOP are indented by the same amount to indicate that they form a logical grouping.
In a similar way, IF, THEN and ELSE statements are indented to clearly distinguish the alternative processing paths.
The end of REPETITION LOOPS and IF, THEN and ELSE statements are explicitly indicated by the use of ENDWHILE and ENDIF at the appropriate points.
Pseudocode should clearly indicate what is happening at each step, including formulas of calculations.
For example:
CALCULATE net
is not as clear as:
CALCULATE net = gross − tax.
CALCULATE net
is not as clear as:
CALCULATE net = gross − tax.
Programmers prefer to use a more abbreviated version in which memory cells used to store the input are given program-like names.
For example:
INPUT num1
INPUT num2
is preferable to:
INPUT first number
INPUT second number
INPUT num1
INPUT num2
is preferable to:
INPUT first number
INPUT second number