2.1 Algorithms Flashcards
algorithms
provide precise instructions needed to solve a problem
all computer programs are algorithms
a step-by-step procedure for solving a problem or carrying out a task
uses for algorithms
often used to improve efficiency by removing the need for human input
e.g. automatic-pilot systems
advantages of an algorithm
a computer following an algorithm can decide what to do far quicker than a human, which can be extremely valuable (e.g. when stock market trading)
constructs of an algorithm
sequence
selection
iteration
sequence
instructions need to be given in the correct order
instructions are read in a specific order
selection
decisions are made and a course of action is chosen
iteration
previous steps are repeated until there is a desired outcome
reusing algorithms
they can be reused with slight changes for solving similar problems
quicker than starting from scratch each time
Write an algorithm to make a cup of instant coffee. It should be annotated to show where sequence, selection and iteration have been used [5]
1) fill kettle with water (sequence)
2) turn on kettle (sequence)
3) place coffee in the cup (sequence)
4) check if the water is boiling (selection)
5) if water is not boiling go back to step 4 (iteration)
6) pour water into the cup (sequence)
7) if needed, add milk and sugar (selection)
Algorithms use selection and iteration.
Define what is meant by:
a) selection
b) iteration [2]
a) selection in an algorithm is where a decision has to be made and a course of action has to be selected
b) iteration is where some of the steps have to be repeated until there is a required outcome