0% found this document useful (0 votes)
9 views38 pages

Ilovepdf Merged

Uploaded by

Sameer Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views38 pages

Ilovepdf Merged

Uploaded by

Sameer Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

AQA Computer Science AS-Level

3.1.1 Programming
Advanced Notes

www.pmt.education
Specification:

3.1.1.1 Data types:


Understand the concept of a data type.
Understand and use the following appropriately:
● integer
● real/float
● Boolean
● character
● string
● date/time
● pointer/reference
● records (or equivalent)
● arrays (or equivalent)
Define and use user-defined data types based on language-defined
(built-in) data types.

3.1.1.2 Programming concepts:


Use, understand and know how the following statement types can be
combined in programs:
● variable declaration
● constant declaration
● assignment
● iteration
● selection
● subroutine (procedure / function)
Use definite and indefinite iteration, including indefinite iteration with the
condition(s) at the start or the end of the iterative structure. A theoretical
understanding of condition(s) at either end of an iterative structure is required,
regardless of whether they are supported by the language being used.
Use nested selection and nested iteration structures.
Use meaningful identifier names and know why it is important to use
them

www.pmt.education
3.1.1.3 Arithmetic operations
Be familiar with and be able to use:
● addition
● subtraction
● multiplication
● real/float division
● integer division, including remainders
● exponentiation
● rounding
● truncation

3.1.1.4 Relational operations in a programming language


Be familiar with and be able to use:
● equal to
● not equal to
● less than
● greater than
● less than or equal to
● greater than or equal to

3.1.1.5 Boolean operations in a programming language


Be familiar with and be able to use:
● NOT
● AND
● OR
● XOR

3.1.1.6 Constants and variables in a programming language


Be able to explain the differences between a variable and a constant.
Be able to explain the advantages of using named constants.

www.pmt.education
3.1.1.7 String-handling operations in a programming language
Be familiar with and be able to use:
● length
● position
● substring
● concatenation
● character → character code
● character code → character
● string conversion operations

3.1.1.8 Random number generation in a programming language


Be familiar with, and be able to use, random number generation.

3.1.1.9 Exception handling


Be familiar with the concept of exception handling.
Know how to use exception handling in a programming language with
which students are familiar.

3.1.1.10 Subroutines (procedures/functions)


Be familiar with subroutines and their uses.
Know that a subroutine is a named ‘out of line’ block of code that may
be executed (called) by simply writing its name in a program statement.
Be able to explain the advantages of using subroutines in programs.

3.1.1.11 Parameters of subroutines


Be able to describe the use of parameters to pass data within
programs.
Be able to use subroutines with interfaces.

3.1.1.12 Returning a value/values from a subroutine


Be able to use subroutines that return values to the calling routine.

www.pmt.education
3.1.1.13 Local variables in subroutines
Know that subroutines may declare their own variables, called local
variables, and that local variables:
● exist only while the subroutine is executing
● are accessible only within the subroutine
Be able to use local variables and explain why it is good practice to do
so.

3.1.1.14 Global variables in a programming language


Be able to contrast local variables with global variables.

www.pmt.education
Data Types

The way in which data is stored depends on what the data is. A ​data type​ is defined by the
values it can take​ or the​ operations which can be performed on it​.

In some situations, it might be possible to store one piece of data using various ​different
data types. In this case, the programmer must decide which option is the ​best suited​ to
solving a particular problem or which is the ​most memory-efficient​.

For example, if a programmer needs to store a user’s age in years, they could use a ​string
or an ​integer​. In this situation, using an integer would be the best option, because a
person’s age is only ever going to contain numerical digits.

Data type Description

Integer A whole number, positive or negative, including zero.

Real / Float A positive or negative number which can have a


fractional part.

Boolean A value which is either true or false.

Character A single number, letter or symbol.

String A collection of characters.

Data / Time A way of storing a point in time, many different formats


are used.

Pointer / Reference A way of storing memory addresses.

Records A collection of fields, each of which could have a


different data type. You can think of a record as a row
from a table.

Arrays A finite, indexed set of related elements each of which


has the same data type.

