Algorithms 2.1 Computational thinking, errors, trace tables, Flashcards

1
Q

State the three principles for computational thinking

A

Abstraction
Decomposition
Algorithmic thinking

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define abstraction

A

Abstraction is the process of removing unnecessary details and including only relevant details

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define decomposition

A

Decomposition is breaking a complex problem down into smaller, more manageable parts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define algorithmic thinking

A

Algorithmic thinking is a way of getting to a solution by identifying the individual steps needed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define algorithm

A

An algorithm is a step-by-step set of rules or instructions used to solve a problem or carry out a task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Advantages of problem decomposition

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

“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

A

Input Length :Real/Float
Height :Real/Float
Depth :Real/Float

Process Length x Height x Depth
Output Volume :Real/Float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define syntax error

A

Syntax errors are errors which break the grammatical rules of the programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What do syntax errors cause in a program

A

Syntax errors stop the program from being run/translated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define logic error

A

Logic errors are errors which produce unexpected output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do logic errors cause in a program

A

On their own, logic errors won’t stop the program from running, but cause the program to produce an unexpected output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

/ /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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is tracing execution

A

Tracing execution is a vital skill for understanding program flow and testing the accuracy of an algorithm for logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a trace table

A

A trace table is a table that keeps track of the value of certain variables as a program is run

17
Q

What do trace tables involve

A

Involves examining a printed extract of program code and running through the program

Take each line at a time and write out in a trace table, the current state of each variable

Noting down any output the program produces

Each variable present in the program should have its own column in the trace table

A new row should be added under any column if the state of a variable changes

18
Q

What does a column represent in a trace table

A

The columns of a trace table usually represnent variables

19
Q

What does a row represent in a trace table

A

The rows in a trace table represents the values that the variables take at a particular point in the algorithm.

20
Q

Rewrite this pseudocode/ocr exam reference language code in python

for i = 0 to 9
print (“i = “ + i)
next i

A

Next for loop

for i= 1 …. all the way to for i = 9

Python

for i in range (0,9+1):

print(“i =”, i)

21
Q

Rewrite this algorithm in OCR exam reference language/pseudocode

number =int(input(“Enter a number”))

total = 1

for counter in range (1,number + 1):

total=total*counter

print(total)

A

number = print(“Enter a number”)
total =1
for counter = 1 to number
total = total * counter
next counter
output (total)

22
Q

Create a trace table for this program

number = print(“Enter a number”)
total =1
for counter = 1 to number
total = total * counter
next counter
output (total)

take number as 5

A

number | counter | total
5 1 1
2 1
3 2
4 6
5 24
6 120

Output window: (imagine what the blue output window looks like on python)

Enter a number
5
120