Representing Algorithms Flashcards
All 29 cards in this deck
What is abstraction?
The process of removing unnecessary detail from a problem, so only the details needed to solve it remain.
What is decomposition?
Breaking a problem into a number of sub-problems, so that each sub-problem accomplishes an identifiable task, which might itself be further subdivided.
e.g. a quiz program splits into: store questions, ask questions, check answers, keep score.In a route-planning app, give one detail abstraction keeps and one it removes.
Keeps: roads and distances between places. Removes: colours of buildings, names of shops, scenery.
True or false? Abstraction means breaking a problem into smaller sub-problems.
False. That is decomposition; abstraction is removing unnecessary detail.
In an algorithm, what is an input?
Data that the algorithm takes in to be processed, e.g. a value the user enters (USERINPUT in AQA pseudo-code).
In an algorithm, what is an output?
Data that the algorithm sends out once it has been processed, e.g. a value displayed on the screen (OUTPUT in AQA pseudo-code).
In an algorithm, what is processing?
The steps and decisions that turn the inputs into the outputs, e.g. calculations and comparisons.
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.
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 subroutine symbol — a call to a separate subroutine.
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"; the pass mark is 50
- 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 AQA pseudo-code?
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:
OUTPUT 'Pass' - Put the No branch after
ELSE, then close:ELSE OUTPUT 'Fail' ENDIF
- Write the condition as an IF:
What is a trace table?
A table with a column for each variable, condition or output being tracked. It records how their values change at each step as the algorithm runs. Not every variable has to be included.
In a trace table, what do the columns hold?
One column for each variable being tracked (or array element, such as
arr[0]), plus a column for a condition or for OUTPUT where needed. Each time a value changes, the new value is written further down its column.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.
Name three ways an algorithm can be represented.
Pseudo-code, program code and a flowchart.
What is an algorithm?
A sequence of steps that can be followed to complete a task. A program is an implementation of an algorithm.
What is pseudo-code?
A way of writing out an algorithm in structured, code-like statements without following the rules of any particular programming language.
On a flowchart, how does a sequence differ from selection?
A sequence follows a single path from Start to Stop with no decisions; selection has a decision diamond that splits the flow into different routes.
How does iteration appear on a flowchart?
An arrow leads back to an earlier point, usually from a decision, so a group of steps is repeated.
When decomposing a problem, when do you stop breaking a sub-problem down?
When each sub-problem accomplishes one identifiable task, simple enough to be written as a single subroutine.
Name two ways to determine the purpose of a simple algorithm.
Trace it with test data in a trace table, and use visual inspection: read the code to see what it inputs, how it changes the variables and what it outputs.