Sunteți pe pagina 1din 102

MATHEMATICS

eBook
included

PEARSON EDEXCEL INTERNATIONAL A LEVEL

DECISION
MATHEMATICS 1
STUDENT BOOK
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

PEARSON EDEXCEL INTERNATIONAL A LEVEL

DECISION MATHEMATICS 1
Student Book

Series Editors: Joe Skrakowski and Harry Smith


Authors: Martin Crozier, Susie Jameson, Keith Pledger, Peter Sherran, Joe Skrakowski,
Harry Smith
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Published by Pearson Education Limited, 80 Strand, London, WC2R 0RL. Endorsement Statement
In order to ensure that this resource offers high-quality support for the associated
www.pearsonglobalschools.com Pearson qualification, it has been through a review process by the awarding body.
This process confirms that this resource fully covers the teaching and learning
Copies of official specifications for all Pearson qualifications may be found on the content of the specification or part of a specification at which it is aimed. It also
website: https://qualifications.pearson.com confirms that it demonstrates an appropriate balance between the development
of subject skills, knowledge and understanding, in addition to preparation for
Text © Pearson Education Limited 2018 assessment.
Edited by Linnet Bruce and Eric Pradel
Typeset by Tech-Set Ltd, Gateshead, UK Endorsement does not cover any guidance on assessment activities or processes
Original illustrations © Pearson Education Limited 2018 (e.g. practice questions or advice on how to answer assessment questions)
Illustrated by © Tech-Set Ltd, Gateshead, UK included in the resource, nor does it prescribe any particular approach to the
Cover design by © Pearson Education Limited teaching or delivery of a related course.

The rights of Martin Crozier, Susie Jameson, Keith Pledger, Peter Sherran, While the publishers have made every attempt to ensure that advice on the
Joe Skrakowski and Harry Smith to be identified as the authors of this work have qualification and its assessment is accurate, the official specification and
been asserted by them in accordance with the Copyright, Designs and Patents associated assessment guidance materials are the only authoritative source of
Act 1988. information and should always be referred to for definitive guidance.

First published 2018 Pearson examiners have not contributed to any sections in this resource relevant to
examination papers for which they have responsibility.
21 20 19 18
10 9 8 7 6 5 4 3 2 1 Examiners will not use endorsed resources as a source of material for any
assessment set by Pearson. Endorsement of a resource does not mean that the
British Library Cataloguing in Publication Data resource is required to achieve this Pearson qualification, nor does it mean that it
A catalogue record for this book is available from the British Library is the only suitable material available to support the qualification, and any resource
lists produced by the awarding body shall include this and other appropriate
ISBN 978 1 292244 56 3 resources.

Copyright notice
All rights reserved. No part of this may be reproduced in any form or by any means
(including photocopying or storing it in any medium by electronic means and
whether or not transiently or incidentally to some other use of this publication)
without the written permission of the copyright owner, except in accordance with
the provisions of the Copyright, Designs and Patents Act 1988 or under the terms
of a licence issued by the Copyright Licensing Agency, Barnard's Inn, 86 Fetter
Lane, London, EC4A 1EN (www.cla.co.uk). Applications for the copyright owner’s
written permission should be addressed to the publisher.

Printed in Slovakia by Neografia

Picture Credits
The authors and publisher would like to thank the following individuals and
organisations for permission to reproduce photographs:
Alamy: ZUMA Press, Inc 1, Iain Masterton 29, Andriy Popov 52, Roy LANGSTAFF
106, Nataliya Hora 132, wu kailiang 170; Getty Images: iStock Unreleased 32;
Science Photo Library: Peter Menzel 89

Cover image: Front: Getty Images: Pete Ryan


Inside front cover: Shutterstock.com: Dmitry Lobanov

All other images © Pearson Education Limited 2018


All artwork © Pearson Education Limited 2018
CONTENTS iii
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

COURSE STRUCTURE iv
ABOUT THIS BOOK  vi
QUALIFICATION AND ASSESSMENT OVERVIEW viii
EXTRA ONLINE CONTENT x
1 ALGORITHMS 1
2 GRAPHS AND NETWORKS 29
3 ALGORITHMS ON GRAPHS 49
REVIEW EXERCISE 1 76
4 ROUTE INSPECTION 81
5 THE TRAVELLING SALESMAN PROBLEM 95
6 CRITICAL PATH ANALYSIS 121
7 LINEAR PROGRAMMING 154
REVIEW EXERCISE 2 187
EXAM PRACTICE 199
GLOSSARY 205
ANSWERS 208
INDEX 255
iv COURSE STRUCTURE
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

CHAPTER 1 ALGORITHMS 1 CHAPTER 4 ROUTE


1.1 USING AND UNDERSTANDING INSPECTION 81
ALGORITHMS 2 4.1 EULERIAN GRAPHS 82
1.2 FLOW CHARTS 5 4.2 USING THE ROUTE INSPECTION
1.3 BUBBLE SORT 10 ALGORITHM 85
1.4 QUICK SORT 13 CHAPTER REVIEW 4 91
1.5 BIN-PACKING ALGORITHMS 16
1.6 BINARY SEARCH 22
CHAPTER REVIEW 1 24
CHAPTER 5 THE TRAVELLING
SALESMAN PROBLEM 95
5.1 THE CLASSICAL AND PRACTICAL
CHAPTER 2 GRAPHS AND TRAVELLING SALESMAN
NETWORKS 29 PROBLEMS 96
2.1 MODELLING WITH GRAPHS 30 5.2 USING A MINIMUM SPANNING
2.2 GRAPH THEORY 34 TREE METHOD TO FIND AN
2.3 SPECIAL TYPES OF GRAPH 38 UPPER BOUND 100
2.4 REPRESENTING GRAPHS AND 5.3 USING A MINIMUM SPANNING
NETWORKS USING MATRICES 42 TREE METHOD TO FIND A
CHAPTER REVIEW 2 44 LOWER BOUND 107
5.4 USING THE NEAREST NEIGHBOUR
CHAPTER 3 ALGORITHMS ON ALGORITHM TO FIND AN UPPER
BOUND 111
GRAPHS 49
CHAPTER REVIEW 5 116
3.1 KRUSKAL’S ALGORITHM 50
3.2 PRIM’S ALGORITHM 54
3.3 APPLYING PRIM’S ALGORITHM
TO A DISTANCE MATRIX 57
3.4 THE NEAREST NEIGHBOUR
ALGORITHM60
3.5 USING DIJKSTRA’S ALGORITHM
TO FIND THE SHORTEST PATH 64
CHAPTER REVIEW 3 71

REVIEW EXERCISE 1 76
COURSE STRUCTURE v
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

CHAPTER 6 CRITICAL PATH REVIEW EXERCISE 2 187


ANALYSIS 121
6.1 MODELLING A PROJECT 122 EXAM PRACTICE 199
6.2 DUMMY ACTIVITIES 126
6.3 EARLY AND LATE EVENT TIMES 131
6.4 THE FLOAT OF AN ACTIVITY 133 GLOSSARY 205
6.5 CRITICAL ACTIVITIES 136
6.6 GANTT CHARTS 139 ANSWERS 208
6.7 SCHEDULING DIAGRAMS 143
CHAPTER REVIEW 6 148
INDEX 255
CHAPTER 7
LINEAR PROGRAMMING 154
7.1 LINEAR PROGRAMMING
PROBLEMS 155
7.2 GRAPHICAL METHODS 161
7.3 LOCATING THE OPTIMAL POINT 165
7.4 SOLUTIONS WITH INTEGER
VALUES 178
CHAPTER REVIEW 7 183
vi ABOUT THIS BOOK
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

ABOUT THIS BOOK


The following three themes have been fully integrated throughout the Pearson Edexcel International
Advanced Level in Mathematics series, so they can be applied alongside your learning.

1. Mathematical argument, language and proof


• Rigorous and consistent approach throughout
• Notation boxes explain key mathematical language and symbols

2. Mathematical problem-solving The Mathematical Problem-Solving Cycle

• Hundreds of problem-solving questions, fully integrated specify the problem

into the main exercises


• Problem-solving boxes provide tips and strategies interpret results
collect information
• Challenge questions provide extra stretch
process and
3. Transferable skills represent information

• Transferable skills are embedded throughout this book, in the exercises and in some examples
• These skills are signposted to show students which skills they are using and developing

Finding your way around the book

Each chapter is mapped to the


specification content for easy
reference

Each chapter starts with


a list of Learning objectives

The Prior knowledge


check helps make sure
you are ready to start the
chapter The real world applications of the
mathematics you are about to
learn are highlighted at the start
of the chapter.

Glossary terms will


be identified by bold
blue text on their first
appearance.
ABOUT THIS BOOK vii
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Transferable skills are


signposted where
they naturally occur
in the exercises and
examples

Challenge boxes give


you a chance to tackle
some more difficult
questions

Step-by-step worked
examples focus on the
key types of questions
you’ll need to tackle

Problem-solving boxes provide hints, Each section begins Exercise questions


tips and strategies, and Watch out with explanation and are carefully graded
Exam-style questions boxes highlight areas where students key learning points so they increase in
often lose marks in their exams difficulty and gradually
are flagged with E
Exercises are packed bring you up to exam
Problem-solving with exam-style standard
questions are flagged Each chapter ends with a Chapter review questions to ensure you
and a Summary of key points are ready for the exams
with P

After every few chapters, a Review exercise


helps you consolidate your learning with
lots of exam-style questions

A full practice paper at the back of


the book helps you prepare for the
real thing
viii QUALIFICATION AND ASSESSMENT OVERVIEW
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

QUALIFICATION AND
ASSESSMENT OVERVIEW
Qualification and content overview
Decision Mathematics 1 (D1) is an optional unit in the following qualifications:
International Advanced Subsidiary in Mathematics
International Advanced Subsidiary in Further Mathematics
International Advanced Level in Mathematics
International Advanced Level in Further Mathematics

Assessment overview
The following table gives an overview of the assessment for this unit.
We recommend that you study this information closely to help ensure that you are fully prepared for
this course and know exactly what to expect in the assessment.

Unit Percentage Mark Time Availability


33 ​_​  3 ​​ % of IAS
1
D1: Decision Mathematics 1 75 1 hour 30 mins January and June
16 ​_​  3 ​​ % of IAL
2
Paper code WDM11/01 First assessment June 2019

IAS: International Advanced Subsidiary, IAL: International Advanced A Level.

Assessment objectives and weightings Minimum


weighting in
IAS and IAL
Recall, select and use their knowledge of mathematical facts, concepts and techniques in a
AO1 30%
variety of contexts.
Construct rigorous mathematical arguments and proofs through use of precise statements,
logical deduction and inference and by the manipulation of mathematical expressions,
AO2 30%
including the construction of extended arguments for handling substantial problems
presented in unstructured form.
Recall, select and use their knowledge of standard mathematical models to represent
situations in the real world; recognise and understand given representations involving
AO3 10%
standard models; present and interpret results from such models in terms of the original
situation, including discussion of the assumptions made and refinement of such models.
Comprehend translations of common realistic contexts into mathematics; use the results of
AO4 calculations to make predictions, or comment on the context; and, where appropriate, read 5%
critically and comprehend longer mathematical arguments or examples of applications.
Use contemporary calculator technology and other permitted resources (such as formulae
AO5 booklets or statistical tables) accurately and efficiently; understand when not to use such 5%
technology, and its limitations. Give answers to appropriate accuracy.
QUALIFICATION AND ASSESSMENT OVERVIEW ix
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Relationship of assessment objectives to units

Assessment objective
D1 AO1 AO2 AO3 AO4 AO5
Marks out of 75 20–25 20–25 15–20 5–10 5–10
26​_​  3 ​​–33​_​  3 ​​ 26​_​  3 ​​–33​_​  3 ​​ 20–26​_​  3 ​​ 6​_​  3 ​​–13​_​  3 ​​ 6​_​  3 ​​–13​_​  3 ​​
2 1 2 1 2 2 1 2 1
%

Calculators
Students may use a calculator in assessments for these qualifications. Centres are responsible for
making sure that calculators used by their students meet the requirements given in the table below.
Students are expected to have available a calculator with at least the following keys: +, –, ×, ÷, π, x2,
__ __ 1
​​ x ​​
√    , ​​    ​​, xy, ln x, ex, x!, sine, cosine and tangent and their inverses in degrees and decimals of a degree,
x
and in radians; memory.

Prohibitions
Calculators with any of the following facilities are prohibited in all examinations:
• databanks
• retrieval of text or formulae
• built-in symbolic algebra manipulations
• symbolic differentiation and/or integration
• language translators
• communication with other machines or the internet
x EXTRA ONLINE CONTENT
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Extra online content


Whenever you see an Online box, it means that there is extra online content available to support you.

SolutionBank
SolutionBank provides a full worked solution for questions in the book.
Download all the solutions as a PDF or quickly find the solution you need online.

Use of technology y

Explore topics in more detail, visualise Online


Find the point of intersection
problems and consolidate your understanding. graphically using technology.
Use pre-made GeoGebra activities or Casio
resources for a graphic calculator.

GeoGebra-powered interactives Graphic calculator interactives

Interact with the maths


you are learning using
GeoGebra's easy-to-use
tools

Interact with the mathematics you are learning Explore the mathematics you are learning and
using GeoGebra's easy-to-use tools gain confidence in using a graphic calculator

Calculator tutorials
Our helpful video tutorials will
guide you through how to use
your calculator in the exams.
They cover both Casio's scientific
and colour graphic calculators.

Online
Work out each coefficient quickly using Step-by-step guide with audio instructions
the nCr and power functions on your calculator. on exactly which buttons to press and what
should appear on your calculator's screen
ALGORITHMS CHAPTER 1 1

1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

1.1
1.2

Learning objectives
After completing this chapter you should be able to:
● Use and understand an algorithm given in words  → pages 2–5
● Understand how flow charts can be used
to describe algorithms  → pages 5–10

● Carry out a bubble sort → pages 10–13

● Carry out a quick sort  → pages 13–16

● Carry out the three bin-packing algorithms and


understand their strengths and weaknesses  → pages 16–22

● Determine the order of an algorithm  → pages 22–24

Prior knowledge check

1 Here is a function machine.


Input ×4 +3 Output

Find:
a the output when the input is 11
b the input when the output is 99. Efficient sorting algorithms such as
______ the quick sort allow software that
2 Given that x1 = 5, use the formula xn + 1 = ​​√x  n + 4 ​​  governs self-drive cars to prioritise
to find x2, x3 and x4, giving your answers to 3 s.f. input information and react quickly
 ← International GCSE Mathematics and safely. 
2 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

1.1 Using and understanding algorithms


■ An algorithm is a finite sequence of step-by-step instructions carried out to solve a problem.
Algorithms can be given in words or in flow charts.
You need to be able to understand and use an algorithm given in words.
You have been using algorithms since you started school. Some examples of mathematical
algorithms that you will be familiar with are:
● how to add several two-digit numbers
● how to multiply two two-digit numbers

● how to add, subtract, multiply or divide fractions.

It can be quite challenging to write a sequence of instructions for someone else to


follow accurately.
Here are some more examples:

At the end of the street turn right and Affix base (B) to leg (A) Dice two large onions.
go straight over the crossroads, take the using screw (F   ) and ... Slice 100 g mushrooms.
third left after the school, then ... Grate 100 g cheese.

Example 1 SKILLS ANALYSIS

A ‘happy’ number is defined by the algorithm:


• write down any integer
• square its digits and find the sum of the squares
• repeat until either the answer is 1 (in which case the number is ‘happy’) or until you get trapped
in a cycle (in which case the number is ‘unhappy’)
Show that:
a 70 is happy b 4 is unhappy
Watch
out You will need to be able to
understand, describe and apply specific
algorithms in your exam. You do not need to
a 72 + 02 = 49 b 42 = 16 learn any of the algorithms in this section.
42 + 92 = 97 12 + 62 = 37
92 + 72 = 130 32 + 72 = 58
12 + 32 + 02 = 10 52 + 82 = 89
12 + 02 = 1 82 + 92 = 145
so 70 is happy 12 + 42 + 52 = 42
42 + 22 = 20
22 + 02 = 4 As soon as the sum of the squares matches a
42 = 16 previous result, all of the steps in-between will be
so 4 is unhappy repeated, creating a cycle.
ALGORITHMS CHAPTER 1 3
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 2 SKILLS INTERPRETATION

a Apply this algorithm.

1 Let n = 1, A = 1, B = 1.
2 Print A and B.
3 Let C = A + B.
These are not equations.
4 Print C.
They are instructions that mean:
5 Let n = n + 1, A = B, B = C. ● replace n by n + 1 (add 1 to n)
● A takes B’s current value
6 If n < 5, go to step 3.
● B takes C’s current value
7 If n = 5, stop.

b Describe the numbers that are generated by this algorithm.

A trace table is used to record the values of each


a Use a trace table.
variable as the algorithm is run.
Step n A B C Print
1 1 1 1
2 1, 1
3 2
4 2
You may be asked to complete a printed trace
5 2 1 2
table in your exam. Just obey each instruction,
6 Go to step 3 in order.
3 3
4 3
5 3 2 3
6 Go to step 3
3 5
4 5
5 4 3 5
6 Go to step 3
3 8
4 8
5 5 5 8
6 Continue to step 7
7 Stop

b This algorithm produces the first few


numbers in the Fibonnacci sequence. You may be asked what the algorithm does.
4 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 3 SKILLS INTERPRETATION

This algorithm multiplies the two numbers A and B.

1 Make a table with two columns.


Write A in the top row of the left-hand column and B in the top row of the right-hand column.
In the next row, write the values for A and B.
2 In successive rows, write: This famous algorithm is sometimes
• in the left-hand column, the number that called ‘the Russian peasant’s algorithm’
is half of A, ignoring remainders or ‘the Egyptian multiplication algorithm’.
• in the right-hand column, the number that
is double B
3 Repeat step 2 until you reach the row which has a 1 in the left-hand column.
4 Delete all rows where the number in the left-hand column is even.
5 Find the sum of the non-deleted numbers in the right-hand column.
This is the product AB.

Apply this algorithm when:


a A = 29 and B = 34 b A = 66 and B = 56

a A B
In each row, the number in the left-hand column
29 34 is halved and the number in the right-hand
14 68 column is doubled.

7 136
Step 4 means that rows where the number in the
3 272 left-hand column is even must be deleted before
1 544 summing the right-hand column.
Total 986

So 29 × 34 = 986

b A B
66 56
33 112
16 224
8 448 Each deleted row has an even number in its left-
hand column.
4 896
2 1792
1 3584
Total 3696

So 66 × 56 = 3696
ALGORITHMS CHAPTER 1 5
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 1A SKILLS INTERPRETATION

1 Use the algorithm in Example 3 to evaluate:


a 244 × 125 b 125 × 244 c 256 × 123

2 The box below describes an algorithm.


a c
1 Write the input numbers in the form __
​​   ​​ and __
​​    ​​ . 3 Let f = bc.
b d
e
2 Let e = ad. 4 Print ​​ _ ​​    .
f

a Apply this algorithm with the input numbers 2 ​​ _4 ​​ and 1 ​​ _3 ​​. 


1 1

b What does this algorithm do?

3 The box below describes an algorithm.

1 Let A = 1, n = 1. 3 Let A = A + 2n + 1. 5 If n < 10, go to 2.


2 Print A. 4 Let n = n + 1. 6 Stop.

a Apply the algorithm.


b Describe the numbers produced by the algorithm.

P 4 The box below describes an algorithm.

1 Input A, r. 5 Let r = s. Hint


This algorithm requires
A you to use the modulus
2 Let C = __
​​  r ​​ to 3 d.p. 6 Go to 2. function. If x ≠ y, |x − y|
is the positive difference
3 If |r − C  | < 10−2 go to 7. 7 Print r.
between x and y.
4 Let s = _​​  2 ​​  (r + C  ) to 3 d.p.
1
8 Stop. For example: |3.2 − 7| = 3.8.

a Use a trace table to apply the algorithm above when:


i  A = 253 and r = 12   ii  A = 79 and r = 10   iii  A = 4275 and r = 50
b What does the algorithm produce?

1.2 Flow charts


You need to be able to apply an algorithm given as a flow chart.
■ In a flow chart, the shape of each box tells you about its function.

Start/End Instruction Decision

The boxes in a flow chart are linked by arrowed lines. As with an algorithm written in words,
you need to follow each step in order.
6 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 4 SKILLS ANALYSIS

The flow chart below describes an algorithm.


Box 1 Start

Box 2 Let n = 0

n is acting as a counter. It ensures that the


Box 3 Let n = n + 1 algorithm stops after this loop has been
completed 10 times.

Box 4 Let E = 2n

Box 5 Print E

Is No
Box 6 n > 10? A decision box will contain a question to
which the answer is either ‘yes’ or ‘no’.
Yes

Box 7 Stop

a Apply this algorithm using a trace table.


b Alter box 4 to read ‘Let E = 3n’ and apply the algorithm again.
How does this alter the output of the algorithm?

a n E Box 6 b n E Box 6
0 0
1 2 No 1 3 No
2 4 No 2 6 No
3 6 No 3 9 No
4 8 No 4 12 No
In a trace table each
5 10 No 5 15 No
step must be made
6 12 No 6 18 No
clear.
7 14 No 7 21 No
8 16 No 8 24 No
9 18 No 9 27 No
10 20 Yes 10 30 Yes
Output is 2, 4, 6, 8, 10, 12, Output is 3, 6, 9, 12, 15, 18,
14, 16, 18, 20 21, 24, 27, 30
This gives the first ten multiples of
3 rather than the first ten multiples
of 2.
ALGORITHMS CHAPTER 1 7
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 5 SKILLS INTERPRETATION

