Algorithmic Thinking

The steps or rules to achieve a given goal. Such a simple sentiment that we can be forgiven for thinking it is easily mastered, a matter of a few lessons before we move on to more lofty goals.

Algorithms and programs follow clearly defined logical rules. Exploring these rules and concepts unlocks branches of logical thinking. Agency over these enables pupils to design powerful efficient sets of instructions and convert some of these into programs that work on digital devices.

Algorithmic thinking includes but is not limited to sequential thinking, thinking with outputs, loopy or repetitive thinking, thinking with inputs, the power of conditions to change pathways of thinking, thinking with variables which is the start of data thinking, procedural thinking and workflow thinking.

Although the following paragraphs separate these constructs out you will see that they all overlap with each other. We want pupils to be able to choose the construct they need to achieve their own goals and to do this they will often need more than one.

After we describe each construct we will look at how we can build pupil understanding at both the planning and the code level. You can read more about the educational theories both CS and general underpinning the 4th generation methods and even more current Gold resources here.

Algorithms that do not lead to code

Algorithmic thinking is not thinking with code. Although there are overlaps in the constructs used (sequence, repetition, selection etc) there are clear differences. You can read about these in more detail here. Algorithms are written in English or whatever your native tongue is. Algorithms cannot be executed, in other words they can’t be directly transferred to a computer and run as a program.

Many algorithms are constructed without any links to programming. These might include such diverse themes as the rules and procedures to be successful in any human endeavour such as industry, commerce or relationships. How to pack luggage into an aircraft hold so that it can accept the maximum possible whilst being quick to load and unload.

Everyday or Formal Algorithms

Everyday algorithms are the steps and processes that we use to manage our lives efficiently. The order we brush our teeth, get dressed, travel to school. For primary pupils these are the type of algorithms we will  use to teach them about algorithmic concepts.

Formal algorithms are much more like the mathematical formulas that we learn to use to efficiently calculate. They simplify a process, are recognised for their brilliance and taught as part of computing science. Secondary pupils in England study some of these as part of their computing curriculum.

If you hear some one in the media talking about algorithms it will often be formal algorithms that they are talking about.

Algorithms that do lead to code

Algorithmic design is also part of the programming planning process sometimes called the levels of abstraction (2).

Levels of abstraction

Algorithmic writing is part of the planning level that progresses from the idea level, through planning level, code level and execution level(2) in the journey from idea to working program. Understanding these levels is important for educators teaching children to program. It also helps if pupils understand which level they are working on. The levels don’t always have to progress from top to bottom and revisiting higher levels when needed is all part of evolving flexible thinking. Pupils may spot an opportunity when working in the code level which dictates changes to idea, planning level or both.

Ideas level

This is where the overall idea is expressed. For example, I want to make a game program that moves my character around a maze collecting items as it goes. I want to make a program that adds two numbers together and shows the result. I want to make a program where two characters talk to each other. Defining an idea accurately is important as it will inform the planning and coding levels.

Planning Level

This is where we decide which characters and objects we want in our program and  what algorithmic steps they will carry out to achieve our ideas. It is a place to think about how we will make sure the program always runs that same every time it is run which we call initialisation. A game algorithm may consist of lots of small decomposed scripts to achieve parts of the game design where as an algorithm to add two numbers and show the result will probably be expressed in just one script.
For example
Assign 0 to first_number variable
Assign 0 to variable called second_number
Assign 0 to total variable
Ask the user what number they would like to add first and assign their answer to a variable called first_number
Ask the user what number they would like to add to the first number and assign their answer to second_number variable
Add first_number to second_number and assign the result to total
Say what is inside the total variable
My hero character will start at the centre of the maze and will move by
Always loop
   If space key is touched
      Walk a step
Both examples could be written in many ways, including with or without indentation and as long as they make sense and don’t have logical errors teachers should accept and encourage a wide variety of algorithmic forms which can be easily read in pupils native language.

An algorithm is defined as being precise. Sometimes when pupils are designing/planning they write imprecise algorithms because they leave decisions for when they are coding.

