Αρχική » 2020 (Σελίδα 2)
Αρχείο έτους 2020
BBC Evaluating
Evaluating solutions
Before solutions can be programmed, it is important to make sure that it properly satisfies the problem, and that it does so efficiently. This is done through evaluation.
What is evaluation?
- is easily understood – is it fully decomposed?
- is complete – does it solve every aspect of the problem?
- is efficient – does it solve the problem, making best use of the available resources (eg as quickly as possible/using least space)?
- meets any design criteria we have been given
If an algorithm meets these four criteria it is likely to work well. The algorithm can then be programmed.
Failure to evaluate can make it difficult to write a program. Evaluation helps to make sure that as few difficulties as possible are faced when programming the solution.
Why do we need to evaluate our solutions?
What happens if we don’t evaluate our solutions?
Once a solution has been decided and the algorithm designed, it can be tempting to miss out the evaluating stage and to start programming immediately. However, without evaluation any faults in the algorithm will not be picked up, and the program may not correctly solve the problem, or may not solve it in the best way.
Faults may be minor and not very important. For example, if a solution to the question ‘how to draw a cat?’ was created and this had faults, all that would be wrong is that the cat drawn might not look like a cat. However, faults can have huge – and terrible – effects, eg if the solution for an aeroplane autopilot had faults.
Ways that solutions can be faulty
We may find that solutions fail because:
- it is not fully understood – we may not have properly decomposed the problem
- it is incomplete – some parts of the problem may have been left out accidentally
- it is inefficient – it may be too complicated or too long
- it does not meet the original design criteria – so it is not fit for purpose
A faulty solution may include one or more of these errors.
BBC Representing an algorithm: Pseudocode and flowcharts
There are two main ways that algorithms can be represented – pseudocode and flowcharts.
Representing an algorithm: Pseudocode
Most programs are developed using programming languages. These languages have specific syntax that must be used so that the program will run properly. Pseudocode is not a programming language, it is a simple way of describing a set of instructions that does not have to use specific syntax.
Writing in pseudocode is similar to writing in a programming language. Each step of the algorithm is written on a line of its own in sequence. Usually, instructions are written in uppercase, variables in lowercase and messages in sentence case.
In pseudocode, INPUT asks a question. OUTPUT prints a message on screen.
A simple program could be created to ask someone their name and age, and to make a comment based on these. This program represented in pseudocode would look like this:
OUTPUT 'What is your name?'
INPUT user inputs their name
STORE the user's input in the name variable
OUTPUT 'Hello' + name
OUTPUT 'How old are you?'
INPUT user inputs their age
STORE the user's input in the age variable
IF age >= 70 THEN
OUTPUT 'You are aged to perfection!'
ELSE
OUTPUT 'You are a spring chicken!'
Representing an algorithm: Flowcharts
Flowchart symbols
A simple program could be created to ask someone their name and age, and to make a comment based on these. This program represented as a flowchart would look like this: