Interpreting, correcting and completing algorithms Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are dry runs, how are they used, and why are they helpful?l

A

A method used to investigate the functioning of an algorithm

Mental or pen/paper run through of an algorithm that does one step at a time

The following are examined at each step:

  • inputs needed
  • data processed
  • outputs

A dry run helps you to understand an algorithm and find any errors

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

What are trace tables, how are they used and why?

A

A trace table is used while the dry run is being worked through to write down the values of each variable, input, output and how they change as the program is running

There are columns for each variable and rows for each step in the algorithm

It is helpful as it makes it easy to keep track

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

Create a trace table for the following algorithm.

number = 3
for index = 1 to 3
    number = number + index
    print(number)
next index

[4]

A

Number index output
3
4 1 4
6 2 6
9 3 9

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

Investigate the following algorithm and create a trace table using these values.
At the start of the following algorithm, X = 2 and Y = 3

Z = X + Y
while X < Z
    X = X + 1
    Y = Y + X
endwhile
print(Y)
A

(Each section is one row of the table)

Z: 5
X: 3
Y: 6
Output:

Z: 5
X: 4
Y: 10
Output:

Z: 5
X: 5
Y: 15
Output:

Z:
X:
Y:
Output: 15

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

Create a trace table for the following algorithm

number = 3
print(number)
for index = 1 to 3
    number = number + 6
    print(number)
next x
A

(Each section is one row of the table)

number: 3
index:
output: 3

number: 9
index: 1
output: 9

number: 15
index: 2
output: 15

number: 21
index: 3
output: 21

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