Loop always
     if a key is touched
         Turn right

In this example the pupil has not chosen which key or how many degrees to steer right. In many ways this is algorithmic heresy as it is imprecise but I think it is an acceptable stage in writing algorithms for planning purposes.

Code level

This is where the algorithm is turned into code and the objects are turned into real things on the computer.

Execution level

This is where the code is run. Will it work? Will anything need to be changed? Are there any bugs?

Concept level

This is not part of the levels of abstraction but is how we might introduce sequence, repetition, selection etc outside of a specific programming project.

Sequential thinking

A set of instructions that follow each other.

At first glance this seems so simple. Why even teach sequential thinking. Don’t children already know about sequence? Life does teach children about sequence. Over time most of us find the most efficient ways to get dressed, eat our food, throw or kick a ball etc. Most of us develop efficient sequences to maximise our time doing the things we want to do or so that we can use to beat others in competition. Most of us learn efficient life sequence unconsciously through trial and error and micro-corrections. So, what do we want pupils to learn when working with sequences?

  • There is one right order for some sequences but not all.
  • That the order of instructions in a sequence can be very important to maximise elegance. It is not enough to just have all the right instructions we often need them in the best most elegant order.
  • Timing can be very important in a sequence. Many commands are time sensitive. Turning the right motor on in a programmable buggy for one second or two seconds will result in a two totally different angles of turn. Thinking about timing is the first steps in developing simple workflow thinking.

I love these sequence trajectories by the everyday computing team based on good research.

KS2 pupils program a takeaway Crumble buggy to go around a square

How might we introduce sequential thinking at the concept level?

Simple sequence role-play activities are a great place to start. Can pupils follow a sequence of actions?
Turn round
Can they adapt or write their own?

Everyday sequences are a great next step. Brushing teeth, getting dressed demonstrate that there is a right order. Can pupils order these sequences? Can they write their own sequence for an everyday purpose? Can they test their sequences to see if it works? Younger pupil’s find symbol-based picture algorithms so much easier to use but at some point, we want to move on to written text-based algorithms.

Sequential thinking at the planning level

Can pupils design their own sequence-based algorithms before converting them into code on devices like the Bee-bot, blue-bot, Roamer too, Scratch Jr and Scratch.

Year 2 pupils design a symbol based sequential algorithm using cards before converting it into code on the Bee-bot. Technically pupils are planning with code as the symbols are exactly the same as the code so they could be punched in and run/executed. However, they are thinking about the steps or goals to achieve a goal so they are fulfilling the simpler (KS1 acceptable) understanding of what an algorithm is. 

Code-it resources that develop sequential thinking at concept, planning and code levels

Bee-bot, Blue-bot, Roamer Too modules for KS1
Travelling using Scratch Junior for KS1
Conversation using Scratch 2.0 for LKS2
Understanding sequence reference sheet for pupils PDF
Sequence role play activity PDF
Adapt a sequence activity cards PDF
Monologue and Dialogue Gold Resources 
Sequence and sequence to repetition Gold Resources
Ladybird Munch Game Module
Step by Step App Module

Bold resources use PRIMM & use-modify-create methodology

Thinking with outputs

What am I going to make my algorithm do? What will it show? What will it make happen? What will the user see? Often these are questions about outputs. Everyday algorithms that feature humans often have many different types of output things such as, sound outputs, speech, singing, humming, noises, movement output, walking, running, dancing, graphical outputs, writing, drawing, painting. Programming algorithms have similar outputs, sound output in note, music or audible speech, movement output in things that more on screen or physical movement of motors or servo motors. We can choose to talk about the programming commands that trigger these outputs as output blocks. So, what do we want pupils to learn when working with outputs?

  • That outputs are often the end results of primary algorithms 
  • That outputs are the things people see or experience.
  • That outputs are a good place to start when thinking about a new idea.
  • That outputs such as a picture on a display or sound come out of a digital device.

How might we introduce and develop output thinking?

Firstly, introducing them to the term and what it means as part of a project. Ask pupils what they want their project to achieve or do when they are working in the idea level? Does it involve outputs?

