Algorithms 2.1 Computational thinking, errors, trace tables, Flashcards
State the three principles for computational thinking
Abstraction
Decomposition
Algorithmic thinking
Define abstraction
Abstraction is the process of removing unnecessary details and including only relevant details
Define decomposition
Decomposition is breaking a complex problem down into smaller, more manageable parts
Define algorithmic thinking
Algorithmic thinking is a way of getting to a solution by identifying the individual steps needed
Define algorithm
An algorithm is a step-by-step set of rules or instructions used to solve a problem or carry out a task.
Advantages of problem decomposition
Makes problems easier to solve
Different people can work on different parts of a problem at the same time reducing development time (and cost)
• (e.g. In a computer game you may have artists working on the graphics, a special effects team that is able to work on the particle effects, and an audio team working on the sound.)
Program components developed in one program can easily be used in other programs. (This make future iterations of the game, much easier and quicker to develop)
“Write a program to calculate the volume of a fish tank based on its dimensions and report the result to the user”
Give the input, processes and outputs
Input Length :Real/Float
Height :Real/Float
Depth :Real/Float
Process Length x Height x Depth
Output Volume :Real/Float
“Write a program which will ask the user for the number of students in their class and then prompt them to enter each of their test scores in a range 0 -100. It should then output the highest, lowest and average score to the user”
Write the input, processes and outputs
Input NumOfStudents : Integer
CurrentScore : Integer
Process TotalScore = TotalScore + CurrentScore
AverageScore : TotalScore / NumOfStudents
Store list of scores in an array: • Loop through array and return min score • Loop through array and return max score
Output MinScore : Integer
MaxScore : Integer
AveScore : Real/Float
Define syntax error
Syntax errors are errors which break the grammatical rules of the programming language.
What do syntax errors cause in a program
Syntax errors stop the program from being run/translated
Define logic error
Logic errors are errors which produce unexpected output.
What do logic errors cause in a program
On their own, logic errors won’t stop the program from running, but cause the program to produce an unexpected output
Spot the error in the program and suggest how it can be fixed
/ /program to work out if you are old enough to vote
const voting_age = 18
your _ age = (input(“How old are you? “))
if (your_age >= voting_age) then
print(“You are old enough to vote”)
else
print(“You are not old enough to vote”)
endif
Missing type conversion from string to integer
/ /program to work out if you are old enough to vote
const voting_age = 18
your _ age =#(input(“How old are you? “))
if (your_age >= voting_age) then
print(“You are old enough to vote”)
else
print(“You are not old enough to vote”)
endif
your _ age =int(input(“How old are you? “))
Syntax error
Spot the error in the program and suggest how it can be fixed
/ /program to work out if you are old enough to vote
const voting_age = 18
your _ age =int (input(“How old are you? “))
if (your_age <= voting_age) then
print(“You are old enough to vote”)
else
print(“You are not old enough to vote”)
endif
/ /program to work out if you are old enough to vote
const voting_age = 18
your _ age = (input(“How old are you? “))
if (your_age #<= voting_age) then
print(“You are old enough to vote”)
else
print(“You are not old enough to vote”)
endif
<= Means that if you are 18 or younger you can vote
Logic error
A ‘less than or equals to’ operator is being used, instead of a ‘greater than or equals to’ operator
REFINEMENT: if (your_age >= voting_age) then
What is tracing execution
Tracing execution is a vital skill for understanding program flow and testing the accuracy of an algorithm for logic