Algorithms - Pseudocode Flashcards

1
Q

What is pseudocode?

A

A way of expressing algorithms in structured English that resembles a computer language.

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

Do you have to write your answers in a particular style of pseudocode?

A

No

Questions will be written using the OCR version

You may answer in any style as long as the meaning could be reasonably understood by a competent programmer

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

How is pseudocode similar to a computer language?

A

It uses similar commands, keywords and structures to those found in computer languages

A solution in pseudocode is converted into a programming language

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

Advantages of pseudocode. (2)

A

It is used to develop the logic ofthe algorithm without considering syntax

A human can follow the logic of an algorithm even if there are syntax errors, while a computer could not execute the same code
This makes it easier to first write a program in pseudocode

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

Disadvantage of pseudocode

A

It cannot be understood by computers

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

Variables in pseudocode

A

Same as python

parcel = “y”

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

Indefinite iteration in pseudocode

A

while (variable) = (value)

endwhile

There is nothing on the end of the line
The rest of the loop is indented after the line

endwhile is used to end the code

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

If statements in pseudocode

A

If (variable) = (value) then

OR

If (variable) = (value) then

else

endif

There is nothing else on the end of the line

“endif” is placed at the end of the code for the statement, still indented

“OR” is used in place of elif
“else” is also used

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

definite iteration

A

for (any word) = (num) to (num)

next (same word)

Any word/variable can be used, like i in python (e.g. index, goes)

next (variable) ends the section of code and is not indented

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

Comments in pseudocode

A

Marked with a //

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

Input in pseudocode

A

Same as python

variable = input(“text”)

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

Display as pseudocode an algorithm that will find the sum of 10 numbers entered by a user and output the result.
Use suitable comments and indentation. [6]

A

total = 0 //the variable total is used to store the sum of the numbers

for goes = 1 to 10 //a loop is set up to run from 1 to 10 as there will be 10 numbers
number = input(“Please enter the number.”) //the user is asked to enter a number
total = total + number //the total is calculated

next goes //closes the for loop
print(total) //the sum of the numbers is output

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