CS Revision Notes
CS Revision Notes
Algorithm
Flowchart symbols
Terminators Process Input/output Decision Continuation
Variable
A variable is used to store data that can change during
the running of a program
Can use a variable without knowing its value
Constant
A constant is used to store data that will not be changed
during the running of a program
Value only needs to be changed once if circumstances
change/during the initialisation process
Variable + Constant Names
1. No spaces
2. Letter and numbers only
3. Must start with a letter
Variable
Comment
name
A poor choice – it has no
l
meaning
length Okay but a bit vague
Sequence
A series of steps executed one after the other and all of the statements are
executed.
Selection/Condition
A series of steps that are executed when criteria is met.
Sometimes not all the statements are executed.
A) un nested IF......... IF......THEN....ENDIF
B) nested IF........IF....THEN....ELSE....ENDIF ....checks for complex condition
C) CASE...OF......OTHERWISE.....ENDCASE
l
Allows multiple selections were one out of several branches of code is executed
depending on the value of the variable )
Simplifies pseudocode so it is more understandable
Checks for a value from a discrete large number of values
Repetition/Iteration/Loops
A sequence of steps that are executed an n number of times
Loop Structures
FOR ... TO ... NEXT
Count Controlled Loop
A set number of repetitions
You need to specify the number of times the loop needs to be executed
WHILE ... DO ... ENDWHILE
Pre-condition loop
Has criteria check at start / pre-test
This loop may never run
REPEAT ... UNTIL
Post-Condition loop
Has criteria check at end / post-test
This loop will always run at least once
A repetition, where the number of repeats is not known
Counting Statement
Increments the value of a counter gradually to find number of items in a list
Or
Use a rogue value to terminate the process and alert the user
that this value is the value needed to end the iterations.
A rogue value is a value of same data type as data entered but is
outside range of normal expected values
Arrays
A list of items of the same data type stored under a single name
Used to reduce the number of variables used
Any item can be found using an index number to show its place in the list
Name
The name identifying the array
Size
The number of elements in the array
Element
Each item in an array is called an element
Index
The index number identifies the position of an element in the array
Type
All elements in an array have the same data type
Dimension
Number of indexes required to access an elemnt
The organisational structure of the array: 1D is a list; 2D is a table
#
Boolean True Data is of one of two values
Why does the computer need to know if the number is integer or real?
.
Because real numbers take up more space. If a database file has a million
records, this can represent a lot of wasted space.
Structure diagrams
Shows hierarchy of different components which make up a system and the relationship between them
It shows an overview of the program or subroutine
Library routines
Pre written code to add in you program to carry out a common task
It is a list of instructions that are used often
Which is given a name
Can be called from another program
Makes writing and testing program easier and faster as it was already tested and debugged
Subroutine
Is a self contained piece of code that can be called when needed that consists of a set of
programming instructions to perform a given task making a subsystem
If written in high level language Then example procedure and function
Procedure
A subroutine that does not have to return a value.
An example of a predefined procedure could be a ‘clear the screen’ command that would clear
whatever is currently displayed when running the program
Function
A subroutine that always returns a value
Example: converting integers to strings
Trace Table
Shows the value of variables as you manually test you data
Stages in producing an algorithm
READ=INPUT
PRINT=OUTPUT
Explain/Describe/Show
All mean that you should write English statements not pseudocode.
ONLY WRITE PSEUDOCODE WHEN ASKED TO DO SO