Code-it resources that help to explain output thinking

General input and output pupil support sheet
Programming outputs pupil support sheet

Loopy or repetitive thinking

Instructions that repeat or loop (iterate).

Many pupils have often been taught about loops prior to encountering them in computing. Music is a rich vein for early loopy thinking. Singing or playing repetitive phrases or sounds. Dance steps often contain repetition. They may even have been introduced to simple loopy notation. So, what do we want pupils to learn when developing loopy thinking in computing?

  • That loops can make some sequences much more elegant.
  • That nested loops, one loop inside another loop, has a multiplication effect on any command inside both loops.
  • That some loops are continuous
  • That some loops can be started or stopped by conditions.
  • Variables adapted in a loop are powerful methods of change and workflow.

I love this repetition trajectory by the everyday computing team.

How might we introduce repetitive thinking at the concept level?

Reading and acting out simple everyday dance or music loops are a great place to start.

Role play using simple loops really help, as pupils must read and interpret these to use them.
Loop 4 times
do 3 times
Before pupils are asked to write their own everyday loops

Examples of repetitive thinking at the planning level

Pupils explore regular 2d shape sequence algorithms
Stand where there is some space
walk forward two steps
Turn right a quarter turn
walk forward two steps
Turn right a quarter turn
walk forward two steps
Turn right a quarter turn
walk forward two steps
Turn right a quarter turn
Before being asked to convert these into a more elegant algorithms that uses repetition
Stand in a space

do 4 times
   walk 2 steps
   Turn right 1/4 turn

Repetitive thinking at the code level

Challenging pupils to make a repeated sequence more elegant gives purpose to the construct.

Drawing a triangle in Scratch using more elegant repetitive code

Nested loop algorithms at the concept level

When introducing nested loops, role playing and writing everyday nested loop algorithms using ordinary language helps pupils comprehend the construct.

loop 3 times
   loop twice

Examining the order of what happens enables pupils to to see how the loops interact with each other. Green instructions represent the first loop and red instructions are the outputs from the nested loop. At a later stage pupils could also be asked to predict how many times an output in a nested loop in enacted?


Code-it resources that help to explain loopy or repetitive thinking

Repetition pupil support sheet
Repeat knowledge card
Repeat forever knowledge card
Nested repeat loop knowledge card
Repeat role play activity
Write your own repeat activity
Nested loop role play activity
Nested loop question cards activity or formative assessment opportunity
Exploring right angles Scratch planning
Exploring 2D shapes and patterns planning
Ladybug Munch and the helicopter game Gold programming modules
Dog chase and toy give away Gold Programming Modules
Exploring loops in shape Gold Programming Module
Bold resource use use-modify-create methodology

Thinking with inputs

Things that put in information into the algorithm or program.

Humans can have very simple inputs, the person that shouts stop, go or any other command can be thought of as a human input. Traffic lights and street signs are human input devices. They input information that people acts on. Programming algorithms can also have simple inputs such as the keys on the keyboard, mouse or trackpad click or touch on a tablet. Humans have a set of more complex input sensors. Information goes into a person in different ways, we feel hot or cold through sensors in our skin, we see images through our eyes, we hear noises and words through our ears, we smell nasty and nice odours through our noses, we taste sweet or sour food through our tongue. If I was writing instructions for a human, such as making a cup of tea or chopping a potato I could use some of these complex human sensory inputs. Programming algorithms can have similar sensory inputs that are input through sensors such as distance, light and sound detectors.  So, what do we want pupils to learn when developing input thinking?

  • That algorithms and programs need some way of starting, changing or adapting things using simple inputs.
  • That more complex inputs can capture sensory information that can be used by the algorithm.
  • That some inputs can be captured and stored in data structures such as variables.

How might we introduce thinking with inputs at the concept level?

Separate out simple inputs from more complex inputs. Explain what simple inputs are. Role play starting action outputs triggered by a human input.

Can pupils write their own everyday inputs?

Can pupils identify inputs in algorithm and programming?

Start with everyday human sensory inputs and then relate these to digital ones. Introduce more complex inputs at a later stage. 