This flow chart can be used to find the roots of an equation of the form ax2 + bx + c = 0.
Start

Input a, b, c

Let d = b2 – 4ac

Is Yes
Print ‘no real roots’
d < 0? You should recognise d
No as the discriminant of
Is Yes the equation.
Let x = – b Print ‘equal roots are’ x
d = 0? 2a ← Pure 1 Section 2.5
No

Let x1 = – b + d
2a

Let x2 = – b – d
2a

Print ‘roots are’ x1 ‘and’ x2

Stop

Demonstrate this algorithm for these equations:


a 6x2 − 5x − 11 = 0 b x2 − 6x + 9 = 0 c 4x2 + 3x + 8 = 0

a a b c d d < 0? d = 0? x1 x2
__
11
6 −5 −11 289 No No ​​  6 ​​  −1
roots are __
​​  11
6  ​​ and −1

b a b c d d < 0? d = 0? x
1 −6 9 0 No Yes 3
equal roots are 3
c a b c d d < 0?
4 3 8 −119 Yes
no real roots
8 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 6 SKILLS INTERPRETATION

Apply the algorithm shown by the flow chart Start


on the right to the data:
u1 = 10, u2 = 15, u3 = 9, u4 = 7, u5 = 11.
Box 1 Let n = 1 and A = u1
What does the algorithm do?
Box 2 n=n+1
n A T T < A? n < 5?
Box 1 1 10
Box 3 Let T = un
Box 2 2
Box 3 15
No Is
Box 4 No Box 4
T < A?
Box 6 Yes
Yes
Box 2 3
Box 3 9 Box 5 Let A = T
Box 4 Yes
Box 5 9 Is Yes
Box 6
Box 6 Yes n < 5?

Box 2 4 No
Box 3 7 Box 7 Print ‘Output is’ A
Box 4 Yes
Box 5 7
Stop
Box 6 Yes
Box 2 5
Box 3 11
This is quite complicated because it has questions
Box 4 No
and a list of data. Tackle one step at a time.
Box 6 No
Box 7 Output is 7
The algorithm selects the smallest number The box numbers have been included to help
from a list. you to follow the algorithm. You do not need to
include them in your exam.

Exercise 1B SKILLS PROBLEM-SOLVING

1 Apply the flow chart in Example 5 to the following equations.


a 4x2 − 12x + 9 = 0 b −6x2 + 13x + 5 = 0 c 3x2 − 8x + 11 = 0

2 a Apply the flow chart in Example 6 to the following sets of data.


i u1 = 28, u2 = 26, u3 = 23, u4 = 25, u5 = 21
ii u1 = 11, u2 = 8, u3 = 9, u4 = 8, u5 = 5
Is
b If box 4 is altered to T > A? , how will this affect the output?

c Which box would need to be altered if the algorithm was to be applied to a list of 8 numbers?
ALGORITHMS CHAPTER 1 9
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

3 The flow chart describes an algorithm that  Start


can be used to find the roots of the equation
2x3 + x2 − 15 = 0.
Input a
a Use a = 2 to find a root of the equation.
b Use a = 20 to find a root of the equation.
3
Comment on your answer. Let b = 15 – a2 to 4 d.p.
2

Is Yes
| a – b | < 0.001? Print b Stop

No
Let a = b

E/P 4 The flow chart on the right  Start


describes how to apply Euclid’s
algorithm to two non-zero integers,
a and b. Input a, b, where a > b

a Apply Euclid’s algorithm to:


i 507 and 52  (2 marks) Let P = integer part of a ÷ b

ii 884 and 85  (2 marks)


iii 4845 and 3795  (2 marks) Let q = Pb

b Explain what Euclid’s algorithm


does.  (2 marks) Let r = a – q

Is Yes
r = 0? Print b Stop

No
Let a = b, b = r

E/P 5 The flow chart describes an algorithm. 


Start
a Copy and complete this table, using the flow
chart with A = 18 and B = 7.
Input A and B
A B A < B ? Output
Yes
Is A < B ? Print A

(4 marks) No
b Explain what is achieved by this flow chart. (2 marks) Stop
A=A–B
c Given that A = kB for some positive integer
k, write down the output of the flow chart. (1 mark)
10 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

1.3 Bubble sort


A common data processing task is to sort an unordered list (a list which is not in order)
into alphabetical or numerical order.
Lists can be put into ascending (increasing) or descending (decreasing) order.
■ Unordered lists can be sorted using a bubble sort or a quick sort.
■ In a bubble sort, we work through the list by comparing pairs of adjacent items
(items that are next to each other) in the list.
• If the items are in the correct order, leave them
• If the items are not in the correct order, swap them
Once we have done this to all of the items in the list, we have completed the first pass.
If sorting the list into ascending order, the first pass will place the
largest item in its correct position in the list.
If sorting the list into descending order, the first pass will place the
smallest item in its correct position in the list.
We then repeat this until no swaps are made in a pass. If no swaps are made
then the list is in order. You will need to write that no swaps have been made.
As the bubble sort develops, it is helpful to consider the original list as being divided into a
working list, where comparisons are made, and a sorted list containing the items that are
in their final positions. To start with, all items are in the working list.

This is the bubble sort algorithm:

1 Start at the beginning of the working list and Notation


Each time you get to the
move from left to right, comparing adjacent items. end of the working list you complete one
pass of the algorithm. The length of the
a If they are in order, leave them.
working list reduces by 1 with each pass.
b If they are not in order, swap them.
2 When you get to the end of the working list, the
last item will be in its final position. This item is
then no longer in the working list.
3 If you have made some swaps in the last pass,
repeat step 1. Notation
The elements in the list
4 When a pass is completed without any swaps, ‘bubble’ to the end of the list in the same
every item is in its final position and the list is way that bubbles in a fizzy drink rise to
in order. the top. This is how the algorithm got
its name.

You need to learn the bubble sort algorithm.


ALGORITHMS CHAPTER 1 11
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 7 SKILLS ANALYSIS

Use a bubble sort algorithm to arrange the list below into ascending order.
24  18  37  11  15  30
Hint
In your exam you may be asked to show
24 18 37 11 15 30 1st comparison: swap
each comparison for one pass, but generally
18 24 37 11 15 30 2nd comparison: leave
you will only be required to give the state of
18 24 37 11 15 30 3rd comparison: swap the list after each pass.
18 24 11 37 15 30 4th comparison: swap
18 24 11 15 37 30 5th comparison: swap 37 is already in its final position. It is now not
18 24 11 15 30 37 End of first pass in the working list. We now return to the start
After the second pass the list becomes of the working list for the second pass.
18 11 15 24 30 37
After the third pass, the last three items are
After the third pass the list is
guaranteed to be in their final positions.
11 15 18 24 30 37 In this example, the list is fully ordered
After the fourth pass the list is but the algorithm requires another pass to
11 15 18 24 30 37 be made.
No swaps were made in the fourth pass,
so the list is in order.

Example 8 SKILLS REASONING/ARGUMENTATION

A list of n letters is to be sorted into alphabetical order, starting at the left-hand end of the list.
a Describe how to carry out the first pass of a bubble sort on the letters in the list.
b Carry out the first pass of a bubble sort to arrange the letters in the word
ALGORITHM into alphabetical order, showing every step of the working.
c Show the order of the letters at the end of the second pass.

a Starting at the beginning of the list, compare the first two letters. If they
are in alphabetical order, leave them in position, otherwise swap them.
Continue through the list, to the end, comparing every pair of letters in
the same way.
b A L G O R I T H M 1st comparison: leave
A L G O R I T H M 2nd comparison: swap
A G L O R I T H M 3rd comparison: leave
A G L O R I T H M 4th comparison: leave
A G L O R I T H M 5th comparison: swap
A G L O I R T H M 6th comparison: leave
A G L O I R T H M 7th comparison: swap
A G L O I R H T M 8th comparison: swap
A G L O I R H M T
At the end of the first pass, the last letter is
c A G L I O H M R T
guaranteed to be in its correct place.
12 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 9 SKILLS INNOVATION

Use a bubble sort to arrange these numbers into descending order.


39  57  72  39  17  24  48

39 57 72 39 17 24 48 39 < 57 so swap
57 39 72 39 17 24 48 39 < 72 so swap Watch
out Read the question carefully. You
57 72 39 39 17 24 48 39 ≮ 39 so leave need to sort the list into descending order.

57 72 39 39 17 24 48 39 ≮ 17 so leave
57 72 39 39 17 24 48 17 < 24 so swap
57 72 39 39 24 17 48 17 < 48 so swap
57 72 39 39 24 48 17
After 1st pass: 57 72 39 39 24 48 17
After 2nd pass: 72 57 39 39 48 24 17
Note that the 48 is now between the two 39s.
After 3rd pass: 72 57 39 48 39 24 17 Do not treat the two 39s as one term.
After 4th pass: 72 57 48 39 39 24 17
After 5th pass: 72 57 48 39 39 24 17 Make sure that you make a statement like
No swaps in 5th pass, so the list is in order. this to show that no swaps have been made
and you have completed the algorithm.

Exercise 1C SKILLS REASONING/ARGUMENTATION

1 Apply a bubble sort to arrange each list below into:


a ascending order b descending order
i 23 16 15 34 18 25 11 19
ii
N E T W O R K S Hint
For part iii, order
iii
A5 D3 D2 A1 B4 C7 C2 B3 alphabetically then numerically.
So C2 comes after A5 but
For each part, you need to show the state of the list only at
before C7.
the end of each pass.

2 Perform a bubble sort to arrange these place names into alphabetical order.
Chester  York  Stafford  Bridlington  Burton  Cranleigh  Evesham

P 3 A list of n items is to be written in ascending order using a bubble sort.


a State the minimum number of passes needed.
b Describe the circumstances in which this number of passes would be sufficient.
c State the maximum number of passes needed.
d Describe the circumstances in which this number of passes would be needed.
ALGORITHMS CHAPTER 1 13
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E 4 Here is a list of exam scores:


63  48  57  55  32  48  72  49  61  39
The scores are to be put in order, highest first, using a bubble sort.
a Describe how to carry out the first pass.  (2 marks)
b Apply a bubble sort to put the scores in the required order.
Only show the state of the list at the end of each pass.  (4 marks)

1.4 Quick sort


The quick sort algorithm can be used to arrange a list into alphabetical or numerical order.
In many cases, a quick sort is faster to perform than a bubble sort. We can thus say that it is more
efficient.
In a quick sort, we choose an item which we call a pivot,
and split the items into two sublists:
• One sublist contains items less than the pivot. Hint
If an item is equal to the
• The other sublist contains items greater than the pivot. pivot it can go in either sublist.

Once we have done this we have completed the first pass.

In doing the quick sort, the first pass will place the pivot item in its correct position in the list.

We then repeat this until all items are chosen as pivots, and then the list is in order. You will need
to write that all items are chosen as pivots, which means that they are in order.

Here is the quick sort algorithm, used to sort a list into ascending order.

1 Choose the item at the midpoint of the list to (n + 1)


Use the formula ______
​​   ​​   and
be the first pivot. 2
round up, if needed, to find the
2 Write down all the items that are less than the
midpoint of the list. For example,
pivot, keeping their order, in a sublist. if there are 10 items in the list,
3 Write down the pivot. (10 + 1)
​​ _______  = 5.5 and so the 6th item
 ​​ 
2
4 Write down the remaining items (those greater in the list is the midpoint.
than the pivot) in a sublist.
5 Apply steps 1 to 4 to each sublist. Do not sort the items as you write
6 When all items have been chosen as pivots, stop. them down.

The number of pivots could double at each pass. There is 1 pivot at the first pass, there could be
2 at the second, 4 at the third, 8 at the fourth, and so on.
14 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 10 SKILLS ANALYSIS

Use the quick sort algorithm to arrange the numbers below into ascending order.
21  24  42  29  23  13  8  39  38

n+1
21 24 42 29 23 13 8 39 38 For n items, the pivot will be the _____
​​   ​​   th

  item,
2
rounding up if necessary.
There are 9 numbers in the list so the
21 13 8
9+1
midpoint will be ​​ _____  = 5, so the pivot is
 ​​ 
2
21 13 8 23 the 5th number in the list. Circle it.

Write all the numbers less than 23.


21 13 8 23 24 42 29 39 38
Write the pivot in a box , then write the
21 13 8 23 24 42 29 39 38 remaining numbers.

8 13 21 23 24 29 42 39 38 Now select a pivot in each sublist.

There are now four sublists so we choose four


8 13 21 23 24 29 38 39 42 pivots (circled).

8 13 21 23 24 29 38 39 42
We can choose only two pivots this time. Each
number has been chosen as a pivot, so the list
is in order.
Example 11 SKILLS PROBLEM-SOLVING

Use the quick sort algorithm to arrange the list below into descending order.
37  20  17  26  44  41  27  28  50  17
There are 10 items in the list so the
37 20 17 26 44 41 27 28 50 17 (​10+1)​
midpoint will be ______
​​   ​​  = 5.5, and so the
2
pivot is the 6th number in the list. Circle it.
44 50 41 37 20 17 26 27 28 17
Numbers greater than the pivot are to the
left of the pivot, those smaller than the
50 44 41 37 27 28 26 20 17 17 pivot are to the right, keeping the numbers
in order. Numbers equal to the pivot may
go either side, but must be dealt with in
50 44 41 37 28 27 26 20 17 17 the same way each time you do a pass.

Two pivots are chosen, one for each sublist.


50 44 41 37 28 27 26 20 17 17

Now three pivots are selected.


50 44 41 37 28 27 26 20 17 17
We now choose the next two pivots, even
if the sublist is in order.
Watch
out Colour is used here to make
the method clear, but colours should not
The final pivots are chosen to give the list
be used in your exam.
in order.
ALGORITHMS CHAPTER 1 15
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 1D SKILLS REASONING/ARGUMENTATION

1 Use a bubble sort to arrange the list of numbers below into:


a ascending order b descending order
8  3  4  6  5  7  2

2 Use the quick sort algorithm to arrange the list below into:
a ascending order b descending order

22  17  25  30  11  18  20  14  7  29

3 Sort the letters below into alphabetical order using:


a a bubble sort b a quick sort
N  H  R  K  S  C  J  E  M  P  L

4 The list shows the test results of a group of students.


Alex 33 Hetal  9
Alison 56 Janelle 89
Amy 93 Josh 37
Annie 51 Lucy 57
Dewei 77 Masingur 19
Greg 91 Sam 29
Harry 49 Sophie 77
Produce a list of students, in descending order of their marks, using:
a a bubble sort b  a quick sort

E/P 5 A list of n items is to be written in ascending order using the bubble sort algorithm.
a Find an expression, in terms of n, for the maximum number of comparisons to be made.
 (2 marks)
b Describe a situation where a bubble sort might be quicker than a quick sort.  (2 marks)
c Decide whether a bubble sort or a quick sort will be quicker in the following cases:
i 1 2 3 7 4 5 6
ii
2 3 4 5 6 7 1
Explain how you made your decisions.  (4 marks)
16 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E 6 The table shows a list of nine names of students in a dance class.

Hassler Sauver Finch Giannini Mellor Clopton Miranti Worth Argi


H S F G Me C Mi W A
a Explain how to carry out the first pass of a quick sort algorithm to order the list
alphabetically.  (2 marks)
b Carry out the first two passes of a quick sort on this list, writing down the pivots
used in each pass.  (3 marks)

Challenge
SKILLS You will need a pack of ordinary playing cards, with any jokers removed. Hint
The final order
INNOVATION A pack of playing cards has 52 cards, split into 4 suits:
should be:
Hearts  ♥    Diamonds  ♦    Clubs  ♣    Spades  ♠ A♥, 2♥, …, K♥, A♣, 2♣, …,
There are 13 cards in each suit, as follows: K♣, A♦, …, K♦, A♠, …, K♠
Ace (1), 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack (11), Queen (12), King (13)
a Use the quick sort algorithm to sort the cards into ascending order,
from Ace to King within each suit and with the suits in the order: Hearts,
Clubs, Diamonds, Spades. Follow these steps:
1 Shuffle the pack thoroughly and hold it face up.
2 Remove the 27th card and place it face up. This is your pivot card.
3 Go through the pack from the top. Place the cards into two piles
depending on whether they are lower or higher than the pivot card.
4 Repeat these steps with each new pile, choosing the card halfway
through the pile as the pivot card.
Record the total number of passes needed to sort the deck completely.
b Once the cards are in order, what single change could be made so that a
bubble sort would require 51 passes to put the cards back in order?

1.5 Bin-packing algorithms


Bin packing refers to a whole class of problems.
The easiest way of thinking about this algorithm is to imagine boxes of fixed width a and length
b, but varying heights, and stacking them into bins of width a and length b, using the minimum
number of bins.

b
a

b
b b
a
a a a a a
ALGORITHMS CHAPTER 1 17
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Similar problems are: loading cars of different lengths onto a ferry with several lanes of equal
length, a plumber needing to cut sections from lengths of copper pipe, or recording music tracks
onto a set of CDs.
You need to be able to apply three different bin-packing algorithms, and be aware of their
strengths and weaknesses.
■ The three bin-packing algorithms are: first-fit, first-fit decreasing and full-bin.
It is useful to first find a lower bound for the number
Notation
An optimal solution is one
of bins needed. There is no guarantee that you will be
that cannot be improved upon. For bin
able to pack the items into this number of bins, but it
packing, an optimal solution will use the
will tell you if you have found an optimal solution.
smallest possible number of bins.

Example 12 SKILLS ANALYSIS

Nine boxes of fixed cross-section have heights, in metres, as follows.


0.3 0.7 0.8 0.8 1.0 1.1 1.1 1.2 1.5
They are to be packed into bins with the same fixed cross-section and height 2 m.
Determine the lower bound for the number of bins needed.

0.3 + 0.7 + 0.8 + 0.8 + 1.0 + 1.1 + 1.1 + 1.2 Sum the heights and divide by the bin size.
  + 1.5 = 8.5 m You must always round up to determine the
8.5
____ lower bound.
 = 4.25 bins
​​   ​​ 
2
So a minimum of 5 bins will be needed. Watch
out In practice, it may not be possible
to pack these boxes into 5 bins. The lower bound
simply tells us that at least 5 bins will be needed.

With small amounts of data it is often possible to ‘spot’ an optimal answer.


The algorithms you will learn in this chapter will not necessarily find an optimal solution,
but can be applied quickly.
■ The first-fit algorithm works by considering items in the order they are given.
First-fit algorithm

1 Take the items in the order given.


2 Place each item in the first available bin that can take it. Start from bin 1 each time.

Advantage: It is quick to apply.


Online
See the operation of the
Disadvantage: It is not likely to lead to a good solution.
first-fit algorithm using GeoGebra.
18 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 13 SKILLS EXECUTIVE FUNCTION

Use the first-fit algorithm to pack the following items into bins of size 20. (The numbers in brackets
are the size of the item.) State the number of bins used and the amount of wasted space.
A(8)  B(7)  C(14)  D(9)  E(6)  F(9)  G(5)  H(15)  I(6)  J(7)  K(8)

A(8) goes into bin 1, leaving space of 12.


G(5) E(6) B(7) goes into bin 1, leaving space of 5.
F(9) C(14) goes into bin 2, leaving space of 6.
B(7) D(9) goes into bin 3, leaving space of 11.
J(7) E(6) goes into bin 2, leaving space of 0.
C(14) H(15)
F(9) goes into bin 3, leaving space of 2.
A(8) D(9) K(8) G(5) goes into bin 1, leaving space of 0.
I(6)
H(15) goes into bin 4, leaving space of 5.
Bin 1 Bin 2 Bin 3 Bin 4 Bin 5 Bin 6 I(6) goes into bin 5, leaving space of 14.
This used 6 bins and there are J(7) goes into bin 5, leaving space of 7.
2 + 5 + 7 + 12 = 26 units of waste of space. K(8) goes into bin 6, leaving space of 12.

■ The first-fit decreasing algorithm requires the items to be in descending order before applying
the algorithm.
First-fit decreasing algorithm

1 Sort the items so that they are in descending order.


2 Apply the first-fit algorithm to the reordered list.

Advantages: You usually get a fairly good solution. Online


See the operation of the
It is easy to apply. first-fit decreasing algorithm using
Disadvantage: You may not get an optimal solution. GeoGebra.

Example 14 SKILLS ANALYSIS

Apply the first-fit decreasing algorithm to the data given in Example 13.

Sort the data into descending order: H(15) goes into bin 1, leaving space of 5.
H(15) C(14) D(9) F(9) A(8) K(8) B(7) J(7) E(6) I(6) G(5) C(14) goes into bin 2, leaving space of 6.
D(9) goes into bin 3, leaving space of 11.
G(5) E(6) I(6) F(9) goes into bin 3, leaving space of 2.
A(8) goes into bin 4, leaving space of 12.
F(9)
K(8) K(8) goes into bin 4, leaving space of 4.
J(7)
B(7) goes into bin 5, leaving space of 13.
H(15) C(14) J(7) goes into bin 5, leaving space of 6.
D(9) A(8) B(7) E(6) goes into bin 2, leaving space of 0.
I(6) goes into bin 5, leaving space of 0.
Bin 1 Bin 2 Bin 3 Bin 4 Bin 5 G(5) goes into bin 1, leaving space of 0.
This used 5 bins and there are
2 + 4 = 6 units of wasted space.
ALGORITHMS CHAPTER 1 19
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