www.pmt.education
User-defined data types

User-defined data types​ are derived from ​existing data


types​ in order to create a ​customised data structure​.
Creating and using user-defined data types allows a
programmer to ensure that a solution is ​as memory
efficient as possible​.

For example, a shop might use a user-defined data


type called ​Customer​to store information about their
customers. The user-defined data type might have
attributes ​like ​Forename​
, ​Surname​and ​EmailAddress​.

The way in which you use user-defined data types ​differs between programming
languages​. It’s important that you know how to use them in your chosen language.

Programming Concepts

Programming languages support a ​variety of different statement types​, some of which are
explained in the table below.

Statement type Description

Variable declaration Creating a variable for the first time, giving it a ​name
and sometimes a ​data type​. This allocates a portion of
the computer’s memory to the variable.

Constant declaration The same as variable declaration, but when creating a


constant​. The value of a constant ​does not change
while the program is running.

Assignment Giving a constant or variable a value.

Iteration Repeating ​an instruction, this could be ​definite ​or


indefinite ​(see below).

Selection Comparing values​ and ​choosing an action​ based on


those values.

Subroutine A named ​block of code​ containing a ​set of instructions


designed to perform a ​frequently used​ operation.

www.pmt.education
Definite and indefinite iteration
Iteration is the process of ​repeating a block of code​. Examples of iteration include ​for
loops and ​while​loops.

Definite iteration is a type of iteration in which the ​number of repetitions​ required is ​known
before the loop starts.

In contrast to definite iteration, indefinite iteration is used when the number of repetitions
required is ​not known​ before the loop starts.

FOR Count ← 0 TO 63 WHILE Temperature = 18


OUTPUT Count Temperature = GetTemp()
ENDFOR ENDWHILE

This is an example of ​definite ​iteration. The The ​while​loop above uses ​indefinite
for​loop will run​ 64 times​ before finishing. iteration. The number of repetitions is ​not
known​ before the loop begins.

Nested Structures
Selection structures and iteration structures can be ​nested​.

This means that one structure is ​placed within another​ and


can easily be identified by different levels of ​indentation ​in
code.

For example, the pseudocode below consists of an ​if


structure, containing further selection and iteration structures.

Whenever a new IF Colour = “RED” THEN


selection or iteration WHILE Colour = “RED”
structure begins, the Colour ← UpdateColour()
code moves to a ENDWHILE
higher level of ELSE
indentation​, making IF Colour = “GREEN” THEN
the code ​easier for WHILE Colour = “GREEN”
humans to Colour ← UpdateColour()
understand​. ENDWHILE
ELSE
Colour ← “RED”
ENDIF
ENDIF

www.pmt.education
Meaningful Identifier Names
When declaring a constant, variable or subroutine, it’s
important to give it a ​sensible ​and ​meaningful​ identifier name.
This makes it ​easier for others to understand​ what the
purpose of the named object is within the program.

If a different programmer, who was ​unfamiliar ​with your


program, were to read the code, they should be able to work
out the purpose of a constant, variable or subroutine from its
name.
Arithmetic Operations

The following operations can be applied to operands by your programming language.


Different languages notate these operations differently, so ensure that you’re familiar with
your chosen language’s approach.

Operation Description Example

Addition When two values are added, the result is 128 + 42 = 170
the ​sum ​of the two values.

Subtraction When one value is subtracted from another, 34 - 13 = 21


the result is the ​difference ​between the two
numbers.

Multiplication The ​product ​of two numbers is returned 64 * 2 = 128


when multiplied.

Real / Float When one value is divided by another, both 12 / 8 = 1.5


Division a quotient and a remainder are returned.

Integer Division Integer division returns just the ​whole 12 \ 8 = 1


number part​ of a division. Or​ 12 DIV 8 = 1

Modulo Returns the remainder of an integer 12 MOD 8 = 4


division.

Exponentiation Raising one value to the power of another. 2 ^ 6 = 64

Rounding Limiting the​ degree of accuracy​ of a 3.14159 = 3.14


number, for example, to a set number of to 3 significant figures
significant figures.

