2.1 – Algorithms

This page is NOT YET READY

πŸŽ‡2.1.2 Designing, creating and refining algorithms

This section covers:

  • Identify the inputs, processes, and outputs for a problem

  • Structure diagrams

  • Create, interpret, correct, complete, and refine algorithms using:

    • Pseudocode

    • Flowcharts

    • Reference language/high-level programming language

  • Identify common errors

  • Trace tables

🏠 Click here to go back to the main page.

Other sections in this topic:

πŸ”—2.1.1 Computational thinking

πŸ”—2.1.3 Searching and sorting algorithms

This page examines Algorithms in more detail and looks at several different ways in which we can represent an algorithm. You need to be able to understand what an algorithm is describing and many students find this extremely difficult. Think of an algorithm as a detailed list of instructions that explain how a program can solve a problem.

Identify the Inputs, Processes and Outputs for a problem.

Any problem that an algorithm describes can be thought of as a system. Something will happen, or certain conditions will exist and the algorithm will do something using as a result. A system will not be complete unless it actually does something at the end. These stages are known as the input, process and output of a system.

Structure Diagrams

A structure diagram is a simple diagram that represents how the different parts of a system are (literally) structured and connect with each other. They should include the three stages shown above, input, process and output.

The input section should include all of the things that can alter what the system actually does. This may be when a program actually asks you for something "What is your name?", "How many players are there?" but it may also include items which are fixed, like the value of Pi.

During the process phase, the program will carry out operations such as calculations and more complex processes such as sorting into a particular order. The process stage may involve repeating a block of code several times and completing different operations depending on the result of calculations.

Once the system has computed a result, something will need to be done with the result. This may just be displaying an "answer", or it could be altering what the program does, how it looks or what it does next. The output may also control something such as a motor or light.

Create, interpret, correct, complete, and refine algorithms using:



Interpret, Correct or Complete Algorithms

As we have seen, an algorithm is simply a way of solving a problem.

Algorithms can take many forms:

  • They may be a simple written list which could be numbered or just done as a bullet list

  • They may be a flowchart with arrows to indicate "program flow"

  • They may be pseudocode, which is a cross between written English and a programming language

  • They may be a fully working program

We need to be able to understand what a particular algorithm does and see how it will handle a particular situation.



Flowcharts

Flowcharts have been used for many years to document or describe how systems work. They use a standard set of symbols or shapes and each specific symbol has a set meaning. Each symbol contains text which explains its function. They can be coloured but are normally left as just a plain black and white symbol and text.

Arrows connect each shape which indicates how the "flow" of the program moves from one shape to another. There should be only one possibility of the program flow at any one time. A diamond shaped decision box has two possible routes of flow, and the question in the shape should be one that has two possible answers "Yes" and "No"


Identify common errors


Trace tables





This is the "terminator" shape that should be used at the very start and end of a flowchart.

All flowcharts must have a "Start" terminator (Labelled as Start) and most systems will also have a "Stop" terminator.


This shape is used when a program requires an input or an output.

An example of an input would be when a program asks the user to enter their name.

An example of an output would be when a program prints out an answer.


This is the process shape which is used when a program does something that does not involve a decision, an input or an output.

The process should be described briefly, and complex processes should be broken down into several smaller steps.


This is the decision shape, which is used whenever a program uses a statement that has a choice of possible routes. The box should be labelled with a brief statement that summarises the two possible choices. (Decisions should always have only two choices)

A decision shape is unusual because will have two arrows from it, which should be labelled as "Yes" or "No"


This shape is used when a subroutine has been used. This is a frequently used piece of code that may contain lots of separate tasks. The main flowchart will refer to the subroutine using this shape.


Arrows should be drawn to connect each shape. the direction of the arrow represents the "flow" of the program. Arrows should be drawn horizontally or vertically and angled or non straight lines should be avoided.



Algorithm Examples

We can also use pseudocode, or even full code to describe an algorithms.

Look at this program (its pseudocode, because Python wouldnt recognise the capitalised words)

What would you do if you followed this algorithm? (try it!)

What would your teacher do?


Here are some keywords that you should understand when discussing algorithms:

  • Algorithm – the series of steps to solve a problem or perform an action.

  • Flowchart – a diagram that shows the inputs, outputs and processes in an algorithms.

  • Process – an action that takes place.

Pseudocode – simplified programming code that is not language specific, used to design algorithms.





Flowchart Example

This is a typical problem that you may have to solve when writing a program, and you may get something similar in the unit 2 exam.

Imagine that you are the computer, and follow the steps one at a time.

This slide show uses a trace table which is a great way of keeping track of the values of any variables as your program runs.

Step through the slides one at a time, using the ">" button.

Try to answer the question at the end.

followanalgorithm.pptx


Click here for the next topic:

πŸ”—2.1.3 Searching and Sorting Algorithms