Writing & Amending Algorithms
- To create algorithms for a given problem several stages must be followed:
- The problem must be sufficiently analysed and understood. The requirements and purpose of the algorithm must be clearly stated
- The problem must be sufficiently decomposed into sub-problems. A complex problem may require many sub-problems with each sub-problem requiring their sub-problems and algorithms. When determining an algorithm for a sub-problem developers need to consider inputs, outputs, processes and long term data storage (if necessary)
- Consideration must be given to how data is going to be gathered, stored and processed as well as how output is going to be displayed to the user
- For example, will data be entered via input boxes or file upload/opening? Is data to be stored in a file? What overall processes will be performed on the data? Will the data be displayed on a form, a web page or output into a file?
- The structure of the problem and subproblems should be illustrated by creating a structure diagram which details the breakdown and hierarchy of sub-problems
- Once each sub-problem is specified, an algorithm can be created using flowcharts or pseudocode. The algorithm should be clear, easy to read and as simple as possible
- Meaningful variable names help readers understand what data is being stored and their purpose
- Mathematical symbols such as “=” or “<=” are quicker and simpler to read than “equal to “ or “less than or equal to”. “Percentage < 0 OR Percentage > 100” is clearer than “Percentage under zero or Percentage over one-hundred”. Be concise
- Sets of predetermined test data should be dry run on the algorithm, including normal, abnormal, extreme and boundary data. The results should be displayed in a trace table, with clear outputs to allow errors to be detected
- Encountered errors should be fixed and the algorithm retested to make sure it functions as intended
Exam Tip
- Writing algorithms in an exam can be challenging and time consuming. It's important to allocate your time carefully to not spend too little or too long writing an algorithm
- You will likely make mistakes and rewrite your algorithm a few times. Use scrap paper or the back of your exam paper if possible to sketch out your ideas before committing to your answer. This will make your answer clearer, neater and easier to read, follow and understand
- You may wish to chunk your algorithm into parts initially, for example, “This part will enter the grades”, “this part will calculate the total”, and “This part will allocate grades”. You can then put the whole algorithm together in order later
- Make a plan before you start answering the question and writing your algorithm. A plan can be simple but allows you to order your thoughts, for example:
- Part 1: Declare and initialise variables
- Part 2: Allocate marks for each subject
- Part 3: Allocate grades for each student's subject
- Part 4: Include a loop
- Part 5: Output all necessary data
- Pseudocode does not have a syntax, therefore you can write an algorithm in any way which is easily understandable. Caution is advised to stick to iGCSE specification standards to ensure your answer is consistent and easy for examiners to follow
- Be sure to use variable names and data provided in the question as given. Failure to do so will lose you marks
- Remember to comment on your code. It helps both you and the examiner understand your answer and also awards marks in the mark scheme!