■ Full-bin packing uses inspection to select items that will combine to fill bins.
Remaining items are packed using the first-fit algorithm.
Full-bin packing
1 Use observation to find combinations of items that will fill a bin. Pack these items first.
2 Any remaining items are packed using the first-fit algorithm.

Advantage: You usually get a good solution.


Disadvantage: It is difficult to do, especially when the numbers are plentiful and awkward.

Example 15 SKILLS EXECUTIVE FUNCTION

A(8)  B(7)  C(10)  D(11)  E(13)  F(17)  G(4)  H(6)  I(12)  J(14)  K(9)
The items above are to be packed in bins of size 25.
a Determine the lower bound for the number of bins.
b Apply the full-bin algorithm.
c Is your solution optimal? Give a reason for your answer.

a 111 ÷ 25 = 4.44
So lower bound is 5 bins.
b Three groupings of numbers that sum to
25 can be made as follows:
8 + 7 + 10 = 25
11 + 14 = 25
13 + 12 = 25 The first three bins are full bins.

C(10) I(12)
J(14)

B(7)

D(11) E(13)
A(8)

Bin 1 Bin 2 Bin 3 Bin 4 Bin 5

We now apply the first-fit algorithm to the


C(10) I(12) G(4) remainder.
J(14)
F(17) goes into bin 4, leaving space of 8.
B(7) K(9) G(4) goes into bin 4, leaving space of 4.
F(17) H(6) goes into bin 5, leaving space of 19.
D(11) E(13)
A(8) K(9) goes into bin 5, leaving space of 10.
H(6)
Bin 1 Bin 2 Bin 3 Bin 4 Bin 5
c The lower bound is 5, and 5 bins were
used, so the solution is optimal.
20 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 16 SKILLS EXECUTIVE FUNCTION

A plumber needs to cut the following lengths of copper pipe. (Lengths are in metres.)
A(0.8)  B(0.8)  C(1.4)  D(1.1)  E(1.3)  F(0.9)  G(0.8)  H(0.9)  I(0.8)  J(0.9)
The pipe comes in lengths of 2.5 m.
a Calculate the lower bound of the number of lengths of pipe needed.
b Use the first-fit decreasing algorithm to determine how the required lengths may be cut from the
2.5 m lengths.
c Use full-bin packing to find an optimal solution.

0.8 + 0.8 + 1.4 + 1.1 + 1.3 + 0.9 + 0.8 + 0.9 + 0.8 + 0.9
a ​​ ____________________________________________________
            ​​
2.5
= 3.88
Since a sort was not asked for, this can
So at least 4 lengths are required.
be done by inspection.
b Sorting into descending order,
C(1.4), E(1.3), D(1.1), F(0.9), H(0.9),
J(0.9), A(0.8), B(0.8), G(0.8), I(0.8) C goes into bin 1, leaving space of 1.1.
E goes into bin 2, leaving space of 1.2.
D goes into bin 1, leaving space of 0.
D(1.1) G(0.8)
F(0.9) F goes into bin 2, leaving space of 0.3.
H goes into bin 3, leaving space of 1.6.
J(0.9)
B(0.8) J goes into bin 3, leaving space of 0.7.
A goes into bin 4, leaving space of 1.7.
C(1.4) E(1.3)
H(0.9) A(0.8) I(0.8) B goes into bin 4, leaving space of 0.9.
G goes into bin 4, leaving space of 0.1.
Bin 1 Bin 2 Bin 3 Bin 4 Bin 5 I goes into bin 5, leaving space of 1.7.

c By inspection,
In part a we found that at least 4
C(1.4) + D(1.1) = 2.5
lengths would be needed, so this
F(0.9) + A(0.8) + B(0.8) = 2.5
solution is optimal since it uses 4
J(0.9) + G(0.8) + I(0.8) = 2.5
lengths.
A full-bin solution is:

B(0.8) I(0.8)
D(1.1)
H(0.9)
A(0.8) G(0.8)

C(1.4) E(1.3)
F(0.9) J(0.9)

Bin 1 Bin 2 Bin 3 Bin 4


ALGORITHMS CHAPTER 1 21
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 1E SKILLS REASONING/ARGUMENTATION

1 18  4  23  8  27  19  3  26  30  35  32
The above items are to be packed in bins of size 50.
a Calculate the lower bound for the number of bins.
b Pack the items into the bins using:
i  the first-fit algorithm  ii  the first-fit decreasing algorithm  iii  the full-bin algorithm

2 Laura hosts an internet music channel and wishes to play the 13 pieces of music listed below.
Each day, she hosts a session which is at most 3 hours long.
Piece of music A B C D E F G H I J K L M
Length (minutes) 30 30 30 45 45 60 60 60 60 75 90 120 120

a Apply the first-fit algorithm, in the order A to M, to determine the number of days that need
to be used. State which music is played on each day.
b Repeat part a using the first-fit decreasing algorithm.
c Is your answer to part b optimal? Give a reason for your answer.
Laura finds that her session time is now reduced to only 2 hours.
d Use the full-bin algorithm to determine the number of days she needs to use. State which
music is played on each day.

E 3 A small ferry loads vehicles into 30 m lanes. The vehicles are loaded bumper to bumper.
Vehicle Length (m) Vehicle Length (m)
A car 4 m F car 4 m
B car and trailer 7 m G lorry 12 m
C lorry 13 m H lorry 14 m
D van 6 m I van 6 m
E lorry 13 m J lorry 11 m

a Describe one difference between the first-fit and full-bin methods of bin packing.  (1 mark)
b Use the first-fit algorithm to determine the number of lanes needed to load all the
vehicles onto the ferry.  (4 marks)
c Use a full-bin method to obtain an optimal solution using the minimum number of lanes.
Explain why your solution is optimal.  (4 marks)

E 4 The ground floor of an office block is to be fully recarpeted, with specially made carpet
incorporating the firm’s logo. The carpet comes in rolls of 15 m.
The following lengths are required.
A 3 m D 4 m G 5 m J 7 m
B 3 m E 4 m H 5 m K 8 m
C 4 m F 4 m I 5 m L 8 m
22 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

The lengths are arranged in ascending order of size.


a Obtain a lower bound for the number of rolls of carpet needed.  (2 marks)
b Use the first-fit decreasing bin-packing algorithm to determine the number of rolls needed.
State the length of carpet that is wasted using this method.  (3 marks)
c Give one disadvantage of the first-fit decreasing bin-packing algorithm.  (1 mark)
d Use a full-bin method to obtain an optimal solution, and state the total length
of wasted carpet using this method.  (4 marks)

E/P 5 Eight computer programs need to be copied onto 40 GB USB sticks.


The size of each program is given below.
Program A B C D E F G H
Size (GB) 8 16 17 21 22 24 25 25
a Use the first-fit decreasing algorithm to determine which
programs should be recorded onto each USB stick.  (3 marks)
b Calculate a lower bound for the number of USB sticks
Problem-solving
needed.  (2 marks)
Consider the programs over
c Explain why it is not possible to record these programs
20 GB in size.
on the number of USB sticks found in part b.  (1 mark)

1.6 Binary search


You need to be able to carry out a binary search.
A binary search will look through an ordered list to find out whether or not an item you are trying
to find is in the list. If the item is in the list, the binary search will locate its position within the list.
If the list is not in order, then you may need to use a bubble sort or quick sort to put the items
into order first.

■ In a binary search, we look at halving the size of the list each time we perform a pass.
n+1
• In a binary search, we locate the midpoint of the list using _____  . We call this the pivot.
​​   ​​ 
2
Like with the quick sort, we round this up if it is not an integer.
• We compare this midpoint with the item we are trying to locate; this will help us decide which
half of the list to choose.
• Eventually we will get to one item – it will either be the item we are trying to locate, or it
will not be. In this case we can say that the item we were trying to locate is not in the list.
Here is the binary search algorithm to locate an item in a list:
n+1
1 Select the midpoint of the list using _____
​​   ​​ 
 and round up if necessary. This is the pivot.
2
2 a If the pivot is the item we are locating, then the search is complete.
b If the pivot is after the item we are locating, then we look in the first half of the list.
c If the pivot is before the item we are locating, then we look in the second half of the list.
3 Repeat steps 1 and 2 to each remaining list until the item is located. If the item is not found,
then it is not in the list.
ALGORITHMS CHAPTER 1 23
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 17

Use the binary search algorithm to try to locate these names in the list that follows.
a Robinson b Davies
 1 Acharya  6 Laing
Watch
out Remember that a search can be
 2 Blackstock  7 Leung
unsuccessful. You may be asked to try to locate
 3 Cheung  8 Robinson
something that is not in the list. You must be
 4 Coetzee  9 Saludo able to show that the item is not in the list.
 5 Fowler 10 Xiao
n+1
Remember to round up if _____
a The middle name is the ​​(​  _____   = 5.5)​​6th name:
n+1 ​​   ​​  is not an
 ​
  2
2 integer.
6 Laing
Robinson is after Laing, so the list reduces to
Since Robinson is after Laing, Robinson
1 Leung
cannot be in the first part of the list and
2 Robinson
so we consider the list after the pivot.
3 Saludo
4 Xiao
The middle name in this sublist is the Robinson is before Saludo so it cannot
be in the second list and so we consider
(​​ ​  2 ​   = 2.5)​​ 3rd name:
+1
4_____
  the list before the pivot.
3 Saludo
Robinson is before Saludo, so the list reduces to:
1 Leung
2 Robinson
The middle name in this sublist is the

(​​ ​  2 ​   = 1.5)​​ 2nd name:


+1
2_____

2 Robinson
The search is complete.
Robinson has been found in the list. It is important to write this down.

b The middle name is the ​​(​  ______   = 5.5)​​ 6th name:


10 + 1
 ​ 
2 Consider the list before the pivot.
6 Laing
Davies is before Laing so the list reduces to:
1 Acharya
2 Blackstock
3 Cheung
4 Coetzee
5 Fowler
The middle name is the ​​(​  _____   = 3)​​ 3rd name:
5+1
 ​
  Consider the list after the pivot.
2
3 Cheung
Davies is after Cheung so the list reduces to
1 Coetzee
2 Fowler
24 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

The middle name is the ​​(​  _____   = 1.5)​​ 2nd name:


n+1
 ​
  Consider the list before the pivot.
2
2 Fowler
Davies is before Fowler so the list reduces to:
1 Coetzee
The list has only one item which is not Davies. It is important to write this down.
Therefore Davies is not in the list.

Exercise 1F SKILLS ANALYSIS

1 Use the binary search algorithm to try to locate these names in the list that follows:
a Connock b Walkey c Peabody
1 Berry 5 Tapner
2 Connock 6 Walkey
3 Li 7 Wilson
4 Sully 8 Wu

2 Use the binary search algorithm to try to locate these numbers in the list that follows:
a 21 b 5
1 3 3 7 5 10 7 15  9 18 11 21
2 4 4 9 6 13 8 17 10 20 12 24

P 3 The binary search algorithm is applied to an ordered list of n items.


Find the maximum number of times the algorithm is run when n is equal to:
a 100 b 1000 c 10 000

4 a 
Use the quick sort algorithm to put the list below into ascending order.
 1 Adam  6 Ramin 11 Oli 16 Miranda
 2 Ed  7 Alex 12 Lotus 17 Matt
 3 Lei  8 Emily 13 Des 18 Katie
 4 Lottie  9 Felix 14 George 19 Doug
 5 Saul 10 Leo 15 Jess 20 Hongmei
b Use the binary search algorithm to try to locate:
i George ii David iii Jess

Chapter review 1

E 1 Use the bubble-sort algorithm to sort, in ascending order, the list


27  15  2  38  16  1
giving the state of the list at each stage.  (4 marks)
ALGORITHMS CHAPTER 1 25
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E/P 2 a Use the bubble-sort algorithm to sort, in descending order, the list
25  42  31  22  26  41
giving the state of the list on each occasion when two or more
values are interchanged (swapped).  (4 marks)
b Find the maximum number of interchanges needed to sort a list
of six pieces of data using the bubble-sort algorithm.  (2 marks)

E 3 8  4  13  2  17  9  15
This list of numbers is to be sorted into ascending order.
Perform a quick sort to obtain the sorted list, giving the state of the list after each
rearrangement.  (5 marks)

E 4 111  103  77  81  98  68  82  115  93
a The list of numbers above is to be sorted into descending order.
Perform a quick sort to obtain the sorted list, giving the state of the list
after each rearrangement and indicating the pivot elements used.  (5 marks)
b i Use the first-fit decreasing bin-packing algorithm to fit the data
into bins of size 200.  (3 marks)
ii Explain how you decided in which bin to place the number 77.  (1 mark)

E 5 Trishna wishes to record eight television programmes. The lengths of the programmes,
in minutes, are:
75  100  52  92  30  84  42  60
Trishna decides to use 2-hour (120 minute) DVDs only to record all of these programmes.
a Explain how to apply the first-fit decreasing bin-packing algorithm.  (2 marks)
b Use this algorithm to fit these programmes onto the smallest number of DVDs possible,
stating the total amount of unused space on the DVDs.  (3 marks)
Trishna wants to record an additional two 25-minute programmes.
c Determine whether she can do this using only 5 DVDs, giving reasons for your answer.
 (3 marks)

E 6 A DIY enthusiast requires the following 14 pieces of wood as shown in the table.
Length in metres 0.4 0.6 1 1.2 1.4 1.6
Number of pieces 3 4 3 2 1 1

The DIY store sells wood in 2 m and 2.4 m lengths. He considers buying six 2 m lengths of wood.
a Explain why he will not be able to cut all of the lengths he requires from these six
2 m lengths.  (2 marks)
b He eventually decides to buy 2.4 m lengths. Use a first-fit decreasing bin-packing algorithm
to show how he could use six 2.4 m lengths to obtain the pieces he requires.  (4 marks)
c Obtain a solution that requires only five 2.4 m lengths.  (4 marks)
26 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E/P 7 The algorithm described by the flow chart below is to be Hint


This question uses the
applied to the five pieces of data below. modulus function. If x ≠ y, |x − y|
u1 = 6.1, u2 = 6.9, u3 = 5.7, u4 = 4.8, u5 = 5.3 is the positive difference between
x and y, e.g. |5 − 6.1| = 1.1.
a Obtain the final output of the algorithm using the five
values given for u1 to u5.  (4 marks)
b In general, for any set of values u1 to u5, explain what the algorithm achieves.  (2 marks)
Start

Box 1 i = 1, A = u1
Temp = | 5 – u1 |

Box 2 i=i+1

Box 3 M = | 5 – ui|

Is
Box 4 M < Temp?

Yes

A = ui
Box 5 No
Temp = M

Is Yes
Box 6
i < 5?

No

Box 7 Print A

Stop

c If Box 4 in the flow chart is altered to


‘Is M > Temp?’
state what the algorithm achieves now.  (1 mark)

E  8 A plumber is cutting lengths of PVC pipe for a bathroom.


The lengths needed, in metres, are:
0.3  2.0  1.3  1.6  0.3  1.3  0.2  0.1  2.0  0.5
The pipe is sold in 2 m lengths.
a Carry out a bubble sort to produce a list of the lengths needed in descending order.
Give the state of the list after each pass.  (4 marks)
b Apply the first-fit decreasing bin-packing algorithm to your ordered list
to determine the total number of 2 m lengths of pipe needed.  (3 marks)
c Does the answer to part b use the minimum number of 2 m lengths?
You must justify your answer.  (2 marks)
ALGORITHMS CHAPTER 1 27
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E/P  9 Here are the names of eight students in an A level group:


Manisha, Vivien, Cath, Alex, Da Ming, Beth, Kandis, Sze-To
Use a quick sort to put the names in alphabetical order. Show the result of each pass
and identify the pivots.  (5 marks)

Challenge
E/P 10 A binary search is to be performed on a list of names to try to locate Kim.
 1 Jenny  6 Hyo
 2 Merry  7 Kim
 3 Charles  8 Richard
 4 Ben  9 Greg
 5 Toby 10 Freya
a Explain why a binary search cannot be performed with the list in its present form.(1 mark)
b Using an appropriate algorithm, alter the list so that a binary search can be
performed, showing the state of the list after each complete iteration. State the
name of the algorithm you have used. (4 marks)
c Use the binary search algorithm to locate the name Kim in the list you obtained
in b. You must make your method clear.  (4 marks)
28 CHAPTER 1 ALGORITHMS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Summary of key points


1 An algorithm is a finite sequence of step-by-step instructions carried out to solve a problem.

2 In a flow chart, the shape of each box tells you about its function.

3 Unordered lists can be sorted using a bubble sort or a quick sort.

4 In a bubble sort, you compare adjacent items in a list:


•  If they are in order, leave them.
•  If they are not in order, swap them.
•  The list is in order when a pass is completed without any swaps.

5 In a quick sort, you select a pivot and then split the items into two sublists:
•  One sublist contains items less than the pivot.
•  The other sublist contains items greater than the pivot.
•  You then select further pivots from within each sublist and repeat the process.

6 The three bin-packing algorithms are first-fit, first-fit decreasing, and full-bin:
• The first-fit algorithm works by considering items in the order they are given.
• The first-fit decreasing algorithm requires the items to be in descending order
before applying the algorithm.
• Full-bin packing uses inspection to select items that combine to fill bins completely.
Remaining items are packed using the first-fit algorithm.

7 The three bin-packing algorithms have the following advantages and disadvantages:

Type of algorithm Advantage Disadvantage


First-fit Quick to apply Not likely to lead to a good solution
First-fit decreasing Usually a good solution; May not get an optimal solution
easy to apply
Full-bin Usually a good solution Difficult to do, especially when the
numbers are plentiful or awkward

8 A binary search will search an ordered list to find out whether an item is in the list. If it is in
the list, it will locate its position in the list.
In a binary search, the pivot is the middle item of the list. If the target item is not the pivot,
the pivot and half of the list are discarded. The list length halves at each pass.
n+1
The middle of n items is found by _____
​​   ​​ 
 , rounding up if necessary.
2
2 GRAPHS AND
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

NETWORKS 2.1

Learning objectives
After completing this chapter you should be able to:
● Know how graphs and networks can be used to
create mathematical models → pages 30–33
● Be familiar with basic graph theory terminology  → pages 34–38
● Know some special types of graph  → pages 38–40
● Understand how graphs and networks can be
represented using matrices  → pages 42–44

Prior knowledge check

1 In the diagram, triangle ABC has sides of lengths


a, b and c.
A
b c

C B
a

Explain why a < b + c.


 ← International GCSE Mathematics

2 Find the shortest path between A and D and write


down its length.
In decision mathematics, a graph
B 6 C or network refers to a set of points
6 7 1 joined by edges (line segments).
This graph models an underground
14
A D train network. The lines show which
6 5 stations are connected but their
4 7
lengths do not represent distances
F 3 E in real life.
30 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

2.1 Modelling with graphs


You need to know how graphs and networks can be used to create mathematical models.
In decision mathematics, the word graph has a very specific meaning.
■ A graph consists of points (called vertices or nodes) Notation
which are connected by lines (edges or arcs). ● A vertex is a point on a graph.
■ If a graph has a number associated with each edge Vertices (the plural of vertex) are
(usually called its weight), then the graph is known sometimes called nodes.
● An edge is a line segment joining
as a weighted graph or network.
vertices. Edges are sometimes
called arcs.

Example 1 SKILLS REASONING/ARGUMENTATION


Addis Ababa
This graph shows the routes flown by an airline. Douala
a Explain why this is a graph. Kigali
Kinshasa
b Describe what is represented by:
Libreville Bujumbura
i  the vertices
ii  the edges.
Nairobi
c Describe two possible flight routes from Brazzaville
Johannesburg to Libreville.

a It has vertices connected by edges. Johannesburg


b i  Cities served by the airline
The graph shows only which cities are connected
ii  Flight routes connecting cities
by a flight route. There is no scale and the graph
c Johannesburg to Douala to Libreville is not weighted, so it does not show any distances
Johannesburg to Kinshasa to Libreville or the correct geographical position of the cities.

Example 2 SKILLS INTERPRETATION

This network shows the lengths of pipes running A 150 E


between taps on a camp site. The lengths on the 80
edges are given in metres. 30 100 60
60
a Write down the length of the B
50
main 90 F
pipe connecting tap B to tap D. supply D
b Write a list of the taps that 100 80
are directly connected to tap E. C

a 50 m
b A, B, F This is an example of a weighted network.
GRAPHS AND NETWORKS CHAPTER 2 31
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 3 SKILLS ANALYSIS

The network shows the times taken, in minutes, by a car to travel along some sections of road.
C
A
5 8

B 1
10
2

E 5 D

Calculate the minimum time needed to travel from A to D and give the route taken.

Route Time needed (min) Watch


out A weighted network is not usually
ABCD 5 + 8 + 1 = 14 drawn to scale. The quickest route may not be
ABED 5 + 2 + 5 = 12 the route which appears to be the shortest;
AED 10 + 5 = 15 you need to consider the weight on each arc.

The minimum time required is 12 minutes,


along the route ABED.

Exercise 2A SKILLS ANALYSIS

1 This graph represents the friendships within a group of students.


Adok
Fabio
Han
Banjit