Truncation Removing the decimal part​ of a number. 3.14159 truncated = 3


Truncation always returns the whole part of
the number and never rounds up.

www.pmt.education
Relational Operations

You can make use of relational operators whenever you need to compare two values.
They are used in iterative and selection structures as well as for ​base cases​ in ​recursion​.

Operation Example

Equal to 12 = 12

Not equal to 16 <> 413


16 != 413

Less than 75 < 422

Greater than 19 > 18

Less than or equal to 6 >= 22


95 >= 95

Greater than or equal to 20 >= 126


44 >= 44

Boolean Operations

As explained earlier in this document, a Boolean data type is one whose value can ​only
ever be true or false​. There are a series of ​operations ​that can be performed on Boolean
values.

Operation Description Example

NOT The ​opposite ​of a NOT 1 = 0


Boolean value

AND The ​product ​of two 1 AND 1 = 1


Boolean values 0 AND 1 = 0

OR The ​sum ​of two Boolean 1 OR 0 = 1


values 1 OR 1 = 1

XOR True if ​strictly one​ of two 1 XOR 1 = 0


values is true 1 XOR 0 = 1

www.pmt.education
Constants and Variables

When a program needs to store data, it usually does so using one of two types of data
item: ​constants ​or ​variables​.

As their name suggests, variables can ​change their value​ during the execution of a
program, whereas a constant’s value ​cannot change​ once assigned.

Constants can be used for storing data that ​doesn’t need to


change​ such as a value for ​pi​ or the number of days in a
year. Using constants allows values to be given ​identifier
names ​which makes code ​easier for a human to understand​.

Furthermore, should a constant value be required ​multiple


times​ throughout a program, using a constant makes
changing that value ​much easier ​as it only needs to be updated ​in one place​.

Using hard-coded values Using constants

HoursWorked ← USERINPUT HourlyRate ← 14


PAY ← 14 * HoursWorked HoursWorked ← USERINPUT
OUTPUT PAY PAY ← HourlyRate * HoursWorked
OUTPUT PAY

The pseudocode examples above show two different approaches to the same problem.
One approach uses hard-coded values whereas the other uses constants.

The code which makes use of constants is ​easier to understand​ as it clearly specifies that
14​refers to an hourly rate. In the example which uses hard-coded values, it’s ​difficult to
understand ​why ​HoursWorked​is being multiplied by 14.

www.pmt.education
String-handling operations

As discussed earlier in this document, a string is a ​collection of characters​. Thanks to their


composition, strings can have ​various functions​ applied to them.

Function Description

Length Returns the ​number of characters​ in a specified string.

Position Returns the ​position of a specified character ​within a string.

Substring Given a starting position and a length, returns a ​portion of a


string​.

Concatenation Joining two or more strings together​ to form a new, longer


string.

Character to character Returning the ​character code​ which corresponds to a


code specified character.

Character code to Returning the ​character ​represented by a given character


character code.

String to integer Converting a string to an integer.

String to float Converting a string to a float.

Integer to string Converting an integer to a string.

Float to string Converting a float to a string.

Date / time to string Converting a date / time data type to a string.

String to date / time Converting a string to a date / time data type.

www.pmt.education
Random number generation

Most high level programming languages have the ability to


generate random numbers​.

A built-in function takes a ​seed value​ and uses a series of


mathematical operations​ to arrive at a number. However, a
computer can never generate a ​truly ​random number and as
such, computer-generated random numbers are said to be
pseudorandom​.

It’s important that you make yourself familiar with random number generation in your
chosen programming language.

Exception handling

When an error occurs in program code, an “​exception​” is said to be thrown. This could be
caused by using the wrong data type, attempting to divide by zero or attempting to access
a non-existent element in an array to name a few examples.

Once an exception has been thrown, the computer has to


handle the exception​ to avoid crashing. It does this by
pausing execution​ of the program and saving the current
volatile ​state of the program on the ​system stack​ before
running a section of code called a ​catch block​.

This code will ​prevent the program from crashing ​and might ​inform the user​ that an error
has occurred. Once the exception has been handled, the program uses the ​system stack
to restore its previous state before resuming execution.

