Introduction to Algorithms
What is an algorithm?
- An algorithm is a set of precise instructions that, if strictly followed, will result in the solution to a problem
- Algorithms are particularly useful for programming computers
- Computers can process huge amounts of data and perform millions of calculations in very short time frames
- Robots can be programmed to follow an algorithm in order to complete a task
- E.g. A robot vacuum cleaner or lawn mower
- Algorithms can be performed by human beings too!
- E.g. The recipe and cooking instructions for a cake
- Algorithms are particularly useful for programming computers
What does an algorithm look like?
- Algorithms may be presented in a variety of ways
- A list of instructions, in order, written in words
- Flow charts are a visual way of presenting the steps of an algorithm
- These clearly show the order of instructions and any parts of an algorithm that may need repetition
What else do I need to know about algorithms?
- Some algorithms do not always provide an optimal (best) solution
- However, they will give a solution that is sufficient for the purpose
- Modern real-life situations can be complex to analyse
- A compromise between the efficiency of an algorithm and its accuracy is often required
- E.g. An algorithm may produce a 'shortest route' result that is inaccurate by 200 miles
- For a very long journey, the time saved using this algorithm may be more important than this inaccuracy
- When using an algorithm with a small amount of data in an exam you must follow the algorithm precisely and accurately
- This demonstrates understanding of the algorithm
- Using common sense or intuition to 'see' the solution will not gain full marks
Examiner Tip
- You must show that you have followed an algorithm precisely
- Use checks built into the algorithm to know that an algorithm is complete
- State (or 'print') any 'output' at the end if that is what an algorithm instruction requires
- Do not assume the output is the last number in your working