Chris

Govinda
Dhevan Esme

a State what is represented by each:


i vertex
ii arc.
b List all of Chris’s friends within the group.
c State two new friendships that could be created to ensure that
every pair of friends has at least one friend in common.
32 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

2 This table gives information about the subjects studied by some students.
Student Subjects
A Mathematics, Chemistry
B Mathematics, Chemistry, Biology, Art
C Physics, Chemistry, Biology
D Mathematics, Physics, Art, English
E Biology, English, Art
F English, Mathematics, Art, Physics

a Copy and complete the graph to represent this information.


Use the arcs to show which subjects each student studies.
A B C D E F

Mathematics Physics Chemistry Biology Art English

b Which subjects are studied by the most students?

P 3 Here is a map of part of the London underground train system. The colours indicate the
different train lines and a circle indicates where you can change from one line to another without
leaving the underground.
GRAPHS AND NETWORKS CHAPTER 2 33
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

To go from Lancaster Gate to Hyde Park Corner, for example, you would take the red line from
Lancaster Gate to Bond Street, change onto the grey line to Green Park, and finally take the
dark blue line to Hyde Park Corner.
a Work out a possible route from Chancery Lane to Victoria:
i that requires a minimum number of changes
ii that passes through a minimum number of stations.
A student estimates that it takes 80 seconds to travel from one station to the next, and that it
takes 3 minutes to change trains at one of the junction stations.
b Work out the quickest possible journey time from:
i Marylebone to Waterloo
ii Victoria to Baker Street
iii Holborn to St James’s Park.

P 4 This weighted network shows the flight times of a particlar airline, in minutes,
between some airports in the UK and Ireland.
A

A Aberdeen
118 E
G B Belfast
45 C Cork
B 85 N
40 D Dublin
38
73 E Edinburgh
L
D G Glasgow
65 M
L Leeds-Bradford
92
55 M Manchester
C N Newcastle
a Write down the flight time between Glasgow and Manchester.
b Name the route with the longest flight time.
c Suggest which city might be the home base of this airline. Give a reason for your answer.

P 5 This network shows the lengths, in km, of a network P 16 U


of mountain bike trails. 17
A student says that the shortest possible route to 12 15
9
cycle from P to V is 27 km long. Q
4 18
a State which route the student has chosen to T V
3
calculate this distance. 19
5
b State, with a reason, whether or not the student
R 4
is correct. S

Challenge H G
SKILLS The diagram shows a wire network in the shape of a cube. E F
INNOVATION An ant walks from vertex A to vertex G along the cube’s edges.
Find the total number of possible different routes which: D
C
a are of minimum length
b do not pass through any vertex more than once. A B
34 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

2.2 Graph theory


Graph theory is a rapidly growing area of mathematics, mainly due to its applications in many areas.
Satellite navigation systems use graph theory to find the fastest or shortest journey between two
places. Many project management companies use critical path analysis to schedule how a project
can be organised. The famous four colour theorem has also been proved using graph theory ideas.
First, we need to introduce some of the basic ideas and definitions in graph theory.
There are two different types of notation used to describe graphs, as follows:
B
A and B are
nodes (vertices).
C
A

AF is an arc (edge). Watch


out
D The intersection of the edges AC
E
and BD is not a vertex.
F Graph G
In graph G, above:
● the vertices (nodes) are: A, B, C, D, E and F
(the list of vertices is sometimes called the vertex set).
● the edges (arcs) are: AB, AC, AF, BC, BD, CE and DE
(the list of edges is sometimes called the edge set).
■ A subgraph of G is a graph, each of whose vertices belongs to G and each of whose edges
belongs to G. It is simply a part of the original graph.
B Subgraph 1 B Subgraph 2
Some A C
A C possible A C
subgraphs. D
F E
D
F E F

■ The degree of a vertex is the number of edges that meet at that vertex. Notation
K Vertex Degree The degree
Degree 2 because 2 edges meet here.
J 2 of a vertex is
L K 2 sometimes called
the valency or
L 1
order.
J M 4
M
N
N 1

Links
A trail which traverses
■ If the degree of a vertex is even, it has even degree, so J,
K and M have even degree. Vertices L and N have odd degree. every arc and starts and ends
at the same vertex is called an
■ A walk is a route through a graph along edges from Eulerian cycle.
one vertex to the next.  → Decision 1 Section 4.1
GRAPHS AND NETWORKS CHAPTER 2 35
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

■ A path is a walk in which no vertex is visited more than once.


■ A trail is a walk in which no edge is visited more than once.
■ A cycle is a walk in which the end vertex is the same as the
start vertex and no other vertex is visited more than once.
■ A Hamiltonian cycle is a cycle that includes every vertex.
In the graph below, an example of:
● a walk is RSUWVU On a walk, it is okay to include a vertex or an edge more than once.
● a path is RSUVW
● a trail is RUSVUW
● a cycle is RSUR In a cycle, it is not necessary to include every vertex.
● a Hamiltonian cycle is RSUVWTR.
S
V

R
U
W

■ Two vertices are connected if there is a path between them.


A graph is connected if all its vertices are connected.
E R T
G

F H V
S
U
This is a connected graph. This graph is not connected.
A path can be found between any two vertices. There is no path from R to V, for example.
■ A loop is an edge that starts and finishes at the same vertex.
A

loop This contains a loop from C to C.



C
B Vertex C has degree 3.

■ A simple graph is one in which there are no loops and there is no more than one edge
connecting any pair of vertices.
multiple
edges This is not a simple graph because it
D
has two edges connecting D and E.
E

F
C
36 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

■ If the edges of a graph have a direction associated with them they are known as directed edges
and the graph is known as a directed graph, often abbreviated to digraph.
Q

P R

T
S

■ In any undirected graph, the sum of the degrees of the vertices Notation
A lemma is
is equal to 2 × the number of edges. As a result, the number a small theorem used as
of odd vertices must beeven, including possibly zero. a stepping stone to more
This result is knownas Euler’s handshaking lemma. important results.

Example 4 A
a Find the sum of the valencies of the vertices in this graph.
b Verify that your answer to part a is twice the number of B
edges in the graph. F C

a Vertex Valency
A 3
B 3 E D
C 3
D 3 Notice that the number of vertices of odd degree
is even (there are four of them).
E 4
If each vertex represents a person and each edge
F 2
indicates that two people have shaken hands,
Total 18 then the number of people who have shaken
b The graph has 9 edges. hands an odd number of times must be even.
Sum of valencies = 18 = 2 × 9
= 2 × number of edges

Example 5 SKILLS PROBLEM-SOLVING

A graph has 5 nodes and 8 edges. The valencies of the nodes are x, x − 1, x + 1, 2x − 1 and x − 1.
Find the value of x.

Sum of valencies Problem-solving


= x + x − 1 + x + 1 + 2x − 1 + x − 1 Use Euler’s handshaking lemma to
= 6x − 2 formulate an equation in x.
Sum of valencies = 2 × number of edges
= 2 × 8 = 16
6x − 2 = 16
6x = 18
x=3
GRAPHS AND NETWORKS CHAPTER 2 37
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 2B SKILLS REASONING/ARGUMENTATION

1 Draw a connected graph with:


a one vertex of degree 4 and four vertices of degree 1
b three vertices of degree 2, one of degree 3 and one of degree 1
c two vertices of degree 2, two of degree 3 and one of degree 4.

2 Which of the graphs below are not simple?


a A D b F G
K

C J

I H
B E
c P d U V

T Q
W

X
Z
S R

3 In question 2, which graphs are not connected?

4 For the graph on the right, state: A


B
a four paths from F to D
b a cycle passing through F and D C
F
c the degree of each vertex.
D
Use the graph to: E

d draw a subgraph
e confirm the handshaking lemma.
N
5 Repeat question 4 parts c, d and e using this graph: K
Q
L P

J R
M S
P 6 Show that it is possible to draw a graph with:
a an even number of vertices of even degree
b an odd number of vertices of even degree.
c Explain why it is not possible to draw a graph with an odd number of vertices of odd degree.
38 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

7 Copy the diagram and complete a digraph 2 16


for the relationship ‘is a factor of’.

4 8

E 8 a Explain what is meant by a Hamiltonian cycle. (2 marks) P

b For this graph, list all of the Hamiltonian cycles


that start from the vertex P. (4 marks) T Q
c Explain what is meant by a subgraph. (2 marks)
d Draw a subgraph of this graph with 4 vertices. (1 mark)

S R
9 A graph has 7 nodes and 14 edges.
The valencies of the nodes are: x, x2, x + 1, 3x − 1, 2x + 1, 3x − 2, 4x − 3.
Find the value of x.

2.3 Special types of graph


You need to know about the following special types of graph.
■ A tree is a connected graph with no cycles.
B R
C S
A

D
T
E U W
F G V

This is a tree. This is not a tree.


It contains cycle RTUSR.

■ A spanning tree of a graph G is a subgraph which includes


all the vertices of G and is also a tree.
GRAPHS AND NETWORKS CHAPTER 2 39
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 6 SKILLS INTERPRETATION

For the following graph, draw two spanning trees.


B D

A F

C E

Possible spanning trees are:


B D
A spanning tree must be a tree (no cycles) which
means all nodes are connected by arcs.
A F

C E
B D

A F

C E
There are many other possible spanning trees.

■ A complete graph is a graph in which every vertex is directly connected by a single edge to each
of the other vertices.

Notation
The complete graph
with n vertices is written as K n .

K3 K4
K6
■ Isomorphic graphs are graphs which show the same information but may be drawn differently.
40 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

For two graphs to be isomorphic, they must have the same number of vertices of the same degree,
and these vertices must also be connected together in the same ways. If there is an edge between
two vertices in one graph, then there is also an edge between the two corresponding vertices in
the other graph.

Example 7 SKILLS DECISION-MAKING

Show that the two graphs below are isomorphic.


J K L U V

  and  R W
T
M N P Q S X

Both graphs have the same number of vertices. Each graph has the same number of vertices of
First graph Second graph the same degree.
Vertex Degree Vertex Degree
N 4 S 4
P 3 U 3
K 2 V 2
L 2 X 2
J 1 R 1
M 1 T 1
Q 1 W 1
N can be paired with S.
P can be paired with U. Pair up the vertices, starting with N and S as they
K can be paired with V. are the only vertices which have degree 4.
L can be paired with X.
J can be paired with R. You will need to check that the pairings create
M can be paired with T. the graphs in the original question.
Q can be paired with W.
Since the pairing can be made, the two
graphs are isomorphic.

If graphs are isomorphic it is possible to pair equivalent vertices.


The pairs of equivalent vertices for the graphs above are shown in this table.
Vertex Vertex paired with Vertex paired with
in first graph in second graph
A J R
B M T
C N S
D L V
E Q W
F P U
G K X
GRAPHS AND NETWORKS CHAPTER 2 41
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 2C SKILLS INTERPRETATION

1 State which of the following graphs are trees.


a b c d

P 2 There are 11 spanning trees for the graph shown below.


Draw them all.
A B

E D

3 For the graph on the right, identify a complete subgraph B


that has 4 vertices. C
A
D

F E

4 Identify which of graphs A, B and C are isomorphic to graph D.

C D
A B

E 5 a Define the terms:


i tree (1 mark)
ii spanning tree. (1 mark)
b Explain why it is not possible to construct a spanning tree for this graph. (1 mark)

E/P 6 a Draw K4. (2 marks)


b State the degree of each vertex in the graph Kn. (1 mark)
c Find the total number of edges in the graph K20. (2 marks)

Challenge
Draw all possible connected SKILLS Hint
Not counting isomorphic graphs,
graphs with three edges. CREATIVITY there are 11 such graphs.
42 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

2.4 Representing graphs and networks using matrices


You can use an adjacency matrix to represent a graph or network. The adjacency matrix provides
information about the connections between the vertices in a graph.
■ Each entry in an adjacency matrix describes the
number of arcs joining the corresponding vertices.

B
Example 8 SKILLS INTERPRETATION E

Use an adjacency matrix to represent this graph. A


F
C

A B C D E F
D
A 0 1 0 0 0 0
Watch
out You should be able to write down
B 1 0 1 0 2 1 the adjacency matrix given a graph, and draw a
C 0 1 0 1 1 0 graph given the adjacency matrix.

D 0 0 1 0 0 1
This indicates that there are 2 direct connections
E 0 2 1 0 0 1 between B and E.
F 0 1 0 1 1 2
This indicates a loop from F to F. It could be
travelled in either direction, and hence counts as 2.

The matrix associated with a weighted graph is called a distance matrix.


■ In a distance matrix, the entries represent the weight of each arc, not the number of arcs.

Example 9 SKILLS INTERPRETATION

Use a distance matrix to represent this network. B 23


17 E
A 19 16
15
A B C D E D
18 20
A — 17 18 — — C
B 17 — 15 19 23
C 18 15 — 20 —
Watch
out You should be able to write down
the distance matrix given the network, and draw
D — 19 20 — 16 the network given the distance matrix.
E — 23 — 16 —
If the network has directed edges then the
distance matrix will not be symmetrical.
Notice that the matrix is symmetrical about the
leading diagonal (top left to bottom right). This
If the vertices are not connected we use the
will be the case for any non-directed network.
— symbol, not a zero.
GRAPHS AND NETWORKS CHAPTER 2 43
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

T
Example 10 SKILLS INTERPRETATION
11
8 6 V
Use a distance matrix to represent this directed network. R U
7
9
4 9
R S T U V W
R — 4 11 — — — S 10 W

S 4 — — 9 — 10 Watch
out This matrix is not symmetrical about
11 — — 8 — — the leading diagonal.
T
U — 9 8 — 6 — This indicates a direct link of weight 6 from U to V.
V — — — 7 — —
This indicates a direct link of weight 7 from V to U.
W — 10 — — 9 —
This shows a direct link of weight 9 from W to V.

This indicates that V is not directly linked to W.


Exercise 2D SKILLS INTERPRETATION

1 Use an adjacency matrix to represent the graph below.

D
B G

C F

A
E

2 Draw a graph corresponding to each adjacency matrix.


a A B C D E b A B C D
A 0 1 0 1 0 A 0 1 0 1
B 1 0 1 1 1 B 1 0 0 1
C 0 1 0 2 0 C 0 0 2 1
D 1 1 2 0 1 D 1 1 1 0
E 0 1 0 1 0

c A B C D d A B C D
A 0 1 0 1 A 0 2 0 1
B 1 0 1 1 B 2 0 1 0
C 0 1 0 1 C 0 1 0 1
D 1 1 1 0 D 1 0 1 0
44 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

3 Draw the network corresponding to each distance matrix.


a  A B C D E b A B C D E F
A — 21 — 20 23 A — — — — 15 8
B 21 — 17 23 — B — — 9 13 17 11
C — 17 — 18 41 C — 9 — 8 — —
D 20 23 18 — 22 D — 13 8 — 10 —
E 23 — 41 22 — E 15 17 — 10 — —
F 8 11 — — — —

4 Use a distance matrix to represent the directed network below.


B 11 E
9
14 13
7
A 10 F
D 10

11 12

E 5 a Draw a graph to represent this adjacency matrix.


A B C D E
Watch
out This is an adjacency matrix,
A 0 2 0 0 1
not a distance matrix.
B 2 0 1 0 1
C 0 1 0 1 1
D 0 0 1 0 1
E 1 1 1 1 0 (3 marks)
b For this graph, a spanning tree may be drawn such that
one vertex connects to every edge. Which vertex is this? (1 mark)
c Draw the spanning tree referred to in part b. (2 marks)

Chapter review 2

1 A, B, C and D are four towns. The distance matrix shows the


direct distances by road between the towns in kilometres.
A B C D
A — 11 15 9
B 11 — — 8
C 15 — — 16
D 9 8 16 —
Draw a weighted graph to show this information.
GRAPHS AND NETWORKS CHAPTER 2 45
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

2 Which of these graphs are isomorphic?


a b c d e

f g h i

3 a Draw a graph with eight vertices, all of degree 1.


b Draw a graph with eight vertices, all of degree 2, so that the graph is:
i  connected and simple   ii  not connected and simple   iii  not connected and not simple.

4 a Describe the difference between a distance matrix and an adjacency matrix.


b Use a distance matrix to represent the network below.
B 50
F
20
15 30

18 25
A
C 20
10
16 E
23
D

c Draw a spanning tree for this network and state the weight of your spanning tree.

P 5 Write an expression for the number of edges in a spanning tree containing v vertices.

6 Write down all the possible routes from P to R Q


in this digraph.
R

P
T

S
46 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E  7 The diagram shows a graph.


A

E B

D C

a Write down the valency of vertex A. (1 mark)


b Identify:
i a path from B to D (1 mark)
ii a cycle. (1 mark)
c Sketch:
i a spanning tree for this graph (1 mark)
ii a complete subgraph of this graph. (2 marks)

E/P  8 a Explain why it is not possible to draw a graph with exactly


four vertices with degrees 3, 1, 2 and 1. (1 mark)
A connected graph has exactly four vertices and 10 edges.
The degrees of the vertices are k2 – 3k, k + 1, 8 – k and k – 4 respectively.
b Find the value of k. (3 marks)

E  9 A Hamiltonian cycle for this graph begins AGB…


A E

B F

C G

D H

a Complete the Hamiltonian cycle. (2 marks)


b For the graph below, write down a Hamiltonian cycle starting from A.
A B

F
C

E D (2 marks)

GRAPHS AND NETWORKS CHAPTER 2 47
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Challenge
SKILLS The diagram shows a connected graph. The regions of the graph are shaded in different colours.
INNOVATION,
CREATIVITY

Let V denote the number of vertices, E denote the number of edges, and R denote the number of regions
in a connected graph.
a For the graph above, verify that V + R – E = 1.
b Draw a graph with one vertex and four edges, and verify that V + R – E = 1.
c Explain why the relationship V + R – E = 1 holds for any graph with one vertex.
A contraction of an edge in a graph glues together adjacent vertices, creating a graph with one less vertex.
This diagram shows the above graph with one edge contracted.

d Given that G is a connected graph, and that G’ is the graph formed by contracting one edge of G, show
that if the relationship
V + R – E = 1 holds for G’, then it must hold for G.
e Using your results from parts c and d, show that the relationship
V + R – E = 1 holds for all connected graphs.

Summary of key points


 1 A graph consists of points (called vertices or nodes) connected by lines (edges or arcs).

 2 If a graph has a number associated with each edge (usually called its weight), then the graph is
known as a weighted graph or network.

 3 A subgraph is a graph, each of whose vertices belongs to the original graph and each of whose
edges belongs to the original graph. It is part of the original graph.

 4 The degree (or valency or order) of a vertex is the number of edges that meet at that vertex.

 5 If the degree of a vertex is even, you say that it has even degree. If the degree of a vertex is
odd it has odd degree.
48 CHAPTER 2 GRAPHS AND NETWORKS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

 6 A walk is a route through a graph along edges from one vertex to the next.

 7 A path is a walk in which no vertex is visited more than once.

 8 A trail is a walk in which no edge is visited more than once.

 9 A cycle is a walk in which the end vertex is the same as the start vertex and no other vertex
is visited more than once.

10 A Hamiltonian cycle is a cycle that includes every vertex.

11 Two vertices are connected if there is a path between them. A graph is connected if all its
vertices are connected.

12 A loop is an edge that starts and finishes at the same vertex.

13 A simple graph is one in which there are no loops and there is at most one edge connecting
any pair of vertices.

14 If the edges of a graph have a direction associated with them they are known as directed
edges and the graph is known as a directed graph (or digraph).

15 In any undirected graph, the sum of the degrees of the vertices is equal to 2 × the number
of edges. As a consequence, the number of odd nodes must be even. This result is called
Euler's handshaking lemma.

16 A tree is a connected graph with no cycles.

17 A spanning tree of a graph is a subgraph which includes all the vertices of the original graph
and is also a tree.

18 A complete graph is a graph in which every vertex is directly connected by a single edge
to each of the other vertices.

19 Isomorphic graphs are graphs which show the same information but may be drawn differently.

20 Each entry in an adjacency matrix describes the number of arcs joining the corresponding
vertices.

21 In a distance matrix, the entries represent the weight of each arc, not the number of arcs.
ALGORITHMS ON GRAPHS CHAPTER 3 49
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

3 ALGORITHMS
ON GRAPHS
Learning objectives

2.1
2.2

Learning objectives
After completing this chapter you should be able to:
● Use Kruskal’s algorithm to find a minimum spanning tree → pages 50–54
● Use Prim’s algorithm on a network to find a minimum
spanning tree  → pages 54–56
● Apply Prim’s algorithm to a distance matrix → pages 57–60
● Apply the nearest neighbour algorithm to find a
short path → pages 60–63
● Use Dijkstra’s algorithm to find the shortest path
between two vertices in a network  → pages 64–71

Prior knowledge check

1 The diagram shows a weighted network.


A
12
B
9 15 7
4
3 11 C
G
F 14
2 5 9 Map apps model roads as
E 16 D arcs on a graph, and add
weightings depending on
a State the order of vertex C. traffic conditions. By finding
b Draw a distance matrix for this network. the shortest path on the
c Find a spanning tree with total weight less than 40. graph, the app can compute
State clearly which arcs are included in your the quickest route to a
spanning tree and its total weight.  ← Decision 1 Chapter 2 destination.
50 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

3.1 Kruskal’s algorithm


