Algorithm Questions
Algorithm Questions
What is an Algorithm?
An algorithm is simply a set of steps/instructions needed to complete a task. A recipe is an example of an
algorithm. For instance you could define an algorithm to make a cup of tea. You start by filling the kettle,
then place a tea bag in the cup and so on. When the word algorithm is used in computing, it defines the way
in which a software task can be completed or the way a problem can be solved.
Writing algorithms is all about problem solving. After being given a problem to solve, programmers never
begin programming straight away, they will first do the following:
Think about the important parts of the problem (Abstraction),
Break the problem down into smaller chunks (Decomposition),
Think of the steps needed to solve each chunk (Algorithmic Thinking),
Write down the steps – which in turn becomes the algorithm (Algorithmic Thinking).
Writing Algorithms
When writing algorithms, we could…
…write an algorithm in a specific language. However, doing this results in the following:
Too time consuming
Pointless – could just code
Can’t be taken by a programmer using a different language
Too complex – need knowledge of syntax (code specific to a language)
…write an algorithm in everyday language. However, doing this results in the following:
Too time consuming
Open to interpretation – thus resulting in different outcomes
As a result, effective Algorithms should be independent of any language…
1
Flowcharts
Pseudocode
Examples of each method of algorithm writing:
Flowchart
Pseudocode
Flowcharts
Flowcharts provide a visual representation of the logic of a program. They make use of a limited range of
symbols to describe processes and arrows to show the order of instructions / program flow.
Flowchart Example:
A central heating system will try to keep the temperature between 2
values (19 and 21)
If the temperature falls below 19 it will turn the heating system on
If the temperature rises above 21 it will switch the heating system off.
Flowcharts and their symbols
Representation Explanation Symbol
1
Start and Stop (Terminal) All flow charts begin with a Start
Symbols Symbol and at the end of the flow
chart (or at various end points of
the chart) we place a Stop
Symbol.
1
Tips on correcting flowcharts:
Read the flowchart and look for decisions which don’t make sense or iterations (loops) that you cannot enter
of break out of.
Pseudocode
Algorithms can be written in ‘generic code’ (which doesn’t follow any particular syntax) as well as a
flowchart. This ‘generic code’ is known as pseudocode. Pseudocode has keywords such as IF, ELSE and
FOR and so mimics a programming language and therefore the logic is easy to follow and easy to turn into
code. Although there are no STRICT STANDARDS for pseudocode there are some generally accepted
keywords that you should be aware of.
Pseudocode Example:
A central heating system will try to keep the temperature between 2
values (19 and 21)
If the temperature falls below 19 it will turn the heating system on
If the temperature rises above 21 it will switch the heating system off.
1
Pseudocode and commonly used keywords
Representation Explanation Symbol
1
Decision/Selection “Key Words” At times your program will be
programmed to make a decision
based on certain conditions.
1
Tips on correcting pseudocode:
Read the pseudocode and look for decisions which don’t make sense or iterations (loops) that you cannot
enter of break out of.
Questions (The question zone you choose must either match your target grade or be higher!)
3. Write an algorithm in pseudocode, which asks for the user to input 2 numbers and then outputs their
sum. [3]
Start
Input Number1
Input Number2
1
Then
Output Number1+Number2=Number3
Print Number3
End
Is it 8
characters. Display “Long Word”
Display “Short
Word”
3. “Effective algorithms are independent of any language”. Explain the meaning of this statement [5]
A good algorithm can be written in any language the writer prefers.
1
_____________________________________________________
_____________________________________________________
_____________________________________________________
Does it match
String pa$$word? Display “Correct
_____________________________________________________
Password”
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
3. Discuss the two methods of writing algorithms and explain which you think is the most effective for
_____________________________________________________
an experienced software designer. [4]
_____________________________________________________
Pseudocode and Flowcharts are the 2 methods for writing an algorithm. In my opinion flowcharts are
_____________________________________________________
more effective for an experienced software designer since it’s much easier and a better representation
since it’s a visual one. It’s easy to make, not to complex and just easy to understand/work with it.
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________ 1
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
Checklist:
Date and title, clearly presented
Keywords / Key Terms:
Algorithm: A set of steps/instructions needed to complete a software task.
_____________________________________________________
Spelling & grammar checked
Question numbers in the margin
Flowchart: A graphical representation of an algorithm.
Pseudocode: A representation of an algorithm in which the algorithm
_____________________________________________________
Handwriting neat & legible
Punctuation / Capital letters
resembles a simplified, generic programming language.
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________ 1
State/Identify/Give/Name: Simply label a diagram, fill out a table or write a few words
Describe: Describing is ‘saying what you see’ (E.G.: A computer will have a CPU, Primary and Secondary storage etc)
Explain: Explaining is ‘saying WHY/HOW something is like that’. (E.G.: A computer will have a CPU so that it can process all of the data the
computer needs to perform a range of tasks. Primary and Secondary storage is needed because…)
Discuss: Discussing is ‘looking at two sides of an issue, weighing up the two views and giving a conclusion’. Often these require a mini essay
answer. (E.G.: New technology could be seen as being bad for the environment because…, but on the other hand, new technology has led to…
In conclusion I believe that…)
Describe/Explain/Discuss using examples: Finally, if you are asked to give examples in any of these types of questions – YOU MUST GIVE
EXAMPLES!
1
Reflections: Score: / Percentage: % Grade: Progress: On / Above / Below
Further thoughts:
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________
__________________________________________________________________________