Code-it resources that help to explain and use simple input thinking

General input and output facts sheet for pupils
Programming input facts sheet for pupils
Key press input maker card
Mouse or touch input maker card
Green flag input maker card
Simple input role play cards activity
Simple input write your own activity
Simple input scaffold prompts questions activity
Scratch magic carpet planning for lower KS2
Scratch travel Europe planning for lower KS2
Ladybug Munch Input use-modify-create Gold programming resource

The power of conditions to select different pathways

A powerful algorithmic thinking concept is conditional selection. If a condition is met, then one branch or pathway will be taken. If a condition is not met another branch will be accessed. Human algorithmic instructions use conditional selection all the time. If you haven’t had a bath today go and have one now. In this simple example the condition (if had a bath today) directly selects those who will bath and those who won’t. Children who got seven or less marks out of ten in their spelling test need to stay in to learn them, everyone else can go out to play. This slightly more complex mathematical condition (if seven or less marks out of ten) directly controls what each child will be selecting to do (play or study) at break-time. Similarly programming algorithms might have simple conditional selection such

check condition over and over again
   if doodles character is touching colour red on the screen
      then say I love red


ask the user what is 3×3=?
if their answer was 3
   then say correct
   say wrong.

So, what do we want pupils to learn when developing conditional selection thinking?

  • That conditions can be used to halt an algorithm without any selection.
  • That conditions can be used to select a different path.
  • That conditions can be used to switch between two different paths rather like a power switch (on off) or railway point (left or right).

  • That conditions can be used to stop a loop
  • That conditions can be simple or complex
  • That conditions can use mathematical operations such as = (same as) > & < (greater than less than)
  • That one condition out of many can trigger action using OR
  • Than multiple conditions are needed to trigger action using AND
  • That a condition can be reversed using NOT

(the conditions in red are part of the KS3 curriculum but can be used with UKS2 pupils)

The everyday computing team have a great trajectory for selection (conditionals) that you can find here.

How might we introduce conditional selection at the concept level?

The fact that we use conditional selection in everyday speech makes this a great place to start when introducing the concept, can pupils identify which part is the condition and which part is the action or output. Can they role-play the outcomes correctly?

Asking pupils to write their own everyday conditions to start an output, switch between two outputs or stop a loop deepens their conception of these concepts.

At this point introduce it as part of the programming process.

Code-it resources that help to explain and use conditional selection

Conditional selection pupil information sheet 
Condition starts action knowledge card
Condition switches between actions knowledge card
Condition ends loop knowledge card
Conditional selection role play activity
Conditional selection write your own activity
Conditional selection scaffold prompts questions
Maths quiz planning for early KS2 focusing on conditional selection
Adventure game planning
Making choices and wizards choice introduce selection in these Gold Programming Modules
Diving Beetle and Cheese crush Gold Programming modules introduce selection within an indefinite loop The planning in bold uses a use-modify-create methodology

Thinking with variables

The everyday use of variable suggests something that varies or changes. The weather is variable, my son’s moods are variable. However some variables are changeable and others are designed to be constant and not change. Variables are constructs where data (number, number and text we call a string or true and false) is assigned to a name or label. The value of a variable can be referred to using the name. The most common everyday analogy for variables is to liken them to a box or a container with a label (name) on the front but this can lead to misconception at a later stage. A better analogy is the whiteboard. Assigning data is like writing a new value on the whiteboard. Changing the data is easy as we can rub off the old value and write on a new one.

So what do we want pupils to learn?

  • That values can be assigned to a variable
  • That what has been assigned to a variable can be referred to by using its name.
  • That variables that hold numbers can be changed by mathematical operations.
  • That variables need to be initialised at the start of an algorithm or program.
  • That variables can be changed sequentially by using a loop.
  • That variables are one way a computer program can store data.

How might we introduce thinking with variables at the concept level?

Use the whiteboard analogy to introduce name and value

Introduce the word assign to write a value onto a variable. It is by far the best most accurate word and it will stop a lot of misconceptions later.