You can use Kruskal’s algorithm to find a minimum spanning tree. This can tell you the shortest,
cheapest or fastest way of linking all the nodes in a network.
Notation
An MST is
■ A minimum spanning tree (MST) is a spanning tree such that sometimes called a
the total length of its arcs (edges) is as small as possible. minimum connector.
■ Kruskal’s algorithm can be used to find a minimum spanning tree:

1 Sort all the arcs (edges) into ascending order of weight.


2 Select the arc of least weight to start the tree.
3 Consider the next arc of least weight.
• If it would form a cycle with the arcs already selected, reject it.
• If it does not form a cycle, add it to the tree.
If there is a choice of equal arcs, consider each in turn.
4 Repeat step 3 until all vertices are connected.

Example 1 SKILLS EXECUTIVE FUNCTION

Use Kruskal’s algorithm to find a minimum spanning tree for this network. List the arcs in the
order that you consider them. State the weight of your tree.
D
4 8 In a network of n vertices, a spanning tree will
E 6 C always have (n − 1) arcs. In this case there will be 4
6
5 arcs in the spanning tree.
5
B
7
A

By inspection, the order of the arcs is AE and BC could have been written in either
DE(4), AE(5), BC(5), AD(6), order, as both have weight 5. Likewise, AD and
BD(6), AB(7), CD(8). BD could have been written in either order.
Start with DE.
D
4 8
E C
6 6 Online
Explore
7 Kruskal's algorithm
5
B using GeoGebra.
7
A
Add AE.
D
4 8 You do not need to draw each of these diagrams.
E C The list of arcs, in order, with your decision about
6 6
5 rejecting or adding them, is sufficient to make
5 your method clear.
B
7
A
ALGORITHMS ON GRAPHS CHAPTER 3 51
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Add BC. Watch


out The spanning tree does not
D necessarily remain connected as it grows, but the
4 8 finished spanning tree must be connected.
E C
6 6
5
5
B
7
A
Reject AD (it would make the cycle AEDA).
Add BD.
D
4 8
E C
6 6 All the vertices are now connected so you can stop.
5
5
7 B
A
If you continued to work through the list of arcs,
All vertices are connected so this is a each would be rejected because they would make
minimum spanning tree. cycles.
Its weight is 5 + 4 + 6 + 5 = 20

Example 2 SKILLS ANALYSIS

Use Kruskal’s algorithm and show that there are  A 8 D


four minimum spanning trees for this network.
13
State their weight. 10 10
12 F
C
12 11
8
E
B 14

By inspection, the order of the arcs is Remember that you can choose AD and BC in
AD(8), BC(8), AC(10), CD(10), EF(11), CE(12), either order, AC and CD in either order, and CE
DE(12), DF(13), BE(14). and DE in either order.
Start with AD. 8 D
A
C You may find it helpful to draw out the tree as
you go. It makes it easier to check for cycles.
F

B E
Add BC. 8
A D Watch out
You need to consider all the arcs in
C
turn, even when they have equal weight. If you
8 F start with AD then you have to consider BC next.

B E
52 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Add AC. 8
A D
10 C

8 F

B E

Reject CD (it forms a cycle ACDA).


Add EF. 8
A D Remember, the spanning tree does not
10 C necessarily remain connected as it grows, but the
8 F finished spanning tree must be connected.
11
B E

8 D
Add CE. A
10 C

8 F
12 11
B E
One solution is:
8 D
A The minimum spanning tree that you create
10 C will depend on how you choose the arcs. Each
8 F one is a solution because they will all have the
12 11 least weight.
B E (using AC and CE)
The other three solutions are:
8 D
A
10 C
12
8 F
11
B E (using AC and DE)
8 D
A
C 10
8 F
12 11
B E (using CD and CE)
A 8 D
C 10 12
8 F
11
B E (using CD and DE)
The weight of each tree is All four solutions are minimum spanning trees,
8 + 8 + 10 + 11 + 12 = 49 so they will all have the same total weight.
ALGORITHMS ON GRAPHS CHAPTER 3 53
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 3A SKILLS PROBLEM-SOLVING

1 Use Kruskal’s algorithm to find minimum spanning trees for each of these networks.
State the weight of each tree. You must list the arcs in the order in which you consider them.
a A 25 B b A 7 C
4 B 7
14 16 C 18 6
17 12
5 4 2 5 D
H 20 12 D E
21 7
15
11 3 F 8
18
G 6 E
G 24 F

c A 3.8 B
C
4.2 2.1
4.1
4.3 D
2.2 E
H 1.4
4.1 3.8 1.7 2.1
2.3

J 3.1 G 3.2 F

E/P 2 a State what is meant by:


i a tree  (1 mark)
ii a minimum spanning tree.  (1 mark)
b Use Kruskal’s algorithm to find a minimum spanning tree for this network.  (3 marks)
X
S 18 17
18
U 18 Y
22 17
20
W 15
19
T 16 18
23 V Z

c Draw the minimum spanning tree found in part b.  (1 mark)


d State, giving a reason, whether or not this minimum spanning tree is unique.  (1 mark)

P 3 Draw a network in which:


a the three shortest edges form part of the minimum connector (MST)
b not all of the three shortest edges form part of the minimum connector.
54 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E 4 The diagram shows nine villages and the distances between them in kilometres.
A cable TV company plans to link up the villages.
Claver
0.8 1.4
Morris Salis 2.8 Cedars
1.7 1.9
2.3 1.6 Haversham
3.3 2.9
2.8 2.8 2.1
Ritchie
1.1
Plumptree 3.1 Edwards Shrewsbury

a Find a minimum spanning tree for the network using Kruskal’s algorithm. List the arcs
in the order that they were added to the tree.  (4 marks)
b Use your answer to part a to find the minimum length of cable required to link all the
villages together.  (1 mark)

3.2 Prim’s algorithm


■ Prim’s algorithm can be used to find a minimum spanning tree:
Notation
Prim’s algorithm
1 Choose any vertex to start the tree.
considers vertices, whereas
2 • Select an arc of least weight that joins a vertex already Kruskal’s algorithm considers
in the tree to a vertex not yet in the tree. edges. Because we are
• If there is a choice of arcs of equal weight, choose any considering adding an arc from
of them. an unconnected vertex to the
3 Repeat step 2 until all the vertices are connected. graph, a cycle will never be
formed and so we don’t need
4 List the arcs in the order that they were added.
to check for cycles.

Example 3 SKILLS ANALYSIS

B 15
F Online
Explore Prim's algorithm using
10 9 GeoGebra.
8
12 A
C 12
Watch
out In your exam, you may be asked to
9 11
8 use Prim’s or Kruskal’s algorithm. You must know
E which is which.
D 14

Use Prim’s algorithm to find a minimum spanning tree for the network above.
List the arcs in the order in which you add them to your tree.
ALGORITHMS ON GRAPHS CHAPTER 3 55
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Choose to start the tree at A.


Add the arc of least weight, AF, to the tree.
B F
8 The arcs to consider are those linking A to another
vertex: AF(8), AB(9), AD(9), AE(11) and AC(12).
A
C Add the one of least weight, AF, to the tree.

E
D Now consider arcs that link either A or F to a
Add AD to the tree. vertex not in the tree: AB(9), AD(9), AE(11),
B AC(12), FE(12) and FB(15).
F
8
A
C Add the arc of least weight, from A or F, that
introduces a new vertex to the tree. In this case
9 there are two arcs of least weight, AD and AB.
E You can choose either. In this case, AD is chosen.
D
Add DC to the tree.
B F
8 The arcs linking A, F and D to the remaining
A vertices are AB(9), AE(11), AC(12), FE(12), FB(15),
C
DC(8), DE(14). The one of least weight is DC.
8 9
E
D

Add AB to the tree.


B F
9 8 The arcs linking A, F, D and C to the remaining
A vertices are AB(9), AE(11), FE(12), FB(15),
C DE(14), CB(10). The one of least weight is AB.
8 9
E
D
Add AE to the tree.
B F The arcs linking A, F, D, C and B to the remaining
9 8
vertex, E, are AE(11), FE(12), DE(14). The one of
A least weight is AE.
C
11
8 9
E
D Hint
Notice that with Prim’s algorithm the tree
Arcs added in this order: AF, AD, DC, AB, AE. always grows in a connected fashion. The arcs
do not jump around as they sometimes do with
Kruskal’s algorithm.
56 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 3B SKILLS PROBLEM-SOLVING

1 Repeat Question 1 in Exercise 3A using Prim’s algorithm. Start at vertex A each time.

2 Describe two differences between Prim’s algorithm and Kruskal’s algorithm.

3 The network shows the distances,  H


E 5.2 C
3.1
in kilometres, between eight weather D
1.8 3.7
monitoring stations. The eight stations 2.5 2.4
A 3.5
need to be linked together with 4.6 E
underground cables. 2.3 B
G 3.4 2.8
a Use Prim’s algorithm, starting at A, 8.7
to find a minimum spanning tree. F
You must make your order of arc selection clear.  (3 marks)
b Given that cable costs £850 per kilometre to lay, find the minimum cost
of linking these weather stations.  (1 mark)

E/P 4 Q 38 T 27 W

27 35 15 41
18 29
31 S 33 V
P 19 Y
29
33 24 34 28 48

R 37 U 29 X

The network shows ten villages and the costs, in thousands of dollars, of connecting them with
a new energy supply.
a Use Prim’s algorithm, starting at P, to find the energy supply network
that would connect all ten villages for minimum cost.  (3 marks)
b Draw your minimum connector and state its cost.  (2 marks)
c Unforeseen problems with the link between villages W and X mean that the cost of connecting
them rises to $34 000. Explain how this affects your minimum spanning tree.  (2 marks)

E/P 5 a Explain why it is not necessary to check for cycles when using Prim’s algorithm.  (1 mark)
B
SKILLS 21
D J
4 24
REASONING/
ARGUMENTATION 8 F 17
A 10 10 9
8
8
12 9 K
8 I
C
19
7
11 G
E 16
8 L
6
H
b Use Prim’s algorithm, starting at A, to find a minimum spanning tree for this network.
You must make your order of arc selection clear.  (3 marks)
c State, with a reason, whether this minimum spanning tree is unique.  (2 marks)
ALGORITHMS ON GRAPHS CHAPTER 3 57
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

3.3 Applying Prim’s algorithm to a distance matrix


Networks (especially large ones) are often described using distance matrices. This is a convenient
way to input a large network into a computer. You can apply Prim’s algorithm directly to a distance
matrix, which makes it more convenient for computer applications.
■ The distance matrix form of Prim’s algorithm is:

1 Choose any vertex to start the tree.


2 Delete the row in the matrix for the chosen vertex.
3 Number the column in the matrix for the chosen vertex.
4 Circle the lowest undeleted entry in the numbered columns. (If
there is an equal choice, choose randomly.)
5 The circled entry becomes the next arc to be added to the tree.
6 Repeat steps 2, 3, 4 and 5 until all rows have been deleted.
7 List the arcs in the order that they were added.

Example 4 SKILLS ANALYSIS

Apply Prim’s algorithm to the distance matrix A B C D E


to find a minimum spanning tree. Start at A.
A – 27 12 23 74
B 27 – 47 15 71
C 12 47 – 28 87
D 23 15 28 – 75
E 74 71 87 75 –

1

A B C D E
A – 27 12 23 74 Delete row A, and number column A.
B 27 – 47 15 71
C 12 47 – 28 87
D 23 15 28 – 75
E 74 71 87 75 –

1

A B C D E
A – 27 12 23 74
B 27 – 47 15 71 The lowest undeleted entry in column A is 12,
C 12 47 – 28 87 so circle it. The first arc is AC.
D 23 15 28 – 75
E 74 71 87 75 –
The first arc is AC.
58 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

1 2
↓ ↓
A B C D E The new vertex is C. Delete row C, and number
A – 27 12 23 74 column C.
B 27 – 47 15 71
C 12 47 – 28 87 The lowest undeleted entry in columns A and C
D 23 15 28 – 75 is 23, circle it. The second arc is AD.
E 74 71 87 75 –
The second arc is AD.
1 2 3
↓ ↓ ↓ The new vertex is D. Delete row D, and number
A B C D E column D.
A – 27 12 23 74
B 27 – 47 15 71 The lowest undeleted entry in columns A, C and
C 12 47 – 28 87 D is 15. Circle it. The third arc is DB.
D 23 15 28 – 75
E 74 71 87 75 –
The third arc is DB.
1 4 2 3
↓ ↓ ↓ ↓
A B C D E
A – 27 12 23 74
The new vertex is B. Delete row B, and number
B 27 – 47 15 71
column B.
C 12 47 – 28 87
D 23 15 28 – 75 The lowest undeleted entry in columns A, C, D and
E 74 71 87 75 – B is 71. Circle it. The fourth arc is BE.
The fourth arc is BE.
1 4 2 3 5
↓ ↓ ↓ ↓ ↓
A B C D E
A – 27 12 23 74
B 27 – 47 15 71
C 12 47 – 28 87
D 23 15 28 – 75
The new vertex is E. Delete row E and number
E 74 71 87 75 –
column E.
The minimum spanning tree is:
A B All rows have now been deleted, so the algorithm
23 15
12 71 is complete.
D
C
E Watch
out You do not need to show all of these
Its weight is 12 + 23 + 15 + 71 = 121 tables. The final annotated table, plus a list of arcs
The arcs added were AC, AD, BD, BE. in order, is sufficient to make your method clear.
ALGORITHMS ON GRAPHS CHAPTER 3 59
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 3C SKILLS EXECUTIVE FUNCTION

1 Apply Prim’s algorithm to the distance matrices below. List the arcs in order of selection
and state the weight of your minimum spanning tree.
a A B C D E F b R S T U V
A – 15 20 34 25 9 R – 28 30 31 41
B 15 – 36 38 28 14 S 28 – 16 19 43
C 20 36 – 43 38 22 T 30 16 – 22 41
D 34 38 43 – 26 40 U 31 19 22 – 37
E 25 28 38 26 – 31 V 41 43 41 37 –
F 9 14 22 40 31 –

2 The table shows the distance, in kilometres, between five cities. It is desired to link these
five cities by a transit system.

Birmingham Nottingham Lincoln Stoke Manchester


Birmingham – 262.4 160 78.4 140.8
Nottingham 262.4 – 59.2 89.6 118.4
Lincoln 160 59.2 – 144 137.6
Stoke 78.4 89.6 144 – 70.4
Manchester 140.8 118.4 137.6 70.4 –
Use Prim’s algorithm, starting at Birmingham, to find the minimum total length of a
transit system linking all five cities. You must list the arcs in order of selection and state
the weight of your tree.

E/P 3 The matrix shows the costs, in euros per 1000 words, of translating appliance
instruction manuals between eight languages.
A B C D E F G H
A – 84 53 35 – 47 – 42
B 84 – 71 113 142 61 75 –
C 53 71 – – – – 59 –
D 35 113 – – 58 67 151 –
E – 142 – 58 – 168 159 48
F 47 61 – 67 168 – – 73
G – 75 59 151 159 – – 52
H 42 – – – 48 73 52 –
a Use Prim’s algorithm, starting from language D, to find the cost of translating
an instruction manual of 3000 words from D into the seven other languages.  (4 marks)
60 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

b Draw your minimum spanning tree.  (1 mark)


A manual is written in language E and needs to be translated into language G.
The table shows that it costs 159 euros per 1000 words to translate from language E to G.
c Give a reason why:
i it might be decided not to translate directly from E to G
ii it might be decided to translate directly.  (2 marks)

E/P 4 The table shows the distances, in kilometres, between nine oil rigs and the depot X.
Pipes are to be laid to connect the rigs and the depot.
X A B C D E F G H I
X – 65 80 89 74 26 71 41 41 74
A 65 – 27 41 22 37 20 29 25 43
B 80 27 – 30 24 55 16 46 40 42
C 89 41 30 – 50 84 24 70 49 26
D 74 22 24 50 – 51 35 34 47 63
E 26 37 55 84 51 – 52 18 23 68
F 71 20 16 24 35 52 – 45 31 27
G 41 29 46 70 34 18 45 – 25 64
H 41 25 40 49 47 23 31 25 – 44
I 74 43 42 26 63 68 27 64 44 –
a Use Prim’s algorithm, starting at X, to find a minimum spanning tree for
the network. You must make the order of arc selection clear.  (3 marks)
b X must now be directly connected to D and to F. Based on this condition,
use Prim’s algorithm, starting at A, to find a minimum spanning tree.
You must make the order of arc selection clear. (2 marks)
c The oil company now requires that the depot must be directly connected to oil rig D.
Find a minimum spanning tree that must meet this condition. (3 marks)

3.4 The nearest neighbour algorithm


The nearest neighbour algorithm can be used to find a short path connecting all vertices. You will
see this again when we investigate the travelling salesman problem. The algorithm works only if
we use a least distance matrix between each node. This will be expanded further in Chapter 5.

1 Choose any vertex to start the path.


Watch
out Do not confuse the
2 Select an arc of least weight which joins a new vertex
nearest neighbour algorithm with
to the last vertex added only.
Prim’s algorithm. In Prim’s algorithm
3 Repeat step 2 until all of the vertices are added you look for the vertex nearest any of
the vertices in your growing tree.
The path may not be optimal, but is a key part in the In the nearest neighbour algorithm,
travelling salesman problem. you look for the vertex nearest to the
In Example 4, we saw Prim’s algorithm applied to a last vertex chosen.
distance matrix. Let us now see the nearest neighbour
algorithm applied.
ALGORITHMS ON GRAPHS CHAPTER 3 61
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Example 5 SKILLS ANALYSIS

Apply the nearest neighbour algorithm to the distance A B C D E


matrix to find a short path connecting all vertices.
A – 27 12 23 74
Start at A.
B 27 – 47 15 71
C 12 47 – 28 87
D 23 15 28 – 75
7 74 71 87 75 –

1

A B C D E
A – 27 12 23 74 Delete row A, and number column A.
B 27 – 47 15 71
C 12 47 – 28 87
D 23 15 28 – 75
E 74 71 87 75 –

1

A B C D E
A – 27 12 23 74
B 27 – 47 15 71 The lowest undeleted entry in column A only is 12,
C 12 47 – 28 87 so circle it. The first arc is AC.
D 23 15 28 – 75
E 74 71 87 75 –

1 2

A B C D E
A – 27 12 23 74
B 27 – 47 15 71
The new vertex is C. Delete row C, and number
C 12 47 – 28 87
column C.
D 23 15 28 – 75
E 74 71 87 75 –

1 2

A B C D E
A – 27 12 23 74
B 27 – 47 15 71
C 12 47 – 28 87
The lowest undeleted entry in column C only is
D 23 15 28 – 75 28, so circle it. The second arc is CD.
E 74 71 87 75 –
62 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

1 2 3

A B C D E
A – 27 12 23 74
B 27 – 47 15 71
C 12 47 – 28 87
The new vertex is D. Delete row D, and number
D 23 15 28 – 75
column D.
E 74 71 87 75 –
1 2 3

A B C D E
A – 27 12 23 74
B 27 – 47 15 71 The lowest undeleted entry in column D is 15, so
circle it. The third arc is DB.
C 12 47 – 28 87
D 23 15 28 – 75
E 74 71 87 75 –
1 4 2 3

A B C D E
A – 27 12 23 74
15 The new vertex is B. Delete row B, and number
B 27 – 47 71
column B.
C 12 47 – 28 87
D 23 15 28 – 75
E 74 71 87 75 –
1 4 2 3

A B C D E
A – 27 12 23 74
B 27 – 47 15 71
C 12 47 – 28 87
D 23 15 28 – 75 The lowest undeleted entry in column B only is 71,
E 74 71 87 75 – so circle it. The fourth arc is BE.
1 4 2 3 5

A B C D E
A – 27 12 23 74
The new vertex is E. Delete row E and number
B 27 – 47 15 71
column E.
C 12 47 – 28 87
D 23 15 28 – 75 All rows have now been deleted, so the algorithm
E 74 71 87 75 – is complete.

The path created is: A C D B E


● ● ● ● ●
12 28 15 71
Its weight is 12 + 28 + 15 + 71 = 126
ALGORITHMS ON GRAPHS CHAPTER 3 63
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 3D SKILLS PROBLEM-SOLVING

1 Apply the nearest neighbour algorithm to find a short path connecting all vertices for
the following matrices:
a Start at A b Start at S
A B C D E F R S T U V
A – 15 20 34 25 9 R – 28 30 31 41
B 15 – 36 38 28 14 S 28 – 16 19 43
C 20 36 – 43 38 22 T 30 16 – 22 41
D 34 38 43 – 26 40 U 31 19 22 – 37
E 25 28 38 26 – 31 V 41 43 41 37 –
F 9 14 22 40 31 –

2 After applying the nearest neighbour algorithm, adding an arc back to the start vertex will create
a route. By applying the nearest neighbour algorithm, starting at each vertex in turn,
find a shortest route and state its length.
A B C D E F
A – 20 30 32 12 15
B 20 – 10 25 32 16
C 30 10 – 15 35 19
D 32 25 15 – 20 34
E 12 32 35 20 – 16
F 15 16 19 34 16 –

3 By applying the nearest neighbour algorithm, starting at each vertex in turn, find a shortest
route and state its length.
A B C D E
A – 153 98 124 115
B 153 – 74 131 149
C 98 74 – 82 103
D 124 131 82 – 134
E 115 149 103 134 –
64 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

3.5 Using Dijkstra’s algorithm to find the shortest path


