Edexcel D1 Revision Sheets
Edexcel D1 Revision Sheets
Algorithms
3kg
2kg
Sorting Algorithms
There are many sorting algorithms, so you must check carefully to see which, if any, you need to memorise for the examination.
Questions often ask about the relative efficiency of sorting algorithms by comparing the number of comparisons (c) and swaps that
are made to sort the same list of numbers, as seen in this example:
Bubble Sort
List 1st 2nd 3rd
pass pass pass First pass: the first number in the list is compared with the second and whichever is
6 1 1 1 smaller assumes the first position. The second number is then compared with the third
1 3 3 3 and the smaller is placed in the second position, and so on. At the end of the first pass,
3 6 5 5 the largest number will be at the bottom. For the list of five numbers on the right, this
7 5 6 6 involves 4 comparisons and 3 swaps.
5 7 7 7 Second pass: repeat first pass but exclude the last number (on the third pass the last two
c 4 3 2 numbers are excluded and so on).
s 3 1 0 The list is repeatedly processed in this way until no swaps take place in a pass.
total number of comparisons: 9 For a list of 5 numbers, the list will definitely be sorted after the 4th pass (why?), so this is
the maximum number of passes. The maximum number of comparisons is 4+3+2+1=10
total number of swaps: 4 and the maximum number of swaps is 10. You should be able to generalise this to a list
of n numbers.
In this case the quick sort takes fewer comparisons and swaps than the bubble sort, though it does take one more pass to achieve
the sort. It is worth noting that the relative efficiency of the different types of algorithm will vary depending on how “mixed up”
the list is.
Alan Biology
Donna Music
Example
The table shows the number of vertices of degree Order of vertex 1 2 3 4
1, 2, 3 and 4 for three different graphs. Graph 1 3 0 1 0
Draw an example of each of these graphs. Graph 2 0 0 4 1
Graph 3 0 2 2 1
solution
graph 1 graph 2 graph 3
Find the number of edges and the sum of the degrees of all the vertices of the graphs. What do you notice?
Graph 1: number of edges 3 sum of degrees of vertices 1+1+1+3 = 6
Graph 2: number of edges 8 sum of degrees of vertices 3+3+3+3+4=16
Graph 3: number of edges 7 sum of degrees of vertices 2+2+3+3+4 = 14
The sum of the degrees of the vertices is always twice the number of edges.
Also note that there are always an even number of odd vertices.
Dijkstra’s Algorithm for the shortest path 1. Label the start vertex with permanent label 0 and order label 1.
1 0 2. Assign temporary labels to all the vertices that can be reached
D directly from the start.
A 3 3. Select the vertex with the smallest temporary label and make its
4 3 6 F label permanent. Add the correct order label.
1. Step 1 4. Put temporary labels on each vertex that can be reached directly
4
C 3 from the vertex you have just made permanent. The temporary
2 2
E label must be equal to the sum of the permanent label and the
B
direct distance from it. If there is an existing temporary label at a
vertex, it should be replaced only if the new sum is smaller.
5. Repeat steps 3 and 4 until the finishing vertex has a permanent
label.
1 0 6. To find the shortest paths(s), trace back from the end vertex to the
D start vertex. Write the route forwards and state the length.
A 3
4 3 6 F 5 7
2. Steps 2 4 1 0
C 3 7
and 3 2 2 D
A 3
B E 4 10 9
2 4 4 3 6 F
4 5. Steps 4 and 5 4
C 3
2 2
1 0 B E
D 3 4
A 2 4 4 6
3 10 4
4 4 6
3 6 F
4 5 7
3. Steps 4 2
C
2 3 1 0 7
and 5 3 4 E D 6 9
B A
4 4 3 10 9
2 4 3
4 6 F
6. Steps 4 4
C 3
1 0 and 5 2 2
7 B 3 4 E
D 4 6
A 3 2 4 4
4 10 9
3 6
6 F 4
4. Steps 4 4
C 3
and 5 2 2
B 3 4 E
4 6 7. Step 6 Solution:
2 4 4 Shortest path ACEF
6
4 Length 9
Apply the Chinese Postman Algorithm to • That you need to identify ALL the odd vertices in the
obtain the closed trail of minimum weight. route inspection problem.
12 10
Solution: 6
9
(a) Odd vertices are A, C, D and E. A 6 18 F
Consider all the possible pairings of odd vertices: C
AC = 6 and DE = 14 total = 20
11 8 12
AD = 11 and CE = 6 total = 17
AE = 12 and CD = 8 total = 20
D
The pairing of least weight is AD and CE = 17.
The sum of the weights in the network is 124.
Repeating AD and CE gives a total weight = 124 + 17 = 141.
A suitable route is A – B – E – F – D – A – C – B – F – C – E – C – D – A.
Terminology Example:
An activity is a task which needs to be done and takes an The table shows the activities involved in creating a small patio
amount of time/resources to complete. in a garden.
Precedence tables show the activities that need to be done
together with their duration and their immediate predecessors. Activity Task Time Preceding
Precedence networks show the sequence of the activities. The Name (hrs) Activities
network must have one start node and one end node.
An event is the start/finish of one or more activities. A Clear Garden 4
Dummy activities are used to keep the correct logic and to B Measure area 1
ensure each activity is uniquely defined by (i, j) where i is its C Design Patio 2 B
starting event and j is the finishing event.
D Purchase fencing 1 B
E Buy pots and plants 3 A,C
This is correct F Plant all pots 1 E
This is incorrect G Purchase paving 1 C
H Construct Garden 6 A, D,G
It can be a good idea to do an initial sketch as it’s often possible
to make your diagram clearer by repositioning activities to avoid The network for this precedence table
them crossing over one another.
Forward pass establishes the earliest times that events can E(3)
happen. A(4)
F(1)
Backward pass establishes the latest time that an event can
happen.
Critical activites are those whose timing is critical if the project G(1)
is to be completed in the minimum time. The critical activities C(2)
B(1)
will form a path through the network H(6)
Float is the amount of time by which an activity can be delayed
D(1)
or extended.
Independent float does not affect other activities.
Interfering float is shared between two or more activities.
A(4)
F(1)
0 0 10 10
G(1)
C(2)
B(1) 3 3
H(6)
Float
0 1 2 3 4 5 6 7 8 9 10 If only three people are available for the first three hours,
A but a fourth friend can then come and help for an hour, we
B could move activity D within its float time to make this
C possible.
D
E This would make the cascade chart look like this
F
G
H
4
3 The resource histogram would now look like this
2 2
1
0 1 2 3 4 5 6 7 8 9 10
Minimisation problems are solved in exactly the same way. Just remember that this time you are looking for the vertex
which makes the objective function the lowest.
Integer Programming
If the solution to the problem has to have integer values then points with integer value coordinates, close to the optimal point
can be checked. This is likely to reveal the optimal solution but it is not guaranteed to. For example suppose the Objective
Function is 2 x + 3 y and that this should be maximised. The optimal point may be (30.6, 40. 8) but do not assume that
(30.40) will give the best solution; you must look at all the points with integer coordinates that are nearby: (31, 40), (30, 41),
(30, 40) and (31, 41).
However (31, 41) and (31, 40) are not in the feasible region. You can check this by substituting in the values into the
constraints. Of the two points nearby which are in the feasible region, namely (30, 41) and (30, 40), it can be seen that
(30, 41) provides the best profit.