Subroutines

A subroutine is a ​named block of code​ containing a ​set of


instructions​ designed to perform a ​frequently used​ operation.
Using subroutines ​reduces repetition​ of code and hence
makes code ​more compact​ and ​easier to read​.

Both ​functions ​and ​procedures ​are types of subroutine and


can be ​called by writing their name​ in a program statement.
While both functions and procedures can return a value,
functions are ​required to​ whereas ​procedures may not​.

www.pmt.education
Parameters of subroutines

Parameters are used to ​pass data​ between subroutines within programs. Specified ​within
brackets​ after a subroutine call, parameters hold ​pieces of information​ that the subroutine
requires to run.

Length ← USERINPUT
Width ← USERINPUT
OUTPUT CalculateArea(Length, Width)

SUBROUTINE CalcualteArea(x, y)
RETURN x * y
ENDSUBROUTINE

The subroutine ​CalculareArea​in the pseudocode above takes two parameters,


Length​and ​Width​ . It then returns the product of the two values.

The actual value passed by a parameter is called an ​argument​. If a rectangle with sides of
height 4 and width 6 was input into ​CalculateArea​ , the ​parameters ​Length​and ​Width
would have ​arguments ​4 and 6 respectively.

Returning values from a subroutine

A subroutine can return a value. One that ​always ​returns a value is called a ​function​, but
don’t think that procedures can’t return a value, they can (but don’t always).

Subroutines that return values can ​appear in expressions​ and be ​assigned to a variable or
parameter​.

Length ← USERINPUT
Width ← USERINPUT
Area ← CalculateArea(Length, Width)
OUTPUT Area

SUBROUTINE CalcualteArea(x, y)
RETURN x * y
ENDSUBROUTINE

For example, in the pseudocode above, the variable ​Area​is ​assigned ​to the subroutine
CalculateArea​ . The value taken by the variable will be the value returned by the
subroutine.

www.pmt.education
Local variables in subroutines

A local variable is a variable that can ​only be accessed from the subroutine within which it
is declared​. They only exist in the computer’s memory when their parent subroutine is
executing. This makes local variables a ​more memory efficient​ way of storing data than
using global variables, which are discussed below.

Global variables

In contrast to local variables, global variables can be​ accessed from any part​ of a program
and exist in memory for ​the entire duration​ of the program’s execution.

Local variables can be given the ​same​ identifier name as global variables, although this is
generally considered ​bad practice​. When the local variable’s value is changed, the global
variable’s value ​remains the same​.

www.pmt.education
AQA Computer Science A-Level
3.1.2 Procedural-oriented programming
Advanced Notes

www.pmt.education
Specification:

3.1.2.1 Structured programming:


Understand the structured approach to program design and
construction
Be able to construct and use hierarchy charts when designing programs
Be able to explain the advantages of the structured approach

www.pmt.education
The procedural programming paradigm

Programs written in the procedural programming paradigm


are formed from ​sequences of instructions ​that are executed
in the order in which they appear​. Procedures like ​functions
and ​subroutines ​form parts of the program and can be ​called
from anywhere​ within the program, by other procedures or
recursively​.

Data is stored in procedural programs by​ constants and


variables​. A data structure is said to have a ​global scope ​if it can be accessed from all
parts of the program and a ​local scope ​if it is only accessible from the structure within
which it is declared.

Most of the programs that you may have written are likely to have been procedural.

The structured approach


Using the ​structured approach ​to program design and
construction keeps programs​ easy to understand and
manage​. Four basic ​structures ​are used: assignment,
sequence, selection and iteration.

Structured programs are said to be ​designed from the top


down​, meaning that the most important elements of a
problem are ​broken down into smaller tasks​, each of which
can be solved in a block of code such as a procedure or
module which goes on to form part of the overall solution.

Advantages of the structured approach


Designing a program from the top down makes ​maintaining the program ​easier as
navigation of different elements of the overall solution is improved. If all of a program’s
code is contained within the same module, finding the specific line of code that needs
fixing can be incredibly difficult - especially in large projects.