You can use Dijkstra’s algorithm to find the shortest path between a start vertex and any other in
a network. This could be useful for finding the cheapest, shortest or quickest transportation route
between two locations.
Notation
Dijkstra is
■ Dijkstra’s algorithm can be used to find the shortest path pronounced ‘Dike-Stra’.
from S to T through a network:

1 Label the start vertex, S, with the final label, 0. The algorithm makes
use of labels. Start
2 Record a working value at every vertex, Y, that is directly
at the initial vertex
connected to the vertex, that has just received its final label, X.
and move through
• Working value at Y = final label at X + weight of arc XY the network, putting
• If there is already a working value at Y, it is only replaced if working values on
the new value is smaller. each vertex.
• Once a vertex has a final label, it is not revisited and its Each pass finds the
working values are no longer considered. shortest route to one of
the vertices and records
3 Look at the working values at all vertices without final labels.
its final label (also
Select the smallest working value. This now becomes the final
called its permanent
label at that vertex. (If two vertices have the same smallest label). Once a vertex
working value, either may be given its final label first.) has its final label it is
4 Repeat steps 2 and 3 until the destination vertex, T, receives its ‘fixed’ and its working
final label. values are no longer
5 To find the shortest path, trace back from T to S. If B already considered. Continue
in this way until the
lies on the route, include arc AB whenever:
destination vertex
final label of B − final label of A = weight of arc AB
is reached.

Online
Explore Dijkstra's
algorithm using GeoGebra.

Example 6 SKILLS INTERPRETATION

Use Dijkstra’s algorithm to find the shortest route from S to T in the network below.
A
4 Notation
To make the working clear, you
5 D
4 3 replace the vertices with boxes like this:
6 B 8
S T Vertex Order of labelling Final label
2 Working values
2 12

C
ALGORITHMS ON GRAPHS CHAPTER 3 65
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

The network becomes:


A
4
5 D Give vertex S a final label of 0.
4 Indicate that this is the first vertex to
S 1 0 6 B 3 receive its final label by completing
8 the top boxes at S like this:
T S 1 0
2 2

C 12

Give working values to A, B and C


A since they are directly connected to S.
5 4
5 D
4
S 1 0 6 B 3
6 8
T
2 2

C 12
2

A
5 4
5 D
4
S 1 0 6 B 3
6 8
T Look at the working values at A, B
2 2
and C. The smallest is 2 (at C). This
C 2 2 12 will become the next final label. C is
2 now completed. It is the 2nd vertex
to be completed.
A
5 4
5 D Add working values to each vertex
that is directly connected to C.
4
S 1 0 6 B Note that the algorithm has picked
3
up the shortcut to B. S → B has
6 4 8
weight 6, but S → C → B has total
T
2 2 weight 4.
14
C 2 2 12
2
66 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

A
5 4
5 D The smallest working value is 4 at B.
4 8 This becomes the final label at B.
S 1 0 6 B 3 4 3 B becomes the 3rd completed vertex.
6 4 8 Add working values to D and T
T because these are directly connected
2 2 to B.
14 12
C 2 2 12
2
The smallest working value is 5 at
A 4 5 A. A becomes the 4th vertex to be
5 4 completed. It has a final value of 5.
5 D
4 8 The only working value to add would
S 1 0 6 B 3 4 3 be a 9 at D. However this is larger
6 4 8 than the 8 already there, so it does
T
not need to be recorded.
2 2
14 12
C 2 2 12
2

A 4 5 The smallest working value is 8 at D.


5 4 This becomes D’s final label.
5 D 5 8 D becomes the 5th vertex to be
4 8 completed. The only working value to
S 1 0 6 B 3 4 3 add is the 11 at T.
6 4 8
T
2 2
14 12 11
C 2 2 12
2

A 4 5
5 4
5 D 5 8 The final diagram looks like this.
4 8
S 1 0 6 B 3 4 3 Hint
You do not need to draw lots
6 4 8
of diagrams to show your working.
T 6 11 Working through just one diagram
2 2
14 12 11 and completing all the boxes will
C 2 2 12 make the method clear.
2  → Example 7
ALGORITHMS ON GRAPHS CHAPTER 3 67
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

The length of the shortest route from S to T is 11.


To find the shortest route, start at T and trace back
looking at final values and arc lengths.
Check the arcs into T.
11 − 2 ≠ 12 so CT is not on the route.
11 − 4 ≠ 8 so BT is not on the route.
11 − 8 = 3 so DT is on the route.
To get to T in 11 you must have come from D.
Continue working back from D.
Watch
out Unless you are asked
The working is:
to explain how you obtained your
11 − 8 = 3 DT
final route, you do not need to
8 − 4 = 4 BD
show all of this working. You can
4 − 2 = 2 CB
identify the shortest route from
2 − 0 = 2 SC your fully labelled diagram by
So the shortest route is SCBDT, length 11 inspection.

■ You can use Dijkstra’s algorithm to find the shortest route between the start vertex and any
other vertex with a final label.

Example 7 SKILLS PROBLEM-SOLVING

Use Dijkstra’s algorithm in this network to  B 15 E


find the length of the shortest route:
8 7 8
a from A to H 6
18 D 9 8
b from A to G. A H
G
List the routes you use. 6
8 8 9

C 12 F

a The final diagram looks like this. It shows all


the working needed to make the method clear. The lowest working values
at B and at C are both 8, so
B 3 8 15 E 6 21 either can be chosen first.
8 23 21
8 7 6 8

A 1 0 18 D 4 15 9 G 7 24 8 H 8 29
18 16 15 24 29

8 8 6
9
C 2 8 F 5 20 Check that your method
8 12 20 can be followed clearly.
68 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

The length of the shortest route from A to H is 29.


There are two shortest routes: either 29 − 21 =   8 EH
21 − 15 =   6 DE
ABDEH and ACFH.
15 −   8 =   7 BD
b From the diagram, the length of the shortest route from
 8 −   0 =   8 AB
A to G is 24.
Problem-solving or 29 − 20 =   9 FH
The route is ABDG.
20 −   8 = 12 CF
G already has a final value, so you do
 8 −   0 =   8 AC
not need to implement the algorithm
again. Just work backwards from G to A.

■ It is possible to use Dijkstra’s algorithm on networks with directed arcs. This is like trying to find
a driving route where some of the roads are one-way streets.

Example 8 SKILLS REASONING/ARGUMENTATION

The network below represents part of a road system in a city. Some roads are one-way and these
are indicated by directed arcs. The number on each arc represents the time, in minutes, to travel
along that arc.
a Show that there are two quickest routes B 4 D 11 G
from A to I. Explain how you found
9 2
your routes from your labelled diagram. 2 3 1
C F 5
Road HI is closed due to roadworks. 5 1 H
2 7 2
b Find the quickest route from A to I, 5 8
avoiding HI.
A 5 E 14 I

a The final diagram looks like this:


Check that your method can be
B 3 4 4 D 4 5 11 G 7 15 understood from the diagram.
5 4 5 16 15
3 9 1 2
2
C 2 2 F 6 14 5 H 8 17
5 1
2 14 19 17
2 8 2
5 7
A 1 0 E 5 6 I 9 19
5 7 6 14 20 19

Hint
Examiners check the order in which the Problem-solving
numbers appear in the list of working values. Notice that 5 does not appear as a working value
It is important to put them in the order given for vertex E since it is not possible to travel
by the algorithm. directly from A to E.
ALGORITHMS ON GRAPHS CHAPTER 3 69
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

The two quickest routes are


A C D F G H I and ACDEFGHI Watch out In this question you

since since are told to explain how you found
19 − 17 = 2 HI 19 − 17 = 2 HI the route from your diagram, so you
17 − 15 = 2 GH 17 − 15 = 2 GH need to show these calculations.
15 − 14 = 1 FG 15 − 14 = 1 FG
14 − 5 = 9 DF 14 − 6 = 8 EF
5 − 2 = 3 CD 6 − 5 = 1 DE
2 − 0 = 2 AC 5 − 2 = 3 CD
2 − 0 = 2 AC
Both are of length 19 minutes.
b Removing HI from the network would leave a final value of 20 at I.
Start at I and find the route of length 20.
20 − 6 = 14 EI
6 − 5 = 1 DE
5 − 2 = 3 CD
2 − 0 = 2 AC
So the quickest route from A to I, avoiding HI, is ACDEI, of length 20 minutes.

Exercise 3E SKILLS EXECUTIVE FUNCTION

1 Use Dijkstra’s algorithm to find the shortest route from S to T in each of the following networks.
In each case, explain how you determined the shortest path from your fully labelled diagram.
a C 3 F   b A 2 C 10 T
10
A
1 2 6 4 8
5 4 5 2
7 5
6 G 8 D 2 F 2
16 T S 1 H
D
S 2 4
6 1 3 6
8 10 9 5
6
E 4 H B 3 E 5 G
3
B

A B C
P 2 The network shows part of a road system in  17 5
a city. The number on each arc gives the time, 24 20 17 14
16 8 16
in minutes, it takes to travel along that arc. F
8 E 6 4 G 9
Use Dijkstra’s algorithm to find: D H
a the quickest route from A to Q 9
3
17
18
8 14 8 5 3
and its length 8 J 11 K 15 L 2
I M
b the quickest route from A to L
and its length 13 27
22 16 22 29
4
c the quickest route from M to A and its length
d the quickest route from P to A and its length. N 3 P 13 Q
70 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

3 Use Dijkstra’s algorithm to find the        A


6 B
12
shortest route, and its length, from 18 9 C
A to F in this directed network. 10
14 2
E 27
D 13
16
F
22
8
G

E/P 4 The network represents the lengths, in B

SKILLS
metres, of all the roads in a building site.
331 275
CREATIVITY
A bulldozer is needed for one day at T. E 291
379 G
There are two bulldozers available on-site, C
S1
one at S1, and the other at S2. 890 438
207 118
One of the two bulldozers will be moved to T. 784
T
In order to minimise the cost it is decided
852
to move the bulldozer that is closest to T. S2 642 F
219
Use Dijkstra’s algorithm to determine which 293 D
309
bulldozer should be moved. A
 (7 marks)
Problem-solving
It is possible to solve this problem with only one
application of Dijkstra’s algorithm. Think carefully
about the starting point.

E/P 5 a Use Dijkstra’s algorithm to find the shortest  D 37 G


route from A to H. Indicate how you 29
A 22
obtained your shortest route from your 55 25 19
F 30
labelled diagram. (6 marks) C 48
30 38
b Find the shortest route from 22
24 26 H
A to H via G. (2 marks)
B 18
c Find the shortest route from 51
E
A to H, not using CE. (2 marks)

E 6 Use Dijkstra’s algorithm to find the shortest  A


route from S to T in this directed network.
State the length of your route. (6 marks) 7 2 6
B
3
4 C 3
T
S 9
1
4
7

D
ALGORITHMS ON GRAPHS CHAPTER 3 71
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E/P 7 A navigation app uses real-time data to determine A F


driving times between different locations. 13 3
8 D 13
The diagram shows a network of driving times, 3 2
7 5
in minutes, along roads joining ten locations. 12 9
S T
a Use Dijkstra’s algorithm to find the B 1 G
quickest route from S to T, and state 14 5
13 E 5
the total driving time for this route. 11 2
(6 marks) C H
A driver is following this quickest route. Due to traffic congestion,
the travel time between H and T increases from 5 minutes to 13 minutes.
b State how this will affect the quickest route if this information is discovered:
i before the start of the journey
ii when the driver reaches point H.  (4 marks)

Chapter review 3 SKILLS PROBLEM-SOLVING

E  1 The network represents a theme park  Kiddizone 800 Scaryzone


with seven zones. The number on each
362 234 444
arc shows a distance in metres. 300 694
340 378 538
Tramways are to be built to link the Entrance Coolzone Quickzone
Highzone
seven zones and the entrance.
423
945 740
a Find a minimum spanning tree using:
i Kruskal’s algorithm (4 marks) Wetzone
836
Darkzone
ii Prim’s algorithm, starting at the
entrance.  (4 marks)
You must make your order of arc selection clear.
b Draw your tree and state its weight.  (2 marks)

E/P  2 The network represents eight observation  L 8.7 M 5.3


N
points in a wildlife reserve and the possible
paths connecting them. The number on 3.8 T 4.1 3.7 6.8
4.7
each arc is the distance, in kilometres, 6.6
9.2
along that path. It is decided to link the Q
9.5 6.6 P
observation points by paths but, in order to S
minimise the impact on the wildlife reserve, 8.4 7.5
the least total length of path is to be used. R
a Find a minimum spanning tree for the network using:
i Prim’s algorithm, starting at L (4 marks)
ii Kruskal’s algorithm. (4 marks)
In each case, list the arcs in the order in which you consider them.
72 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

b Given that paths TQ and RP already exist, and so must form part of the tree, state which
algorithm, Prim’s or Kruskal’s, you would select to complete the spanning tree.
Give a reason for your answer. (2 marks)

E/P  3 The table shows the distances, in mm,  A B C D E F


between six nodes A to F in a network. A – 124 52 87 58 97
a Use Prim’s algorithm, starting at A, B 124 – 114 111 115 84
to find a minimum spanning tree for C 52 114 – 67 103 98
this table of distances. D 87 111 67 – 41 117
You must explain your method E 58 115 103 41 – 121
carefully and indicate clearly the F 97 84 98 117 121 –
order in which you selected the arcs.  (3 marks)
b Draw a sketch showing the minimum spanning tree and find its length.  (2 marks)

E  4 It is intended to network five computers at a large race track. There is one computer at
the office and one at each of the four different entrances. Cables need to be laid to link the
computers. Cable laying is expensive, so a minimum total length of cable is required.
The table shows the shortest distances, in metres, between the various sites.
Office Entrance 1 Entrance 2 Entrance 3 Entrance 4
Office – 1514 488 980 945
Entrance 1 1514 – 1724 2446 2125
Entrance 2 488 1724 – 884 587
Entrance 3 980 2446 884 – 523
Entrance 4 945 2125 587 523 –
a Starting at Entrance 2, demonstrate the use of Prim’s algorithm and hence find a minimum
spanning tree. You must make your method clear, indicating the order in which you selected
the arcs in your final tree. (4 marks)
b Calculate the minimum total length of cable required. (2 marks)

E/P  5 A
29 B 19 C
9
30 27 26
E 8 F 17 D
H 18
22 24 12 20
14 14
26 G
J I
K

The diagram above shows a weighted network. The weights of each arc are given in the
following table:

AB AE AH BC CD CF CG DG EF EJ EK FI FJ GI HK JK
29 27 30 19 9 26 17 18 8 12 24 20 14 14 22 26
a Use a quick sort to write these arcs in order of weight, smallest first.  (4 marks)
ALGORITHMS ON GRAPHS CHAPTER 3 73
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

b Use Kruskal’s algorithm to find a minimum spanning tree for this network.  (3 marks)
c Draw your minimum spanning tree and state its total weight.  (2 marks)
For any connected network,
e = number of edges in the minimum spanning tree
v = number of vertices in the network.
d Write down the relationship between e and v.  (2 marks)

E/P  6 A company is to install power lines  C 3 F 7 H

SKILLS
to buildings on a large industrial 7
CREATIVITY
estate. The lines are to be laid 1 L
2 3 3
by the side of the roads on the 5 4
estate. The estate is shown here 2 5 6
A N
as a network. The buildings are D G I 6
designated A, B, C, ..., N and the 6
5
4 4 4
distances between them are given M
in hundreds of metres. The manager 3
wants to minimise the total length of B 5 E 7 J 3 K
power line to be used.
a Use Kruskal’s algorithm to obtain a minimum spanning tree for the network
and hence determine the minimum length of power line needed.  (4 marks)
Owing to a change of circumstances, the company modifies its plans for the estate.
The result is that the road from F to G now has a length of 700 metres.
b Determine the new minimum total length of power line.  (3 marks)

 7 A weighted network is shown. The number  B 25 C


on each arc indicates the weight of that arc. 8
D 12
a Use Dijkstra’s algorithm to find a path of 7 14 9
E 24
least weight from A to K. 5
K
State clearly: A 8 10
9 9
i the order in which the vertices were F 10
labelled 10 G 11
5 I
ii how you determined the path of least
8 17
weight from your labelling.
H J
b List all alternative paths of least weight.
c Describe a practical problem that could be modelled by the network and solved using
Dijkstra’s algorithm.
74 CHAPTER 3 ALGORITHMS ON GRAPHS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

E  8 The network here shows the distances,  A


105
in kilometres, between nine cities. D
149
157 F
Use Dijkstra’s algorithm to determine 79 101
195
the shortest route, and its length, 134 T
S 123
between cities S and T. You must B 122
83
indicate clearly the order in which G
the vertices are labelled and how you 102 117
E
used your labelled diagram to decide 85
C
which cities to include in the shortest route.  (5 marks)

P  9 a Find a minimum spanning tree for this network using:  B


i Prim’s algorithm 17
SKILLS
ii Kruskal’s algorithm. 20
REASONING/ 26 C
ARGUMENTATION b Compare the application of the two algorithms in
A
this case. State which is easier. 15 22
18
c Describe a condition under which Prim’s algorithm 23 25
19
may be quicker to apply than Kruskal’s algorithm.

E 21 D

10 The table below shows the flight distances, in kilometres, between eight cities: Alice Springs (A),
Brisbane (B), Cairns (C), Darwin (D), Eden (E), Freemantle (F), Gladstone (G) and Hobart (H).
Both Prim’s algorithm and the nearest neighbour algorithm connect all of the cities together.
A B C D E F G H
A – 1970 1450 1290 2130 2010 1770 2470
B 1970 – 1390 2850 1110 3620  440 1790
C 1450 1390 – 1680 2280 3460  960 2890
D 1290 2850 1680 – 3330 2670 2500 3740
E 2130 1110 2280 3330 – 3160 1480  680
F 2010 3620 3460 2670 3160 – 3590 3020
G 1770  440  960 2500 1480 3590 – 2150
H 2470 1790 2890 3740  680 3020 2150 –
a Starting at A, use Prim’s algorithm to find a minimum spanning tree and state the weight of
the minimum spanning tree.
b Starting at C, use the nearest neighbour algorithm to find a short path and state its weight.
A news reporter wishes to visit all eight cities, starting from C. One way of visiting all eight
cities is to create a minimum spanning tree, then starting at C, traverse each arc twice. Another
way of visiting all eight cities is to use the nearest neighbour algorithm and, once completed, to
return directly to C.
c Using your answers to part a and b which method would give the shortest way of visiting all
eight cities.
ALGORITHMS ON GRAPHS CHAPTER 3 75
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Summary of key points


1 A minimum spanning tree (MST) is a spanning tree such that the total length of its arcs
(edges) is as small as possible.
2 Kruskal’s algorithm can be used to find a minimum spanning tree.
• Sort the arcs into ascending order of weight and use the arc of least weight to start the tree.
Then add arcs in order of ascending weight, unless an arc would form a cycle, in which case
reject it.
3 Prim’s algorithm can be used to find a minimum spanning tree.
• Choose any vertex to start the tree. Then select an arc of least weight that joins a vertex
already in the tree to a vertex not yet in the tree. Repeat this until all vertices are connected.
4 Prim’s algorithm can be applied to a distance matrix.
• Choose any vertex to start the tree. Delete the row in the matrix for the chosen vertex and
number the column in the matrix for the chosen vertex. Circle the lowest undeleted entry in
the numbered columns, which becomes the next arc. Repeat this until all rows are deleted.
5 Dijkstra’s algorithm can be used to find the shortest path between two vertices in a network.
• Label the start vertex with final value 0.
• Record a working value at every vertex, Y, that is directly connected to the vertex that has
just received its final label, X:
final label at X + weight of arc XY
• Select the smallest working value. This is the final label for that vertex.
• Repeat until the destination vertex receives its final label.
• Find the shortest path by tracing back from destination to start. Include an arc AB on the
route if B is already on the route and
final label B − final label A = weight of arc AB
Each vertex is replaced by a box:

Vertex Order of labelling Final label


Working values

6 Dijkstra’s algorithm finds the shortest route between the start vertex and each intermediate
vertex completed on the way to the destination vertex.
7 It is possible to use Dijkstra’s algorithm on networks with directed arcs, such as a route with
one-way streets.
GLOSSARY 205
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

