Designing, Creating & Refining Algorithms Flashcards
All 40 cards in this deck
What is an input in a computer system?
Data inserted into a system for processing and/or storage.
What is an output in a computer system?
Data sent out of a system.
What is a process in a computer system?
The steps and decisions required to transform inputs into outputs.
What are the steps to identify the inputs, processes and outputs of a problem?
e.g. a program that asks for a length and a width and displays the area
- List the data entered into the system: length, width
- List the calculations/decisions needed: area = length width
- List the data sent out: display the area
True or false? A value that the program calculates and displays on screen is an input.
False. It is an output — inputs are data entered into the system.
True or false? The inputs, processes and outputs should be identified before an algorithm is designed.
True. The problem must be decomposed first so you know what data is needed and what processing is required.
What is a structure diagram?
A visual chart showing how the parts of a system are broken down, interconnected and organised.
In a structure diagram, what does each box represent?
A separate part (subsection) of the system.
How is a structure diagram organised?
Hierarchically — the whole problem is the top box, with subsections on the levels below joined by lines to show their links.
Give one advantage of using a structure diagram.
It is a planning tool used before coding, so errors or missing parts are spotted early.
Give one drawback of using a structure diagram.
It becomes confusing if made overly detailed, and must be updated whenever the system changes.
True or false? A structure diagram shows the order in which the steps of an algorithm are carried out.
False. It shows how the problem breaks into subsections and how they link; a flowchart shows the order of steps.
Which flowchart symbol is a rounded rectangle (oval), and what is it used for?
The terminal symbol — the Start or Stop of the algorithm.
Which flowchart symbol is a plain rectangle, and what is it used for?
The process symbol — a calculation or an assignment to a variable.
Which flowchart symbol is a diamond, and what is it used for?
The decision symbol — a condition with two labelled exits (Yes/No).
Which flowchart symbol is a parallelogram, and what is it used for?
The input/output symbol — data entered into or sent out of the algorithm.
Which flowchart symbol is a rectangle with two extra vertical lines at its sides?
The sub program symbol — a call to a separate sub program.
What do the lines with arrowheads in a flowchart show?
The flow of control — the order and direction in which the symbols are followed.
What are the steps to work out the output of a flowchart for a given input?
e.g. input 5 to a flowchart that doubles a number then adds 1
- Start at the Start terminal and follow the arrows: number = 5
- Carry out each symbol's instruction, taking the branch that matches at a decision: , then
- Record whatever reaches an output symbol: output 11
What are the steps to complete a missing decision in a partially drawn flowchart?
e.g. an empty diamond whose Yes branch outputs "Pass"
- Look at what each branch out of the symbol does: Yes gives "Pass"
- Work out the condition that must be true to take the Yes branch: score >= 50
- Write it inside the diamond, labelling both exits Yes and No
What are the steps to draw a flowchart for a described algorithm?
e.g. input a number and output "Big" if it is over 100
- Begin with a Start terminal and a parallelogram for each input: input number
- Add rectangles for processes and diamonds for decisions with Yes/No exits: number > 100?
- Add output symbols and a Stop terminal, joining everything with arrows: output "Big"
What are the steps to convert a flowchart decision into pseudocode?
e.g. a diamond "score > 50?" with Yes → output "Pass", No → output "Fail"
- Write the condition as an if:
if score > 50 then - Put the Yes branch underneath:
print("Pass") - Put the No branch after
elseand close:else print("Fail") endif
- Write the condition as an if:
Which operators are accepted for concatenating (joining) two strings in pseudocode?
+,&or., or a sensible function such asconcat(). Commas are not accepted.True or false? In pseudocode you can write
word1 == "Hello"to store the string "Hello" inword1.False. Assignment uses a single
=;==is a comparison, not an assignment.What is nested selection?
e.g. only checking the password once the username is correct
An if statement placed inside another if statement, so the inner condition is tested only when the outer one is true.
What is nested iteration?
e.g. a loop of 4 stars inside a loop of 3 rows
A loop placed inside another loop; the inner loop runs fully on every pass of the outer loop (here, 12 stars).
Give one way to refine an algorithm to make it more efficient.
Replace repeated lines of code with a loop (iteration).
e.g. one loop running five times instead of five separate input lines.What is a syntax error?
An error that occurs when code does not follow the rules of the programming language.
What is a logic error?
An error where the program runs without stopping but does not do what is expected.
Give two examples of syntax errors in code.
Misspelling a statement/keyword and a missing bracket or quotation mark.
Also: using a variable before it is declared, spaces in a variable name.Give two examples of logic errors in code.
Using the wrong logical/Boolean operator and creating an infinite loop.
Also: brackets in the wrong place in a calculation, or an array element outside scope.True or false? A program containing a syntax error will still run but give the wrong answer.
False. A program will not run with a syntax error; it is a logic error that runs but gives incorrect results.
What are the steps to identify and correct a logic error in a given algorithm?
e.g. line 03 reads
total = num1 - num2but the two numbers should be added- Compare what each line does with what the program should do: line 03 subtracts
- State the line number: Line 03
- Give the corrected code, or an unambiguous description of the change:
total = num1 + num2
What is a trace table?
A table containing all the variables in a program with their values recorded at each step of execution.
What is a dry run?
A manual test of a program on paper, using a trace table to follow the execution step by step.
In a trace table, what do the rows and the columns represent?
Each row is one instruction (or pass) and each column is one variable, plus a column for the output.
In a trace table for an algorithm containing a loop, what is recorded for each pass of the loop?
A new row giving the variable values after that pass, including the loop counter and the result of the condition.
True or false? A trace table is used to find syntax errors in a program.
False. It locates logic errors by showing where actual variable values differ from the expected values.
What are the steps to complete a missing line in a given function written in Exam Reference Language?
e.g. a functionaddBonus(score)that must add 10 to the score and give the new score back- Use the parameters already given, with no extra inputs: use
score - Write the missing statement in correct syntax:
score = score + 10 - Return the updated value:
return score
- Use the parameters already given, with no extra inputs: use
When asked to complete missing lines of an algorithm, is a flowchart or structured English accepted instead of code?
Yes — as long as it makes clear exactly what the new lines do and does not simply repeat the question.