When a program is split into modules, ​testing can be carried out on the individual modules
before they are combined to form the overall solution. Furthermore, ​development can be
split over a team ​of developers each of which is assigned a different module to work on.

www.pmt.education
Hierarchy charts
A hierarchy chart graphically represents​ the structure of a structured program​. Each
procedure is​ displayed as a rectangle​ which is connected to any other procedures that are
used within it.

Example
These procedures form part of a program that allows a user to play a game.

SUBROUTINE StartFromLevel(number)
IF number = 1 THEN
SUBROUTINE StartGame()
PlayLevelOne()
level ← INPUT
SUBROUTINE BeginNewGame() ELSEIF number = 2 THEN
IF level = 1 THEN
username ← INPUT PlayLevelTwo()
BeginNewGame()
OUTPUT “Hello” + username ELSEIF number = 3 THEN
ELSE
StartFromLevel(1) PlayLevelThree()
StartFromLevel(level)
END SUBROUTINE ELSE
END IF
OUTPUT “No such level”
END SUBROUTINE
END IF
END SUBROUTINE

The three procedures above form a program which​ could be represented by the hierarchy
chart​ below.

Each rectangle in the hierarchy chart represents a procedure in the program. The lines
between the rectangles show the ​relationships ​that exist between the different procedures.

www.pmt.education
AQA Computer Science AS-Level
3.2.1 Data structures and
abstract data types
Advanced Notes

www.pmt.education
Specification:

3.2.1.1 Data structures:


Be familiar with the concept of data structures.
3.2.1.2 Single- and multi-dimensional arrays (or equivalent):
Use arrays (or equivalent) in the design of solutions to simple problems.
3.2.1.3 Fields, records and files:
Be able to read/write from/to a text file.
Be able to read/write data from/to a binary (non-text) file.

www.pmt.education
Data structures

Data structures are used by computers as the ​containers​ within which information is
stored. Different data structures exist and some are better suited to​ different types of data
than others. When storing data, a programmer must decide which of the data structures
available is the best to use.

Arrays

An array is an​ indexed set of related elements​. An array must


be ​finite​, ​indexed​ and must only contain elements with the
same​ data type​.

Array Names = {“George”, “Sue”, “Mo”}

The elements of an array are given an ​index​, which often


starts from zero​. For example, with the array shown above,
Names(2)​would return ​“Mo”​as the first item (​“George”​ ) is
given the index ​0​.

The array shown above is a ​one-dimensional array​ which could be visualised with the
following table:

0 1 2

“George” “Sue” “Mo”

Arrays can be created in ​many dimensions​. For example, a two-dimensional array could
look like this:

Array Maze = { {Wall, Path, Wall}, {Path, Path, Wall}, {Wall, Path, Wall}}

When displayed in a ​table​, the ​Maze​array starts to make a little more sense:

0 1 2 When an individual element is referenced,


the ​x​coordinate is listed first​.
0 Wall Path Wall
For example, ​Maze(1,2)​would return
1 Path Path Wall
Path​and ​Maze(2,1)​would return ​Wall​
.
2 Wall Path Wall

www.pmt.education
Fields, records and files

Information is stored by computers as a ​series of files​. Each file is made up of ​records


which are composed of a number of ​fields​.

It’s important that you make sure you can write to and read from files in your chosen
programming language.

www.pmt.education
Definitions and Concepts for AQA Computer Science AS-level

Topic 3: Systematic Approach to Problem


Solving

3.1 Aspects of Software Development

3.1.1 Analysis

Analysis: The first stage of software development where the problem is defined and the
requirements for the system are identified.

Data Model: An abstract model organising data items and their relations to one another and
to the real-world entities they represent.

3.1.2 Design

Design: The second stage of software development where the algorithms, data structures
and user interfaces are designed. Data input, processing, output and security specifications
are taken into account along with hardware considerations.

Modularity: A software design technique based on the principle of decomposing the


functionality of a program into independent components known as modules.

3.1.3 Implementation

Implementation: The third stage of software development where the actual code and data
structures are written and developed based on the agreed design specifications to produce
prototypes.

3.1.4 Testing