GLOSSARY
activity network (or arc network) activities decision variables (in a linear programming
represented by arcs, the completion of which, known problem) the numbers of each of the things that
as events, are shown as nodes. can be varied. The variables, which are often called
adjacency matrix each entry in an adjacency x, y, z, etc., will be the ‘letters’ in the inequalities and
matrix describes the number of arcs joining the objective function.
corresponding vertices. degree (or valency; of a vertex) the number of
algorithm a finite (i.e. limited) sequence of step-by- edges incident to the vertex, i.e. sharing a vertex.
step instructions carried out to solve a problem dependency when one activity cannot proceed until
arc a line segment connecting two nodes, also called another activity is completed.
an edge. digraph if the edges of a graph have a direction
backward pass in critical path analysis, this is associated with them, they are known as ‘directed
calculating all of the late event times. edges’ and the graph is known as a digraph.
bin-packing, first-fit an algorithm where each Dijkstra’s algorithm an algorithm to find the
object is fitted into the first available bin. shortest path from a vertex to the source vertex.
bin-packing, first-fit decreasing an algorithm distance matrix the entries in a distance matrix
where objects from a decreasing ordered list is fitted represent the weight of each arc, not the number
into the first available bin. of arcs.
bin-packing, full an algorithm where full bin dummy activity used to show dependencies
combinations are found first. between other activities.
bound a value which a set of numbers cannot go duration the length of time taken or needed to
above (upper bound) or go below (lower bound). complete an activity.
bubble sort an algorithm that orders a list of objects. early event time the earliest time of arrival at the
event allowing for the completion of all preceding
classical travelling salesman problem a problem in
activities.
which each vertex must be visited exactly once in the
shortest possible route. edge a line segment connecting two nodes, also
called an arc.
complete graph a graph in which each of the n
vertices is connected to every other vertex. edge set the set of all edges in a graph.
connected two vertices are connected if there is a Eulerian cycle (or Eulerian circuit) a trail which
path between them. A graph is connected if all its visits every arc, starting and ending at the same
vertices are linked in this way. vertex.
constraints things that will prevent you making or Eulerian graph a graph or network that contains a
using an infinite (i.e. unlimited) number of each of trail that includes every edge and starts and finishes
the variables. Each constraint will give rise to one at the same vertex.
inequality. event the start of finish of an activity.
corresponding an equivalent; connected with what feasible region the region of a graph that satisfies
you have just mentioned. all the constraints of a linear programming problem.
critical activity used to describe an activity if any feasible solution when you have found values for
increase in its duration results in a corresponding the decision variables that satisfy each constraint.
increase in the duration of the whole project. finite a value that is limited, not infinite.
critical path a path from the source node to the sink flow chart a type of diagram that represents an
node made up of critical activities. algorithm by showing the steps in boxes, and their
cycle (or circuit) a closed path, i.e. where the order by connecting the boxes with directional arrows.
end vertex of the last edge is the start vertex of formulate to develop a set of rules, expressing your
the first edge. ideas carefully.
206 GLOSSARY
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

forward pass calculating all of the early event time optimal solution a feasible solution that meets the
in critical path analysis. objective. There might be more than one optimal
Gantt (cascade) chart a graphic representation of solution.
the range of possible start and finish times for all the pass a single application of an algorithm, such as the
activities on a single diagram. bubble sort, where there is a repetition of the steps.
graph a graph G consists of points (vertices or nodes) path a finite sequence of edges, such that the end
which are connected by lines (edges or arcs). vertex of one edge in the sequence is the start vertex
Hamiltonian cycle a cycle that includes every vertex. of the next, and in which no vertex appears more
than once.
incident two objects that touch each other are
incident. pivot an object in a list or matrix which is selected by
an algorithm.
infinite a value that is unlimited, not finite.
practical travelling salesman problem a problem
inspection to use your knowledge in mathematics to
in which each vertex must be visited at least once
know the solution just by looking at it.
before returning to the start.
integer a whole number. The symbol for an integer
precede to happen or exist before something else
is z.
precedence table (or dependence table) a table
isomorphic graph a graph which shows the same
which shows which activities must be completed
information as a complete graph but may be drawn
before others are started.
differently.
Prim’s algorithm an algorithm to find a minimum
Kruskal’s algorithm an algorithm to find a minimum
spanning tree.
spanning tree.
quick sort an algorithm that orders a list of objects.
late event time the latest time that an event can be
left until without extending the time needed for the residual minimum spanning tree found when
project. a vertex is removed from the lower bound in the
travelling salesman problem.
lemma a small theorem used as a stepping stone to
more important results. route inspection algorithm an algorithm to find the
shortest route in a network
linear programming a method of solving problems
in involving inequalities and more than one variable. satisfy when having many inequalities or conditions,
and they are all true, we say that we have satisfied
loop an edge that starts and finishes at the same
them.
vertex.
scheduling a connected graph where there is one
matrix a rectangular array of numbers or other
pair of odd vertices.
mathematical functions for which operations such as
addition and multiplication are defined. semi-Eulerian graph a connected graph where there
is one pair of odd vertices.
maximise to increase something as much as possible.
shortcuts used to reduce the upper bound in the
minimise to reduce something to the smallest
travelling salesman problem.
possible amount.
simple graph a graph in which there are no loops
minimum connector see minimum spanning tree.
and there is no more than one edge connecting a pair
minimum spanning tree (also minimum of vertices.
connector) a spanning tree such that the total
sink node in critical path analysis, the final node.
length of its arcs is as small as possible.
source node in critical path analysis, the first node.
nearest neighbour algorithm an algorithm used to
find a short (but not necessarily the minimum) path spanning tree (of a graph G) a subgraph which
in a network. includes all the vertices of G and is also a tree.
node (also vertex) a point on a graph. subgraph (of G) a graph, each of whose vertices
belongs to G and each of whose edges belongs to G.
non-Eulerian graph a connected graph where there
is more than one pair of odd nodes. It is a graph table of least distances a table showing the
which is neither Eulerian or semi-Eulerian. shortest path between any two points in the network.
GLOSSARY 207
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

total float (of an activity) the amount of time tree a connected graph with no cycles.
that its start may be delayed without affecting the triangle inequality for three vertices A, B and C,
duration of the project. the triangular inequality is ‘length AB < length AC +
tour a walk which visits every vertex, returning to its length CB’, where AB is a longest length.
starting vertex. valency (or degree; of a vertex) the number of
trace table used to record the values of each variable edges incident to the vertex, i.e. sharing a vertex.
as an algorithm is run. vertex (also node) a point on a graph.
trail a walk in which no edge is visited more than vertex set the list of all vertices in a graph.
once.
walk (in a network) a finite (limited) sequence of
travelling salesman problem (also see classical edges such that the end vertex of one edge is the
and practical) a problem where one must find a start vertex of the next.
route minimum length which visits every vertex in an
weight the sum of the arcs in a graph.
undirected network.
weighted graph a graph which has a number
traverse to travel down an arc.
associated with each edge (usually called its weight).
208 ANSWERS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

ANSWERS
CHAPTER 1 ii

Prior knowledge check Step A r C  r − C  s Print r


1 a 47 b 24
1 79 10
2 x2 = 3, x3 = 2.65, x4 = 2.58
2 7.900
Exercise 1A 3 2.1
1 a b c
4 8.950
A B A B A B
5 8.95
244 125 125 244 256 123
6→2 8.827
122 250 62 488 128 246
3 0.123
61 500 31 976 64 492
4 8.889
30 1000 15 1952 32 984
5 8.889
15 2000 7 3904 16 1968
6→2 8.887
7 4000 3 7808 8 3936
3 8000 1 15  616 4 7872 3→7 0.002

1 16  000 Total 30  500 2 15  744 7 Print 8.889

Total 30  500 1 31  488 iii


Total 31  488 Step A r C  r − C  s Print r

2 a 1 ​ __ ​ 9 ​  ​ 
a ​ = __   __ c  ​ = __
​ 4 ​  
  a = 9, b = 4, c = 4, d = 3 1 4275 50
b 4 d 3
2  e = ad = 9 × 3 = 27 2 85.500
3  f = bc = 4 × 4 = 16
3 35.5
4 ​ __
27
16
 ​ 
4 67.750
b It divides the first fraction by the second fraction.
3 a 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 5 67.75
b The first 10 square numbers. 6→2 63.100
4 a i
3 4.65
Step A r C  r − C  s Print r
4 65.425
1 253 12
5 65.425
2 21.083
6→2 65.342
3 9.083
3 0.083
4 16.542
4 65.384
5 16.542
5 65.384
6→2 15.294
6→2 65.383
3 1.248
3→7 0.001
4 15.918
5 15.918 7 Print 65.384

6→2 15.894 b The algorithm finds the square root of A.

3 0.024
Exercise 1B
4 15.906 1 a a b c d d , 0? d=0 x
5 15.906
4 −12 9 0 No Yes 1.5
6→2 15.906
Equal roots are 1.5
3→7 0 b a b c d d , 0? d = 0? x1 x2
7 r = 15.906
−6 13 5 289 No No − ​ _1 ​ 
3
_
​ 5 ​ 
2
8 Stop
Roots are − ​ _13 ​  and _​  52 ​ 

Online
Worked solutions are available in SolutionBank.
ANSWERS 209
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

c 2 Ch St Br Bu Cr Ev Yo
a b c d d,0
Ch Br Bu Cr Ev St Yo
3 −8 11 −68 Yes Br Bu Ch Cr Ev St Yo
Br Bu Ch Cr Ev St Yo
No real roots
Bridlington, Burton, Chester, Cranleigh, Evesham,
2 a i Output is 21      ii  Output is 5 Stafford, York
b It will find the largest number in the list.
3 a 1
c Box 6 − changed to ‘Is n , 8?’
b One pass is sufficient if the items are already in
3 a 1.8041 (4 d.p.)
ascending order.
b 1.8041 (4 d.p.)
c n
The sequence produced in part b is initially quite d n passes are needed if the smallest item is at the
different to the sequence produced in part a but end of the list.
both sequences converge to the same root.
4 a i 13    ii 17    iii 15 4 a Move through the list comparing each pair of
b The algorithm finds the highest common factor of numbers. If the first number of a pair is greater
the two input values. than or equal to the second, make no change.
If the first number of a pair is less than the second,
5 a A B A , B? Output swap them.
18 7 No b 63 57 55 48 48 72 49 61 39 32
63 57 55 48 72 49 61 48 39 32
11 7 No 63 57 55 72 49 61 48 48 39 32
 4 7 Yes 4 63 57 72 55 61 49 48 48 39 32
63 72 57 61 55 49 48 48 39 32
b Calculates remainder when A is divided by B. 72 63 61 57 55 49 48 48 39 32
c 0 72 63 61 57 55 49 48 48 39 32

Exercise 1C Exercise 1D
1 i a 16 15 23 18 25 11 19 34 1 a 2 3 4 5 6 7 8
15 16 18 23 11 19 25 34 b 8 7 6 5 4 3 2
15 16 18 11 19 23 25 34 2 a 7 11 14 17 18 20 22 25 29 30
15 16 11 18 19 23 25 34 b 30 29 25 22 20 18 17 14 11 7
15 11 16 18 19 23 25 34 3 a C E H J K L M N P R S
11 15 16 18 19 23 25 34 b C E H J K L M N P R S
11 15 16 18 19 23 25 34 4 a Amy 93 Greg 91 Janelle 89 Sophie 77
b 23 16 34 18 25 15 19 11 Dom 77 Lucy 57 Alison 56 Annie 51
23 34 18 25 16 19 15 11 Harry 49 Josh 37 Alex 33 Sam 29
Myles 19 Hugo 9
34 23 25 18 19 16 15 11
b 93 91 89 77 77 57 56 51 49 37 33 29 19 9
34 25 23 19 18 16 15 11
n(n − 1)
34 25 23 19 18 16 15 11 5 a (n − 1) + (n − 2) + … 3 + 2 + 1 = ________
​​   ​​  
2
ii a E N T O R K S W b The bubble sort would be quicker, for example,
ENORKSTW if the items are to be put in increasing order
ENOKRSTW and if the only item out of place is the largest.
c i Bubble sort. Only the 7 is out of place and it
ENKORSTW
will be moved to its final position in the first
EKNORSTW pass. A second pass is still needed to complete
EKNORSTW the bubble sort. A total of 11 comparisons are
b N T W O R K S E needed for the bubble sort and 14 are needed for
TWORNSKE the quick sort.
WTROSNKE ii Quick sort. This is the worst case for the bubble
WTRSONKE sort. The 1 is at the wrong end of the list and
only moves one place with each pass.
WTSRONKE
6 a There are 9 names in the list. The 5th name (Mellor)
WTSRONKE
is taken as the pivot. Starting at the beginning of the
iii a A5 D2 A1 B4 C7 C2 B3 D3 list, each name is compared with Mellor and placed
A5 A1 B4 C7 C2 B3 D2 D3 on the appropriate side to produce two sublists. The
A1 A5 B4 C2 B3 C7 D2 D3 process is repeated for each sublist with pivot of G
A1 A5 B4 B3 C2 C7 D2 D3 on the left and M on the right.
A1 A5 B3 B4 C2 C7 D2 D3 b H S F G Me C Mi W A (M is the pivot)
A1 A5 B3 B4 C2 C7 D2 D3 H F G C A Me S Mi W (1st pass)
b D3 D2 A5 B4 C7 C2 B3 A1 F C A G H Me Mi S W (2nd pass)
D3 D2 B4 C7 C2 B3 A5 A1
D3 D2 C7 C2 B4 B3 A5 A1 Challenge
D3 D2 C7 C2 B4 B3 A5 A1 a Answers will vary.
b Put the Ace of Hearts at the end.
210 ANSWERS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 1E 4 a 
Adam
1 a 5 bins Alex
b i  Bin 1: 18 + 4 + 23 + 3 Des
Bin 2: 8 + 27 Doug
Bin 3: 19 + 26 Ed
Bin 4: 30 Emily
Bin 5: 35 Felix
Bin 6: 32 George
ii  Bin 1: 35 + 8 + 4 + 3 Hongmei
Bin 2: 32 + 18 Jess
Bin 3: 30 + 19 Katie
Bin 4: 27 + 23 Lei
Leo

}
Bin 5: 26
iii  Bin 1: 32 + 18 Lottie
Bin 2: 27 + 23 full bins Lotus
Bin 3: 35 + 8 + 4 + 3 Matt
Bin 4: 19 + 26 Miranda
Bin 5: 30 Oli
Ramin
2 a Bin 1: A(30) + B(30) + C(30) + D(45) + E(45)
Saul
Bin 2: F(60) + G(60) + H(60)
b i   George is in the list
Bin 3: I(60) + J(75)
ii  David is not in the list
Bin 4: K(90)
iii  Jess is in the list
Bin 5: L(120)
Bin 6: M(120) Chapter review 1
b Bin 1: M(120) + I(60) 1 15 2 27 16 1 38
Bin 2: L(120) + H(60) 2 15 16 1 27 38
Bin 3: K(90) + J(75) 2 15 1 16 27 38
Bin 4: G(60) + F(60) + E(45) 2 1 15 16 27 38
Bin 5: D(45) + C(30) + B(30) + A(30)
1 2 15 16 27 38
c Lower bound 5 so b optimal.
d Bin 1: M(120) ⎫ 2 a 42 31 25 26 41 22
Bin 2: L(120) ⎪ 42 31 26 41 25 22
Bin 3: A(30) + K(90) ⎪
Bin 4: F(60) + G(60) ⎪
⎬ full bins 42 31 41 26 25 22
42 41 31 26 25 22
Bin 5: H(60) + I(60) ⎪ b 15
Bin 6: J(75) + E(45) ⎭
3
Bin 7: B(30) + C(30) + D(45) 8 4 13 2 17 9 15
3 a e.g. First-fit does not rely on observation.
2 8 4 13 17 9 15
b 4
c Bin 1: A, B, C, D; Bin 2: E, I, J; Bin 3: F, G, H 2 8 4 13 9 15 17
Each of the three lanes is full, so solution is optimal. 2 8 4 9 13 15 17
4 a 4 rolls
b 5 rolls, 15 m wasted 2 4 8 9 13 15 17
c Doesn’t always give an optimal solution
2 4 8 9 13 15 17
d e.g. Bin 1: A, C, L; Bin 2: B, D, E, F; Bin 3: G, H, I,
Bin 4: J, K 2 4 8 9 13 15 17
No carpet is wasted.
5 a Bin 1: H(25) + A(8) 4 a 111 103 77 81 98 68 82 115 93
Bin 2: G(25)
Bin 3: F(24) + B(16) 111 103 115 98 77 81 68 82 93
Bin 4: E(22) + C(17) 111 115 103 98 77 81 82 93 68
Bin 5: D(21)
b Lower bound is 4. 115 111 103 98 93 82 77 81 68
c There are 5 programs over 20  GB. It is not possible 115 111 103 98 93 82 81 77 68
for any two of these to share a bin. So at least 5 bins
will be needed, so 4 will be insufficient. b i Bin 1: 115 + 82
Bin 2: 111 + 81
Exercise 1F Bin 3: 103 + 93
1 a Connock is in the list Bin 4: 98 + 77
b Walkey is in the list Bin 5: 68
c Peabody is not in the list ii No room in bin 1 (3 left) or bin 2 (8 left) or bin 3
2 a 21 is in the list (4 left) but room in bin 4.
b 5 is not in the list 5 a Rank the times in descending order and use them
3 a 7 b 10 c 14 in this order. Number the bins, starting with bin 1
each time.

Online
Worked solutions are available in SolutionBank.
ANSWERS 211
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

b Bin 1: 100 c Middle of the list is Hyo. Kim follows Hyo. Consider
Bin 2: 92 sublist : J K M R T
Bin 3: 84 + 30 Middle of list is Merry. Kim comes before Merry.
Bin 4: 75 + 42 Consider sublist: J K
Bin 5: 60 + 52
unused space on DVD: 65 minutes Middle of list is Kim. Kim found. Kim is in the list.
c There is room on DVD 2 for one of the 25-minute
programmes but no room on any DVD for the
second programme. CHAPTER 2
6 a The two 1.2  m lengths cannot be ‘made up’ to Prior knowledge check
2  m bins since there are only 3 × 0.4  m lengths. 1 If a = b + c, then ABC would be on a straight line, and if
Two of these can be used to make a full bin, a . b + c, then sides b and c would not have sufficient
1.2 + 0.4 + 0.4, but the second 1.2  m cannot be combined length to meet at a single point A
made up to 2  m since there is only one remaining
0.4  m length. 2 AECD = 12
b Bin 1: 1.6 + 0.6
Bin 2: 1.4 + 1
Exercise 2A
Bin 3: 1.2 + 1.2 1 a i a student   ii  that a pair of students are friends
Bin 4: 1 + 1 + 0.4 b Banjit, Dhevan, Esme
Bin 5: 0.6 + 0.6 + 0.6 + 0.4 c e.g. Adok and Chris, Esme and Fabio
Bin 6: 0.4 2 a A B C D E F
c Bin 1: 1.6 + 0.4 + 0.4
Bin 2: 1.4 + 1
Bin 3: 1.2 + 1.2
Bin 4: 1 + 1 + 0.4
Bin 5: 0.6 + 0.6 + 0.6 + 0.6
7 a Output 4.8
b It selects the number nearest to 5.
c It would select the number furthest from 5. Mathematics Physics Chemistry Biology Art English
8 a 1st pass: 2.0  1.3  1.6  0.3  1.3  0.3  0.2  2.0  0.5  0.1 b Mathematics and art
2nd pass: 2.0  1.6  1.3  1.3  0.3  0.3  2.0  0.5  0.2  0.1 3 a i One change. For example, Chancery lane to
3rd pass: 2.0  1.6  1.3  1.3  0.3  2.0  0.5  0.3  0.2  0.1 Notting Hill Gate on red line, then Notting Hill
4th pass: 2.0  1.6  1.3  1.3  2.0  0.5  0.3  0.3  0.2  0.1 Gate to Victoria on the yellow or green line.
5th pass: 2.0  1.6  1.3  2.0  1.3  0.5  0.3  0.3  0.2  0.1 ii  hrough 4 stations. For example, Chancery
T
6th pass: 2.0  1.6  2.0  1.3  1.3  0.5  0.3  0.3  0.2  0.1 Lane – Holborn – Tottenham Court Road – Oxford
7th pass: 2.0  2.0  1.6  1.3  1.3  0.5  0.3  0.3  0.2  0.1 Circus – Green Park – Victoria.
8th pass: 2.0  2.0  1.6  1.3  1.3  0.5  0.3  0.3  0.2  0.1 b i Marylebone to Waterloo on the brown line.
b Bin 1: 2.0; Bin 2: 2.0; Bin 3: 1.6 + 0.3 + 0.1 7 × 80 = 9 min 20 sec
Bin 4: 1.3 + 0.5 + 0.2; Bin 5: 1.3 + 0.3 ii Victoria to Gcreen park (light blue line), green
5 lengths of pipe needed park to baker street (grey line).
c Yes: Total length required is 9.6 m, so lower bound 3 × 80 + 180 = 7 min.
is 4.8, rounded up to 5 lengths of pipe. iii Holborn to Oxford Circus (red line), Oxford Circus
9 M V C A D B K S to Victoria (light blue line), Victoria to St James
Park (yellow or green line)
C A B D M V K S
5 × 80 + 2×180 = 12 min 40 sec
A C B D K M V S
4 a 40 min
A B C D K M S V b Aberdeen/Cork
A B C D K M S V c Dublin − it is the airport with the most connections
5 a PTV
Challenge b Not correct. PTQRSV is 25 km
a The names are not in ascending alphabetical order and
so a binary search cannot be done. Challenge
b a 6 routes b 18 routes
J M C B T H K R G F
J C B M H K R G F T Exercise 2B
1 a For example:
C B J H K M G F R T
B C H J K G F M R T
B C H J G F K M R T
B C H G F J K M R T b
B C G F H J K M R T
B C F G H J K M R T
B C F G H J K M R T
212 ANSWERS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

c 6 a For example

2 a is not simple.
4 vertices of degree 2
There are two edges connecting C
with D. b For example
b and c are simple.
d is not simple. There is a loop attached to U.
3 a and c are connected.
b is not connected, there is no path from J to G, f
or example.
d is not connected, there is no path from W to Z, 3 vertices all even, all of degree 2
for example. c The sum of degrees = 2 × number of edges, so the
sum of degrees must be even. Any vertices of odd
4 a Any four of these:
degree must therefore ‘pair up’. So there must be
F A B D FED
an even number of vertices of odd degree.
F A C B D FECBD
7 2 16
F A B C E D F E C A B D
FACED
b e.g. F A C B D E F, D B A F E D
c Vertex A B C D E F
Degree 3 3 3 2 3 2

