1. Fundamentals of algorithms Flashcards
Define algorithm (important)
An algorithm is a sequence of steps that can be followed to complete a task
An algorithm that can be translated into any programming language is …
Language independent
What is the focus on in an algorithm, and what is it not on?
Whether algorithms are designed with pseudo-code or flowcharts, the focus is on the logic of the steps instead of the programming language because programmers should be able to translate an algorithm into any programming language, for example, from Python to C++.
What is processing ?
Processing refers to any operation the computer system is performing on data, for example doing a calculation or searching for something.
Flow chart symbol:
Represents the flow from one component to the next
Arrow(/line)
Flow chart symbol:
Process - an action
Square box
Flow chart symbol:
Subroutine
Rectangle with a vertical line on each side
Flow chart symbol:
Input/output
Parallelogram
Flow chart symbol:
Decision (yes/no/true/false decision)
Diamond
Flow chart symbol:
Start/Stop (terminator)
Oval
Decomposition definition
Decomposition means breaking a problem into a number of sub-problems, so that each sub- problem accomplishes an identifiable task, which might itself be further subdivided.
Decomposition definition (Important)
Decomposition means breaking a problem into a number of sub-problems, so that each sub- problem accomplishes an identifiable task, which might itself be further subdivided.
Abstraction definition (important)
Abstraction is the process of removing unnecessary detail from a problem
(so that the important details can be focused on. This can make solving the problem easier.)
Real life example of abstraction
An example of abstraction is the London Underground map. It details tube lines, services that run on them and the stations. This is all that is required for a passenger to be able to plan a journey from one station to another. Other details, such as real geographical location, distance between stations, depth underground and number of platforms are not included as they are irrelevant to journey planning on the Underground.
What is ‘dry running’ an algorithm (definition not important)
Dry running an algorithm means to assign the values to variables of an algorithm and to do any processing that takes place without translating it into code.
2 ways to determine the purpose of an algorithm
Trace tables, visual inspection
When are trace tables used?
Used when testing a program to record changes in variable values as code executes.
Contract a trace table.
Input is 5.
num ← USERINPUT
FOR number ← 1 TO 10
OUTPUT number * num
ENDFOR
Num Number Output
1 5 5
2 10
3 15
4 20
5 25
6 30
7 35
8 40
9 45
10 50
When to use visual inspection?
Some algorithms follow a pattern that can be recognised. Many of these are referred to as standard algorithms and often follow a set pattern for searching for or sorting data. Sometimes it is clear what this is just by looking at the pseudo-code.
When to use visual inspection? (Don’t need to remember:
‘Students should be able to use trace tables and visual inspection to determine how simple algorithms work and what their purpose is.’)
Some algorithms follow a pattern that can be recognised. Many of these are referred to as standard algorithms and often follow a set pattern for searching for or sorting data. Sometimes it is clear what this is just by looking at the pseudo-code.
Pseudo-code algorithm to search through a word and match a letter (hangman)
guess ← USERINPUT
FOR i ← 0 TO LEN(word)
IF word[i] = guess THEN
OUTPUT “found”
ENDIF
ENDFOR
What does efficiency look at? (2)
Efficiency looks at how much time it takes to run a particular algorithm and how much space is needed.
What does efficiency look at? (2)
Efficiency looks at how much time it takes to run a particular algorithm and how much space is needed.
(But “Exam questions in this area will only refer to time efficiency”)