Boundary Test Data: Test data typically on the edge case of the acceptable range of inputs.

Erroneous Test Data: Test data typically outside of the acceptable range of inputs that is
invalid and should trigger the system to produce an error.

Normal (Typical) Test Data: Test data within the acceptable range for the system. The
expected result should be obtained from the system.

Testing: The fourth stage of software development where the system is tested for errors and
inconsistencies with the analysis and design specifications using a variety of different input
data and scenarios.

This work by PMT Education is licensed under https://bit.ly/pmt-cc


https://bit.ly/pmt-edu-cc CC BY-NC-ND 4.0

https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc
3.1.5 Evaluation

Evaluation: The final stage of software development where the system is critically reviewed
with the user specification and judged according to the performance objectives and its
usefulness to solving the problem.

https://bit.ly/pmt-cc
https://bit.ly/pmt-edu https://bit.ly/pmt-cc
AQA Computer Science AS Level
3.4.1 Abstraction and automation
Advanced Notes

www.pmt.education
Specification:

3.4.1.1 Problem-solving:
Be able to develop solutions to simple logic problems.
Be able to check solutions to simple logic problems

3.4.1.2 Following and writing algorithms:


Understand the term algorithm.
Be able to express the solution to a simple problem as an algorithm
using pseudocode, with the standard constructs:
● sequence
● assignment
● selection
● iteration
Be able to hand-trace algorithms.
Be able to convert an algorithm from pseudocode into high level
language program code.
Be able to articulate how a program works, arguing for its correctness
and its efficiency using logical reasoning, test data and user feedback.

3.4.1.3 Abstraction:
Be familiar with the concept of abstraction as used in computations and
know that:
● representational abstraction is a representation arrived at by
removing unnecessary details
● abstraction by generalisation or categorisation is a grouping by
common characteristics to arrive at a hierarchical relationship of
the 'is a kind of' type

3.4.1.4 Information hiding:


Be familiar with the process of hiding all details of an object that do not
contribute to its essential characteristics.

www.pmt.education
3.4.1.5 Procedural abstraction:
Know that procedural abstraction represents a computational method.

3.4.1.6 Functional abstraction :


Know that for functional abstraction the particular computation method
is hidden.

3.4.1.7 Data abstraction:


Know that details of how data are actually represented are hidden,
allowing new kinds of data objects to be constructed from previously defined
types of data objects.

3.4.1.8 Problem abstraction/reduction:


Know that details are removed until the problem is represented in a way
that is possible to solve, because the problem reduces to one that has
already been solved.

3.4.1.9 Decomposition:
Know that procedural 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.

3.4.1.10 Composition:
Know how to build a composition abstraction by combining procedures
to form compound procedures.
Know how to build data abstractions by combining data objects to form
compound data, for example tree data structure.

3.4.1.11 Automation:
Understand that automation requires putting models (abstraction of real
world objects/ phenomena) into action to solve problems. This is achieved by:
● creating algorithms
● implementing the algorithms in program code (instructions)
● implementing the models in data structures
● executing the code

www.pmt.education
Problem Solving

Problem solving is the process of ​finding a solution ​to a difficult or complex issue.

In an exam, you might be given a ​series of statements​ from which you have to find the
answer to a question.

Example:​ Given the two statements

George is a student
and
All students like chocolate

which of the following conclusions could be drawn?

George lives in We can’t tell anything about where George lives


Finland
✘ from the statements, so this conclusion can’t be
made. This doesn’t mean that George doesn’t live
in Finland, we just don’t know for sure.

All chocolate is eaten This could be true, because we’re not told that
by students
✘ anyone other than students eat chocolate, but we
can’t say for sure.

George likes This must be true. We’re told that George is a


chocolate
✔ student and that all students (including George)
like chocolate.

Exam questions often contain ​more than two ​statements, but the process of forming a
reasonable conclusion is the same.

Harder example:​ Alice, Bob and Charlie are each wearing a hat, cannot see their own hat
and can see the others’ hats. They are then told that each of their hats is either green or
yellow and that they don’t all have the same colour hat. Charlie then says “​I know that my
hat is yellow​”.