d Here are examples. (There are many others.)


i  A ii  F 4 8
8 a A Hamiltonian cycle is a cycle
C that includes every vertex.
B b PQRSTP, PQSRTP, PTSRQP, PTRSQP
c A subgraph of some graph G is a graph whose
E edges and vertices are all edges and vertices of G.
B d e.g.     or  
iii  A

C D 9 x = 2
e Sum of degrees = 3 + 3 + 3 + 2 + 3 + 2 = 16
number of edges = 8
Exercise 2C
sum of degrees = 2 × number of edges for this graph
1 a and b are trees.
5 c is not a tree, it is not a connected graph.
Vertex J K L M N P Q R S d is not a tree, it contains a cycle.
Degree 1 2 3 1 1 4 2 1 1 2 i

Here are some possible subgraphs (there are many


others).
i  L P   ii Q
ii

S
P
R iii
L
iii J S
Sum of degrees = 1 + 2 + 3 + 1 + 1 + 4 + 2 + 1 + 1 = 16
iv
number of edges = 8
sum of degrees = 2 × number of edges for this graph

Online
Worked solutions are available in SolutionBank.
ANSWERS 213
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

v Exercise 2D
1 A B C D E F G
A 0 1 1 0 2 0 0
B 1 2 1 0 0 0 0
vi
C 1 1 0 2 0 1 0
D 0 0 2 0 0 1 1
E 2 0 0 0 0 1 0
F 0 0 1 1 1 0 1
vii
G 0 0 0 1 0 1 0

2 a A B

viii

C
ix E D
b A B

C
D
xi

c A B

3 BCEF
4 A, C
5 a i A tree is a connected graph with no cycles.
ii A spanning tree is a subgraph which includes all
D C
vertices and is a tree.
b The graph is not connected. d A B
6 a

D C
b Each vertex will have a degree of n − 1
c 190 3 a A
23 21
E B
Challenge 20
23
22
17
41
D 18 C
b A B
8 11
9
F
15 17 13 C
8
E 10 D
214 ANSWERS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

4 iii 
A B C D E F
A — 14 11 — — —
B — — 10 13 11 —
C — — — 12 — —
4 a A distance matrix gives the weights of edges
D — — — — — 10
between pairs of vertices, whereas an adjacency
E — — — — — 7 matrix gives the number of edges between pairs of
F — — — — 9 — vertices.
b A B C D E F
5 a A B A — 20 18 16 — —
B 20 — 15 — — 50
C 18 15 — 10 20 30
C
D 16 — 10 — 23 —
E — — 20 23 — 25
E D
b E F — 50 30 — 25 —
c A B c e.g.  B
F
20 30
18
A 20
C C
16 E
E D D
Weight = 104
Chapter review 2 5 v − 1
1 11 B 6 PQR, PQTR, PTR, PSR
A
7 a 3
b i e.g. BEAD    ii e.g. ACEA
9 c i e.g.  A    
15
D C E B
16
8
2 a, e and h are isomorphic. D C
b and i are isomorphic. ii e.g. A
c and g are isomorphic.
d and f are isomorphic.
3 a B

C
8 a The sum of the degrees of the vertices must be
even. However, 3 + 1 + 2 = 7 is odd, so there is no
4-vertex graph whose vertices have these degrees.
b i  b 5
9 a AGBECFDHA
b e.g. ACEBFDA

Challenge
a V = 7, E = 13, R = 7; 7 + 7 − 13 = 1
b
ii 

V = 1, E = 4, R = 4; 1 + 4 − 4 = 1
c E = R, so V + R − E = V = 1

Online
Worked solutions are available in SolutionBank.
ANSWERS 215
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

d V  9 = V − 1, E9 = E − 1, R9 = R 2 a i  A tree is a connected graph with no cycles.


So V9 + R9 − E9 = (V − 1) + R − (E − 1) = V + R − E = 1 ii A minimum spanning tree is a tree of minimum
e We will prove the following statement by induction: total weight that connects all of the nodes.
The relationship V + R − E = 1 holds for all connected b Writing the arcs in order of their weights: YZ (15),
graphs with n vertices’. Basis step: part c shows that VW (16), XY (17), UW (17), UX (18), WX (18),
this statement holds for n = 1. Induction step: Assume SU (18), WZ (18), UV (19), TU (20), ST (22),
true for any graph with n − 1 vertices. Then, given a TV (23)
graph G of n vertices, contract one edge to obtain a Underlined arcs are in the minimum spanning tree.
graph G9 of n − 1 vertices. The induction hypothesis Total weight = 121
implies that G9 satisfies the relation, and then part d c X
implies that G also satisfies the relation. S 18 U 18 17
Y
CHAPTER 3 20 17
15
W
Prior knowledge check T
16
1 a 5 V Z
b A B C D E F G d The minimum spanning tree is not unique. For
A − 12 15 − − 4 9 example, UX can be replaced with WX.
3 a 6
B 12 − 7 14 − − −
C 15 7 − 9 5 11 − 3
1
D − 14 9 − 16 − − 5
8
E − − 5 16 − − 2 3.5
F 4 − 11 − − − 3
4 2 6
G 9 − − − 2 3 −
c e.g. AF (4), FG (3), GE (2), EC (5), BC (7), CD (9).
7
Total weight 30.
The three shortest edges do not form a cycle.
Exercise 3A b
1 a A
2 1
16
14 C B 2.5

H 12 12 E 5 6 7
18 D
15 11
G F 8
weight:
EF, BD, CD, AH, DF, AC, GH; weight9898
The three shortest edges form a cycle.
b C
A 4 a Cl
6
B 7 0.8
4 1.4 Ce
M S 1.9
2 2.8 2.3 1.6
5 D H
R
3 P 3.1 E
F 1.1
G
Sh
E Arcs were added in the order MCl (0.8), ShR (1.1),
BF, FG, AB, CE, BC, CD;
weight: 27weight 27 ClS, CeR, CeH, SR, ME, PE
c C b 15 km
3.8 2.1
A B

4.2 D
H E 1.4
3.8
1.7
2.3
J F
3.1
G
DE, EF, CD, EG, GJ, AB, GH, BH; weight 22.4
weight: 22.4
216 ANSWERS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Exercise 3B b $17 340
c Replace WX with VX. This is the cheapest way to
1 A
link X to the spanning tree. The total cost is now
16 $231 000 + $28000 − $19000 = $240 000
14 C 5 a Prim’s algorithm identifies the next node to link to
B the existing tree. Linking a new node cannot form
H 12 a cycle.
18 12 b One minimum connector is shown below.
D E
B Order of
15 11 connection
G 4 D
F 10 J AB
8
weight: 98 A F 9 BC
10 8 CD
9 I
b C 8 K DE
A C
6 G L 7 DF
B E FG
4 7 8
6 GH
H HL
2 KL
5 D
Total weight = 87 IK
3 IJ
F
c The minimum connector is not unique; there are
G
three minimum connectors with total weight 87.
E
Exercise 3C
weight: 27 1 a Arcs in order:
c C AF (9)
FB (14)
A 3.8 2.1 AC (20)
AE (25)
4.2 D DE (26)
H E 1.4 weight = 94
1.7 b Arcs in order:
3.8 RS (28)
2.3 ST (16)
F SU (19)
J UV (37)
3.1 G
weight = 100
weight: 22.4 2 Arcs in order:
2 In Prim’s algorithm, the starting point can be any node, BS (78.4)
whereas Kruskal’s algorithm starts from the arc of SM (70.4)
least weight. SN (89.6)
In Prim’s algorithm, each new node and arc are added NL (59.2)
to the existing tree as it builds, whereas in applying weight = 297.6
Kruskal’s algorithm, the arcs are selected according to 3 a cost = €1014
their weight and may not be connected until the end. b D
3 a 35 H
H C 3.1 A 42
D
1.8 48
2.4 52
47 53
A E F
4.6 B 3.4 E
2.8 61 G
2.3 C
G F
B
Selection order: AH, AG, AB, BC, CD, BF, EF i It is cheaper to translate from E to H then from H
c
b 17 340 to G at a cost of 48 + 52 = 100 euro rather than
4 a Q T W 159 euro per 1000 words.
27
ii A direct translation is likely to be more accurate
27 15 41 then a translation via another language.
S 18
P V Y
31 19
29
24

R U X

Online
Worked solutions are available in SolutionBank.
ANSWERS 217
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

4 a order of arcs 4 Shortest route: S1 − B − C − F − E − G − T


XE (26) Length of shortest route: 1660
EG (18) 5 a 94 − 18 = 76  EH  76 − 24 = 52  CE 
EH (23) 52 − 22 = 30  BC  30 − 30 = 0  AB
HA (25) Shortest route A to H: A − B − C − E − H
AF (20) Length 94
FB (16) b Shortest route A to H via G: A − D − G − H
AD (22) Length 96
FC (24) c Shortest route A to H not using C E: A − D − F − E − H
CI (26) Length 95
b 6 Shortest route: S − B − C − T
C 26 I Length of shortest route: 10
E 7 a Quickest route is SCEHT. Shortest time = 31 min.
26 23
X H b i Route changes to SABDGT. New time = 32 min
24
18 ii The driver should change the route to HEGT to
25 20 B save 1 minute. Total travel time 38 min.
A F 16
G
22 Chapter review 3
D 1 a i  Arcs are labelled with initial letters of the nodes.
c I CK add to tree
SH add to tree
X 74 D 22 A 26 CE add to tree
EK reject
20 24
25 C CH add to tree
HW add to tree
23 F CS reject
18 E H 16 HQ add to tree
QS reject
QD add to tree
G B KS reject
DW reject
Exercise 3D EW reject
1 a ii  EC
C A F B E D CK
CH
weight = 97 HS
b S T U R V HW
HQ
weight = 110 QD
b K S
2 AEFBCD weight = 69
BCDEFA weight = 76 234 300
CBFAED weight = 73 378 538
340 Q
DCBFAE weight = 68 C H
EAFBCD weight = 68 E
423 740
FAEDCB weight = 72
shortest route is DCBFAE weight = 68 weight: 2953 W D
or EAFBCD weight = 68
2 a i  LT L M N
3 ACBDE weight =437 MT
BCDAE weight = 395 4.1 4.7
MQ
CBDAE weight = 444 3.8 T 3.7
NQ
DCBEA weight = 420 ST 6.8
Q
ECBDA weight = 432 QR 6.6
shortest route is BCDAE weight = 395 NP S 6.6
P
Exercise 3E R
1 a Shortest route: S − B − E − H − G − C − F − T ii  MQ (3.7) add to tree
Length of shortest route: 20
LT (3.8) add to tree
b Shortest route: S − A − B − D − F − H − T
MT (4.1) add to tree
Length of shortest route: 15
NQ (4.7) add to tree
2 a A to Q A − F − E − I − N − P − Q Length 37 MN (5.3) reject
b A to L A − F − G − M − L Length 19


c M to A M − G − F − A
d P to A P − N − I − E − F − A
Length 17
Length 24
{
ST (6.6) add to tree
QR (6.6) add to tree
NP (6.8) add to tree
3 Shortest route: A − B − E − C − G − F Length 38 reject remaining arcs
218 ANSWERS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

b Start off the tree with QT and PR then apply 7 a Possible paths are A − H − G − E − I − K
Kruskal’s algorithm. Prim’s algorithm requires the and A − H − J − I− K
‘growing’ tree to be connected at all times. When and A − B − C − K
using Kruskal’s algorithm the tree can be built from i  A, B, F, H, D, G, J, E, C, I, K
non-connected sub-trees. ii  44 − 9 = 35 IK 44 − 9 = 35 IK
L 35 − 10 = 25 EI 35 − 17 = 18 JI
M 25 − 10 = 15 GE or 18 − 8 = 10 HJ
3.8
T 15 − 5 = 10 HG 10 − 10 = 0 AH
3.8 N 10 − 10 = 0 AH
6.6 or
9.2 4.7 44 − 12 = 32 CK
S 6.6 Q 32 − 25 = 7 BC
R 7 − 7 = 0 AB
7.5 P b A − H − G − E − I − K and A − H − J − I − K
and A − B − C − K
3 a C
c The arcs could be roads.
The nodes could be junctions.
52 The number on each arc could be distance in km.
84 97 58 41 The network, together with Dijkstra’s algorithm,
could be used to find the shortest route from A to K.
B F A E D 8 Order of vertex labelling:
length 332 mm order: AC, AE, ED, AF, FB
Selection S C B A E D G F T
b length 332 mm Route: S − C − E − F − T
4 a Arcs in order: Entrance 2−Office; Entrance 2− 411 − 101 = 310 FT
Entrance 4; Entrance 4−Entrance 3; Office−Entrance 1 310 − 123 = 187 EF
187 − 85 = 102 CE
Entrance 1 Entrance 2 Entrance 3
102 − 102 = 0 SC
1514 587  9 a B
488
523 17
Office A
Entrance 4 15 C
b length 3112 m 19 Total weight = 72
5 a 29 27 30 19 9 26 17 18 8 12 24 20 14 14 22 26 D
E 21
8 29 27 30 19 9 26 17 18 12 24 20 14 14 22 26
b Students’ own answer
8 9 17 12 14 14 18 29 27 30 19 26 24 20 22 26
c Prim’s algorithm may be quicker on a graph with a
8 9 12 17 14 14 18 19 24 20 22 26 29 27 30 26 large number of arcs, such as a complete network,
8 9 12 14 17 14 18 19 20 24 22 26 29 27 26 30 as Kruskal’s algorithm would require arcs to be
sorted by weight. 10 a
8 9 12 14 14 17 18 19 20 22 24 26 26 27 29 30
10 a D
EF CD EJ FJ GI CG DG BC FI HK EK CF JK AE AB AH
b, c C
1290
B 19 C 1450
A 27 9 960
E 8 F A
17
24 D
12 20 G
H 2010
22 K G
14 440
J I Total weight = 172
d e = v − 1 B
F 1100
6 a weight = 45 so 4500 m needed
C 3 F H
1 E
680
A 3 3
L
2 5
D 6 4 H
4 G I N weight of MST = 7930 km
4 4 b C − G − B − E − H − A − D − F weight = 9620 km
M c MST × 2 = 15 860 , nearest neighbour and return
3 = 13 080. The method using the nearest neighbour
B E J 3 K
will give the shortest way.
b weight = 47 so 4700 m

Online
Worked solutions are available in SolutionBank.
ANSWERS 219
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

Review exercise 1 8 a A Hamiltonian cycle is a cycle that includes every


1 a vertex.
a b c d e f f = 0? answer is 15 b ABDCFGEA
645 255 2.53 2 510 135 No 9 a GC, FD, GF, reject CD, ED, reject EF, BC, AG, reject AB.
255 135 1.89 1 135 120 No b A 54 G 30 F 25 D 35 E

135 120 1.13 1 120 15 No 20 50


120 15 8 8 120 0 Yes C B
cost = (20 + 25 + 30 + 35 + 50 + 54) × €1000
b The first row would be = €214  000
255  645  0.40  0  0  255  
10 a i Method:
but the second row would then be the same as the
• Start at A and use this to start the tree.
first row in the table above. So in effect this new
• Choose the shortest edge that connects a
first line would just be an additional row at the start
vertex already in the tree to a vertex not yet in
of the solution.
the tree. Add it to the tree.
c Finds the highest common factor of a and b. • Continue adding edges until all vertices are in

the tree.   AF, FC ​​ ​   or​  ​   ​​, FD, EB


2 a Total length = 390 cm, so 4 planks are needed. FB
{BC}
b 6 planks
c 5 planks
d There are 5 lengths over 50 cm, so none of these ii A 9 F 7 B 11 E   or
can be paired together. Therefore minimum of
5 lengths are required. 3 8
3 a 80  55  84  25  34  25  75  17  5  3 D
C
80  84  55  34  25  75  25  17  5  3
84  80  55  34  75  25  25  17  5  3 A 9 F 3 C 7 B 11 E
84  80  55  75  34  25  25  17  5  3 8
84  80  75  55  34  25  25  17  5  3
b 403 ÷ 100 = 4.03 so 5 bins are needed. D
c Bin 1: 84 + 5 + 3 iii The tree is not unique, there are 2 of them
Bin 2: 80 + 17 (see above).
Bin 3: 75 + 25 b i number of edges = 7 − 1 = 6
Bin 4: 55 + 34 ii number of vertices = n 1 1
Bin 5: 25 11 a A 7 B
4 a For example, 45 37 18 46 56 79 90 81 51 11 4
b For example, 56 45 79 46 37 90 81 51 18 7 3
F 8 2 C
5 For example, 3 9
5
R P B Y T K M H W G D
6
E

b BD, ​​{  ​   ​  ​ }​​, BC, reject CD, DE; length 18 km


B H G K R P Y T M W
AC

B G H R P M T Y W DF
A B
B G M P R W Y
B G H K M P R T W Y 3 4
F C
list in order 3 2

6 a Since the graph is simple, there are no loops, so D


6
each of the degree-5 vertices must be joined to each E
of the other vertices. This means that each of the c DB, DF, BC, CA, DE
other vertices has degree at least 2. 12 a In Prim’s algorithm, the starting point can be any
b e.g. node, whereas Kruskal’s algorithm starts from the
arc of least weight.
In Prim’s algorithm, each new node and arc is
added to the existing tree as it builds, whereas in
7 a applying Kruskal’s algorithm, the arcs are selected
according to their weight and may not be connected
until the end.
b i GH, GI, HF, FD, DA, AB, AC, DE
ii GH, AB, AC, AD, reject BD, DF, GI, reject BC, FH,
reject DG, DE
c weight is 76
b 4 c 5
220 ANSWERS
Uncorrected proof, all content subject to change at publisher discretion. Not for resale, circulation or distribution in whole or in part. ©Pearson 2018

13 a Route: S − A − C − G − T,  length: 82 With 5 lines there must be at least three of one
C 6 54 colour so there are four points connected by the
20 same colour.
54
A 3 34 16
34 11
34 D 5 45 26 G 9 70 A
S 1 0 46 45 76 71 70 12
0 24 33 T 10 82
E 4 43 84 82
22 For the three lines connecting the new points,
B 2 22 43 25 if one is the original colour then a set of three
21 18
22 H 8 66 vertices is made with the original colour. If none
34 F 7 56 68 66 are the original colour then the three vertices
56 10 make a set of three themselves.
b For example  82 − 12 = 70 GT
70 − 16 = 54 CG
54 − 20 = 34 AC A A
34 − 34 = 0   SA
c Shortest route from S to H + HT  S − B − F − H − T
length: 84 iii
14 a A 1 0 B 3 4 C 7/8 10 D 12 6
4 6 6
0 4 10 16

1 2 8 4

E 2 1 4 F 4 5 5 G 8/7 10 2 H 10/9 12
1 5 10 12 2 a G
5 7 3 1 70 + 2x 40 + 5x
165 + 5x, 265 + 2x
B 8 195 A 5 125
I 5 6 2 J 6 8 4 K 9/10 12 1 L 11 13
6 12 8 12 13 200 195 125
60 50
For example 70 30
13 − 1 = 12 HL or 13 − 1 = 12 KL
12 − 2 = 10 GH 12 − 4 = 8 JK C 7 135
F 6 130 E 4 95
10 − 5 = 5 FG   8 − 2 = 6 IJ 30 140 135 40
5 − 4 = 1 EF   6 − 5 = 1 EI 130 95
1 − 1 = 0 AE   1 − 1 = 0 AE
Shortest path is {​​ ​    ​ }​ length 13
A−E−F−G−H−L 90 95 70
130 140
A−E−I−J−K−L
b State the other path. I 2 50 D 3 80
50 80
Challenge H 1 0
50 80
1 a Let G be any simple graph with more than one
vertex and with number of vertices = n > 2. 0
The maximum degree of any vertex in G is < n − 1. Via A H − E − A − G length 165 + 5x
Also, if our graph G is not connected, then the Via B H − E − C − B − G length 265 + 2x
maximum degree is < n − 1.
b 165 + 5x = 265 + 2x ⇒ x = 33 ​​ __13 ​​  
Case 1: Assume that G is connected. We cannot
have a vertex of degree 0 in G, so the set of vertex So range is 0 < x < 33 ​​ __13 ​​
degrees is a subset of S = {1, 2, … , n − 1}. Since the
graph G has n vertices and there are n − 1 possible CHAPTER 4
degree options, there must be two vertices of the
same degree in G. Prior knowledge check
Case 2: Assume that G is not connected. G has no 1 a 16
vertex of degree n − 1, so the set of vertex degrees is b Sum of orders = 2 × number of arcs
a subset of S9 = {0, 1, 2, … , n − 2}. Again we have n c 4
vertices and n − 1 possible degree options, so there d From part b, the sum of the valencies must be even.
must be two vertices of the same degree in G.
b i Possible sets are: Exercise 4A
Blue: ABD, ACD
1 a Vertex
Red: BCF, DEF A B C D E F
ii For K6 any vertex will have a valency of 5, an Degree 2 3 2 3 3 3
edge to each of the other points.
There are 4 nodes with odd degree so the graph is
A neither Eulerian nor semi-Eulerian.

Online
Worked solutions are available in SolutionBank.

S-ar putea să vă placă și