Computational thinking involves four key strands: abstraction, decomposition, data modelling, pattern recognition and algorithmic thinking.
Abstraction gives us the power to deal with complexity.
An algorithm is an abstraction of a process that takes inputs, executes a sequence of steps, and produces outputs.
An abstract data type defines an abstract set of values and operations for manipulating those values.
Decomposition means breaking problems down into sub-problems in order to explain a process more clearly. Decomposition leads us to the concept of program modules and using procedures and functions.
Data modelling involves analysing and organising data. We can set up abstract data types to model real-world concepts, such as queues or stacks.
Pattern recognition means looking for patterns or common solutions to common problems and using these to complete tasks in a more efficient and effective way.
Algorithm design involves developing step-by-step instructions to solve a problem.
Structured English: a subset of the English language that consists of command statements used to describe an algorithm
Pseudocode: a way of using keywords and identifiers to describe an algorithm without following the syntax of a particular programming language
Flowchart: shapes linked together to represent the sequential steps of an algorithm
Variable: a storage location for a data value that has an identifier
We need to be able to refer to a specific memory location so that we can write statements of what to do with the value stored there. We refer to these named memory locations as variables.
You can imagine these variables like boxes with name labels on them. When a value is input, it is stored in the box with the specified name (identifier) on it.
Identifier table - a table listing the variable identifiers required for the solution, with explanations and data types.
INPUT Number
NumberOfGuesses ← 1
NumberOfGuesses ← NumberOfGuesses + 1
Value2 ← Value1
Temp ← Value1
Value1 ← Value2
Value2 ← Temp
Nested IF statements: conditional statements within conditional statements
IF A < B
THEN
<statement(s)>
ELSE
<statement(s)>
ENDIF
IF Guess = SecretNumber
THEN
OUTPUT "Well done. You have guessed the secret number"
ELSE
IF Guess > SecretNumber AND NumberofGuesses = 10
THEN
OUTPUT "You still have not guessed the secret number"
ELSE
IF Guess > SecretNumber
THEN
OUTPUT "secret number is smaller"
ELSE
OUTPUT "secret number is greater"
ENDIF
ENDIF
ENDIF
Rogue value - a value used to terminate a sequence of values
Nested loop - loop containing another loop
The problem to be solved: Take 10 numbers as input and output the largest number.
INPUT BiggestSoFar
Counter ← 1
REPEAT
INPUT NextNumber
Counter ← Counter + 1
IF NextNumber > BiggestSoFar
THEN
BiggestSoFar ← NextNumber
ENDIF
UNTIL Counter = 10
OUTPUT BiggestSoFar
The problem to be solved: Take 10 numbers as input and output the largest number.
INPUT BiggestSoFar
FOR Counter ← 2 TO 10
INPUT NextNumber
IF NextNumber > BiggestSoFar
THEN
BiggestSoFar ← NextNumber
ENDIF
NEXT Counter
OUTPUT BiggestSoFar
A sequence of non-zero numbers is terminated by 0. Take this sequence as input and output the largest number.
INPUT BiggestSoFar
REPEAT
INPUT NextNumber
IF NextNumber > BiggestSoFar
THEN
BiggestSoFar ← NextNumber
ENDIF
UNTIL NextNumber = 0
OUTPUT BiggestSoFar
INPUT NextNumber
BiggestSoFar ← NextNumber
WHILE NextNumber <> 0 DO // sequence terminator not encountered
INPUT NextNumber
IF NextNumber > BiggestSoFar
THEN
BiggestSoFar ← NextNumber
ENDIF
ENDWHILE
OUTPUT BiggestSoFar
SET value for secret number
REPEAT the following UNTIL correct guess
INPUT guess
count number of guesses
COMPARE guess with secret number
OUTPUT comment
OUTPUT number of guesses
SecretNumber ← Random
NumberOfGuesses ← 0
REPEAT
INPUT Guess
NumberOfGuesses ← NumberOfGuesses + 1
IF Guess > SecretNumber
THEN
// the player is given the message to input a smaller number
ENDIF
IF Guess < SecretNumber
THEN
// the player is given the message to input a larger number
ENDIF
UNTIL Guess = SecretNumber
OUTPUT NumberOfGuesses
SecretNumber ← Random
INPUT Guess
NumberOfGuesses ← 1
WHILE Guess <> SecretNumber DO
IF Guess > SecretNumber
THEN
// the player is given the message to input a smaller number
ENDIF
IF Guess < SecretNumber
THEN
// the player is given the message to input a larger number
ENDIF
INPUT Guess
NumberOfGuesses ← NumberOfGuesses + 1
ENDWHILE
OUTPUT NumberOfGuesses
Take 10 numbers as input and output the sum of these numbers and the average.
RunningTotal ← 0
FOR Counter ← 1 TO 10
INPUT NextNumber
RunningTotal ← RunningTotal + NextNumber
NEXT Counter
OUTPUT RunningTotal
Average ← RunningTotal / 10
OUTPUT Average
Take as input two numbers and a symbol. Output a grid made up entirely of the chosen symbol, with the number of rows matching the first number input and the number of columns matching the second number input.
&&&&&&&
&&&&&&&
&&&&&&&
INPUT NumberOfRows
INPUT NumberOfColumns
INPUT Symbol
FOR RowCounter ← 1 TO NumberOfRows
FOR ColumnCounter ← 1 TO NumberOfColumns
OUTPUT Symbol // without moving to next line
NEXT ColumnCounter
OUTPUT Newline // move to the next line
NEXT RowCounter
Stepwise refinement - breaking down the steps of an outline solution into smaller and smaller steps
Take as input a chosen symbol and an odd number. Output a pyramid shape made up entirely of the chosen symbol, with the number of symbols in the final row matching the number input.
A
AAA
AAAAA
AAAAAAA
AAAAAAAAA
Set up initial values
REPEAT
Output number of spaces
Output number of symbols
Adjust number of spaces and number of symbols to be output in next row UNTIL the required number of symbols have been output in one row
INPUT Symbol
INPUT MaxNumberOfSymbols
NumberOfSpaces ← (MaxNumberOfSymbols – 1) / 2
NumberOfSymbols ← 1
REPEAT
INPUT MaxNumberOfSymbols
UNTIL MaxNumberOfSymbols MOD 2 = 1
// MOD 2 gives the remainder after integer division by 2
FOR i ← 1 TO NumberOfSpaces
OUTPUT Space // without moving to next line
NEXT i
FOR i ← 1 TO NumberOfSymbols
OUTPUT Symbol // without moving to next line
NEXT i
OUTPUT Newline // move to the next line
NumberOfSpaces ← NumberOfSpaces – 1
NumberOfSymbols ← NumberOfSymbols + 2
UNTIL NumberOfSymbols > MaxNumberOfSymbols
// Set Values
INPUT Symbol
// Input max number of symbols (an odd number)
REPEAT
INPUT MaxNumberOfSymbols
UNTIL MaxNumberOfSymbols MOD 2 = 1
NumberOfSpaces ← (MaxNumberOfSymbols – 1) / 2
NumberOfSymbols ← 1
REPEAT
// Output number of spaces
FOR i ← 1 TO
OUTPUT Space // without moving to next line
NEXT i
// Output number of symbols
FOR i ← 1 TO NumberOfSymbols
OUTPUT Symbol // without moving to next line
NEXT i
OUTPUT Newline // move to the next line
// Adjust Values For Next Row
NumberOfSpaces ← NumberOfSpaces – 1
NumberOfSymbols ← NumberOfSymbols + 2
UNTIL NumberOfSymbols > MaxNumberOfSymbols
Procedure - a sequence of steps that is given an identifier and can be called to perform a sub-task
Function - a sequence of steps that is given an identifier and returns a single value; function call is part of an expression
Local variable - a variable that is accessible only within the module in which it is declared
Global variable - a variable that is accessible from all modules
CALL SetValues
REPEAT
CALL OutputSpaces
CALL OutputSymbols
CALL AdjustValuesForNextRow
UNTIL NumberOfSymbols > MaxNumberOfSymbols
definitions
PROCEDURE SetValues
INPUT Symbol
CALL InputMaxNumberOfSymbols // need to ensure it is an odd number
NumberOfSpaces ← (MaxNumberOfSymbols - 1) / 2
NumberOfSymbols ← 1
ENDPROCEDURE
PROCEDURE InputMaxNumberOfSymbols
REPEAT
INPUT MaxNumberOfSymbols
UNTIL MaxNumberOfSymbols MOD 2 = 1
ENDPROCEDURE
PROCEDURE OutputSpaces
FOR Count1 ← 1 TO NumberOfSpaces
OUTPUT Space // without moving to next line
NEXT Count1
ENDPROCEDURE
PROCEDURE OutputSymbols
FOR Count2 ← 1 TO NumberOfSymbols
OUTPUT Symbol // without moving to next line
NEXT Count2
OUTPUT Newline // move to the next line
ENDPROCEDURE
PROCEDURE AdjustValuesForNextRow
NumberOfSpaces ← NumberOfSpaces – 1
NumberOfSymbols ← NumberOfSymbols + 2
ENDPROCEDURE
CALL SetValues
REPEAT
CALL OutputSpaces
CALL OutputSymbols
NumberOfSpaces ← AdjustedNumberOfSpaces
NumberOfSymbols ← AdjustedNumbeOfSymbols
UNTIL NumberOfSymbols > MaxNumberOfSymbols
definitions
PROCEDURE SetValues
INPUT Symbol
MaxNumberOfSymbols ← ValidatedMaxNumberOfSymbols
NumberOfSpaces ← (MaxNumberOfSymbols - 1) / 2
NumberOfSymbols ← 1
ENDPROCEDURE
FUNCTION ValidatedMaxNumberOfSymbols RETURNS INTEGER
REPEAT
INPUT MaxNumberOfSymbols
UNTIL MaxNumberOfSymbols MOD 2 = 1
RETURN MaxNumberOfSymbols
ENDFUNCTION
PROCEDURE OutputSpaces
FOR Count1 ← 1 TO NumberOfSpaces
OUTPUT Space // without moving to next line
NEXT Count1
ENDPROCEDURE
PROCEDURE OutputSymbols
FOR Count2 ← 1 TO NumberOfSymbols
OUTPUT Symbol // without moving to next line
NEXT Count2
OUTPUT Newline // move to the next line
ENDPROCEDURE
FUNCTION AdjustedNumberOfSpaces RETURNS INTEGER
NumberOfSpaces ← NumberOfSpaces – 1
RETURN NumberOfSpaces
ENDFUNCTION
FUNCTION AdjustedNumberOfSymbols RETURNS INTEGER
NumberOfSymbols ← NumberOfSymbols + 2
RETURN NumberOfSymbols
ENDFUNCTION