What colour is Bob’s hat?

The answer is on the next page.

www.pmt.education
Bob’s hat is green.

Charlie can see​ both Alice and Bob’s hats​. For Charlie to be able to say that​ she knows
the colour of her hat, Alice and Bob​ must have the same colour ​hats. Because Charlie has
been told that ​it’s not possible for all three to have the same colour​, she can work out that
her hat is ​the colour that Alice and Bob’s hats are not​. Therefore Charlie works out the
colour of her hat is ​yellow​. This means that Bob’s hat is ​not yellow​, so must be green.

Algorithms

An algorithm is a ​sequence of steps​ that can be followed to complete a task. An algorithm


always terminates​ rather than going on forever in a loop.

Algorithms can be written in ​pseudocode​: a way of describing instructions that is


independent of any particular programming language. Pseudocode allows different
programmers, who may not all understand the same languages, to be able to
communicate algorithms to one another.

Assignment in pseudocode
Assignment is the process of ​giving a value to a variable or constant​. In pseudocode,
assignment is represented using an arrow pointing towards the variable or constant that is
being given a value.

counter ← 27
name ← “Sarah”

The pseudocode above assigns the value 27 to the variable ​counter​and the value Sarah
to the variable ​name​
.

Sequence in pseudocode
Sequence is the name given to instructions that ​follow on from one another​.

counter ← 18
counter ← counter + 1
remainingIterations ← 20 - counter

In the pseudocode above, the variable ​counter​is ​set ​to 18 and then ​incremented ​by one.
Following that, the variable ​remainingIterations​is ​set ​to twenty minus the value of
counter​ . The operations will be executed​ in the order that they appear​.

www.pmt.education
Selection in pseudocode
Selection is the process of​ choosing an action to take based on the result of a comparison
of values.

IF name = “Brian” THEN


OUTPUT “Hello Brian”
ELSE
OUTPUT “Hello user”
END IF

The pseudocode above compares the value of the variable name to the value “Brian” and
outputs different values ​depending on the result​ of the comparison.

In pseudocode, the statements ​IF​


, ​ELSE IF​
, ​ELSE​and ​END IF​can all be used.

Iteration in pseudocode
Iteration is the process of ​repeating an operation​. Iteration structures include ​FOR​and
WHILE​loops.

FOR number ← 6 to 12
OUTPUT number / 2
END FOR

WHILE number < 18


Number ← number + (number / 4)
END WHILE

The code within an iteration structure is ​indented​, allowing for


easy identification​ of different loops.

www.pmt.education
Abstraction

Abstraction is the name given to the process of ​omitting unnecessary details​ from a
problem.

When solving a problem, abstraction can be used to ​simplify the problem ​which can in turn
make finding a solution ​easier​.

There are two distinct forms of abstraction: ​representational abstraction ​and ​abstraction by
generalisation / categorisation​.

Representational abstraction Abstraction by generalisation /


categorisation

A representation of a problem arrived at by A grouping by ​common characteristics​ to


removing unnecessary details​ from the arrive at a​ hierarchical relationship ​of the
problem. “is a kind of”​ type.

The definitions of these two forms of abstraction are ​often asked for ​in exams, so it’s worth
learning them.

Information hiding
Information hiding is defined as the process of ​hiding all details of an object that do not
contribute to its essential characteristics​. For example, if you’re designing a program that
works out how many cars can fit onto a ferry, information about the manufacturer or the
colour of a car can be disregarded and just information about the size and weight of cars
retained.

Procedural abstraction
Procedural abstraction involves ​breaking down a complex model ​into a ​series of reusable
procedures​. The actual values used in a computation are abstracted away and a
computational method is achieved.

For example: To calculate the area of a rectangle, this procedure could be used:
CalcualteArea = width * height

Functional abstraction
Procedural abstraction results in a procedure. Abstracting further​ disregards the particular
method​ of a procedure and ​results in just a function​.

For example: Abstracting the procedure from the previous example leaves us with a
function: ​RectangleArea = CalculateArea()