Introduce the idea of reading the name and getting the value. Pupils can predict what the outcomes will be. They could also write their own everyday algorithms with variables.

Now introduce the idea of changing the value assigned to a variable.

Assign 5 to variable called my_num
Stand up
Bow my_num times
Subtract 2 from my_num
Say my num
Sit down
Wave my_num times
Add 1 to my_num
Say my_num

Pupils could use a whiteboard and change the value as it changes in the everyday algorithm.

Introduce initialising the variable by giving it a value at the beginning of the algorithm.

Do a similar process when introducing the idea that strings can be assigned to a variable without the mathematical operations.

Code-it resources that help to explain and use variable thinking

Number Algorithms with variables PowerPoint
Variables (basics) PDF
Variable number cheat sheet PDF
Shape and variables gold programming module
Placeholder variables gold app programming module
The resources in bold use a use-modify-create methodology

Procedural Thinking

Procedures are self-contained groups of instructions that do a specific thing designed to be used more than once. Everyday cooking algorithms have lots of procedures, boiling, chopping, washing, frying, baking etc.  A salad preparation algorithm uses washing and chopping, frying potatoes uses washing, chopping and frying, preparing rice uses washing and boiling. Some everyday procedures need to be adaptable, boiling needs to know how long for. If we say boil for 15 minutes for rice but boil for 10 minutes for pasta we are adapting the procedure. Programming procedures can also be simple or adaptable. So, what do we want pupils to learn when developing procedural thinking?

  • When to use a procedure and when to avoid one.
  • The difference between a simple procedure and an adaptable one
  • That a procedure should never run itself (recursion) or it gets stuck in a never-ending loop.

How might we introduce procedural thinking?

Start with simple non-adaptable procedures. Make sure pupils are secure in their understanding of these before teaching about adaptable procedure. Open with a good definition of what a procedure is.

Demonstrate programming procedures using simple everyday examples.

Can pupils adapt these before moving onto programming examples. When moving onto adaptable procedures go back and relate these to everyday examples first before teaching about them in a programming context. If during your formative assessment of these concepts during programming pupils show a lack of understanding, go back and use everyday programming examples.

Code-it resources that help to explain and use procedural thinking

Procedure pupils info worksheet
Simple procedures knowledge card
Adaptable procedures knowledge card
Everyday procedures information and questions
Maths quiz with procedures planning
Exploring 2D shapes and patterns including procedures
Basic procedures, nested loops with procedures, adaptable procedures are all Gold shape modules of work. 
New crab maze and orange run introduce basic and adaptable procedures within game programming.
Planning is bold uses a use-modify-create methodology

Workflow thinking

A linear algorithm might start in one place and proceed to a single fixed end. A branching algorithm might start in one point and take many branches with the possibility of multiple end points. Some algorithms might have multiple starting points, branches and multiple end points. Some might have a single start point, multiple sub programs or procedures that handle parts of the program but still end in a single fixed end. Some thinking about workflow can be useful especially when pupils use or design anything that has branches or more complex structures. So, what do we want pupils to learn when developing workflow thinking?

  • That there are many different algorithmic workflow patterns.
  • There is value in sketching out a complex algorithm workflow, abstracting out the complexity so that the overall design can be understood at the planning level.
  • If there are multiple strands to the algorithm where do they interact?

My current thinking is that this can be useful if we spot pupils who are stuck when working on more complex projects rather than as a direct teaching idea for all primary pupils but that might change.

Code-it resources that help to explain and use workflow thinking

Broadcasts in Scratch pupil info sheet
Broadcasts without a wait maker cards
Broadcasts with a wait maker cards

(1) Armoni, Teaching Abstract Thinking in Introduction to Computer Science for 7th Graders, 2013

(2) Jane Waite comes up with these names for the levels of abstraction suitable for primary pupils in her research paper. Abstraction in Action: K-5 teachers’ uses of levels of abstraction, particularly the design level, in teaching programming, 2017 Jane names the levels as shown above but calls the last level running the code. I have changed it to the execution level as it means the same thing but is slightly shorter.