www.pmt.education
Data abstraction
In data abstraction, ​specific details​ of how data is ​actually
represented​ are abstracted away, allowing new kinds of data
structures to be created from previously defined data
structures. Data abstraction forms the basis of​ abstract data
types​.

Problem abstraction / reduction


In problem abstraction (which is sometimes called ​reduction​),
details are removed​ from a problem ​until it is represented in a
way that is solvable​. This works because a simplified
problem is often similar to a problem that has ​already been
solved​, meaning that a solution for the problem can be found.

Decomposition
When using decomposition, a problem is ​divided into a series of smaller sub-problems​.
These smaller problems can be​ solved individually​ or​ further divided ​until all parts of the
original problem have been solved.

Composition
When dealing with a complex problem, composition can be used to ​combine procedures​ to
form a larger system. Composition is used in ​abstract data types​, where a complex
abstract data type is formed for smaller and simpler data types.

Automation
Automation is the process of ​putting abstractions of real world phenomena​ (which are
referred to as ​models​) ​into action​ to solve problems. Automation is achieved by​ creating
algorithms​ which are later ​implemented in code​, implementing ​models in data structures
and finally​ executing the code ​on the data structures.

www.pmt.education
AQA Computer Science AS Level
3.4.2 Finite state machines (FSMs)
Advanced Notes

www.pmt.education
Specification:

3.4.2.1 Finite state machines (FSMs) without output:


Be able to draw and interpret simple state transition diagrams and state
transition tables for FSMs with no output.

www.pmt.education
Finite State Machines

A finite state machine (or FSM for short) is a ​computational model​ for a machine that is
always in a fixed state​. Each finite state machine has a ​finite number of states ​and can
only ever be in one state​ at a point in time.

The state of a finite state machine will change depending on the ​current state​ and the ​input
data​. If the input data is valid, the finite state machine will terminate in an ​accepting state​.

A finite state machine’s state ​can change​ and does so according to​ transition rules​, rules
that describe what a finite state machine should do given certain criteria.

State Transition Diagrams

State transition diagrams are used by computer scientists as a ​visual representation​ of a


finite state machine. They consist of ​states ​(circles) joined by ​transitions ​(arrows) and
always have a ​start state​, indicated with a leading arrow. An ​accepting state​ is shown as a
double circle​.

For example, the state transition diagram above has ​four states​: S​0​, S​1​, S​2​ and S​3​. The
start state is S​0​ and S​3​ is an accepting state.

The​ transition functions ​are each represented by an ​arrow ​(the leading arrow merely
signifies the ​start state ​and does not represent a transition function).

The finite state machine represented by the state transition diagram will ​only accept​ input
data that starts with ​11​
. For example: ​11​
, ​110​
, ​11101​and ​11001100.

www.pmt.education
State Transition Tables

The ​transition function​ between S​0​ and S​1​ in the previous diagram could be described in
English as “​If the finite state machine is in state S​0​ and the input is 1, move to state S​1.​ ​”

The transition functions in a finite state machine can be notated more formally using a
state transition table​, with columns for current state, input and next state, like the one
below.

Current State Input Next State

S​0 1 S​1

S​0 0 S​2

S​1 1 S​3

S​1 0 S​2

Example - Parking Machine

The finite state machine shown by the state transition diagram below represents a parking
machine which requires 50p to be payed. The machine is only designed to take coins
worth 10p or more.

If the customer first pays 10p, the machine moves into the 10p state, from which the
customer can input another 10p or 20p. The 50p state is the accepting state.

www.pmt.education
Example - Parity

This finite state machine represents ​odd parity​. Only


numbers with an ​odd total of ​1​
s​ will be accepted.

The machine has​ two states,​ one start state and one
accepting state.

There are a total of ​four transition functions​, which are shown


in the ​state transition table​ on the left.

Current State Input Next State

S​0 1 S​1

S​0 0 S​0

S​1 1 S​0

S​1 0 S​1

Accepted input strings include ​1, 00000001, 00100011, 11111011​and ​01010111

Rejected input strings include ​0, 00000000, 00011011, 11111111​and ​01011010

www.pmt.education

You might also like