100% found this document useful (1 vote)
13K views273 pages

Edexcel IAL Decision Mathematics 1

Textbook

Uploaded by

Ahsan Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
100% found this document useful (1 vote)
13K views273 pages

Edexcel IAL Decision Mathematics 1

Textbook

Uploaded by

Ahsan Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 273
ee Pearson Edexcel Qualifications 4 i bee Z = : ee aA 7 ba B47 en alae aS DN ea tes) ee ee as, ee eS cod USE (Ha Ue ew Mey ee SUD ST Tie ¢ PDF COMPILED BY SAAD PEARSON EDEXCEL INTERNATIONAL A LEVEL eee Student Book ‘atshes by Posen Edation Line, 80 Star, Landon, WO2R ORL. wwipersongboaechoolcom ‘Copies ool speciteabon ora Pearson qualifications ay be found on the ‘webate: hipe//quatteatons pearon.com “ext © PoaroonEavoston Lites 2018 ed by Line ce ana Ee Pade “ype! by Tach StL, Gateshead UK (Origa usatons © Pasrson Edenton Linea 2018 ‘misatd by ©Tect-Se Li, Gateead, UK ‘Cove design by © Pearson Education Lite “hots of Martin Croce, Susie Jmoson, Kath Pid. Peter Shera oe Sirakowek ana Har Smith be eifod ase author of ths work have ‘ben auld by toni accordance with the Copyright, Design and Patera, et 98, Fret pines 2018 0967654921 ‘ian Lary Cataloguing in Pascatin Data ‘catalogue recor for hs book is valle fom the Beh Library ‘san ova 257244 563 copyright noice ‘Anghs reserve. No par of hs may be reproduce nay orm or by any means fecusing photocopying or tre Win sy recur by etectrnic meas and ‘tha ona tansy or nesta to some oar ue fhe pustcton) ‘ito the writen person of the copa une, except in accordance wih ‘he prouons ofthe Caps. Belg and Pars Act O88 or under the me ‘ofa omen seve by tho Copyriaht Uooneng Agere, Barnard on 05 Fer ‘ane, London, ECA 1EN (wucta.cou, Aoplatan fo Te copyright owners ‘len permission shui! be adresse the publish Protein Sovakia by Neogata Picture Crocs ‘ho athors and publaher would keto hank he oowing nds and ‘orgrisations fr permission to repedace photographs: ‘Mame ZUMA Peas, nc an tastonen 2, ny Popoy 82, Roy LANGSIAFF 106, Natalya Hora 12, ws faang #70: Gatly Images: Stock Unwed 32, Selence Photo Library Potr Mero 39 ‘Cover image: Front tty Images: Peto Ryan Insts ft conse Shuttarstock com: On Lobsroe ‘other images © Pearson ESucaton United 2018 ‘lertwor Pearson Edveston Lined 2038 Endorsement Statement rower to enaure hal hi retcuce fe highly sia forthe atocited Pearson auton, thas bob trou ave process by the awaring body “Ths proces covfme al thwsoure fy comes the teaching a earn contnt ofthe sposteaton or prof a soctoation at which ti med lso onfima that emonavates an appropiate balance betweon the devaonent fai sts role an ncetndig aan panton Ensocstmant a nt cover any gusance on atetementactitas or proceenea {@9-procice uestons or advice on how to wsewerasossrien questions) Iruted mtn recite, rer does t pesca parc appreach 10h teaching oF delivery ofa elated course. le the pubiars have made erry arp to enue that advice onthe (qualflcaton ands assessments accurate, the oficial epecfeaten ahd ‘icoited assesment gute mater re the any eave sere Irtoraton ana stous aways be refs to for dott guidance, Pearson examiners have nt contributed to any actions inthis resource relevant to ‘ramnaton papers er whien hey have responsbiy. ascecoment st by Poaron. Endorsmant of arovoure dees mean that he resource i rogue to schave ths Pearson quailtin, pox dows rea that Is tre ery eutabe matora avaible to support the qualcaton and ary rsource 1s produced by te awarding body shal icudo tha and ther approprate COL COURSE STRUCTURE 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 CHAPTER 1 ALGORITHMS 1.1 USING AND UNDERSTANDING ALGORITHMS 1.2 FLOW CHARTS: 1.3 BUBBLE SORT 1.4 QUICK SORT 1.5 BIN-PACKING ALGORITHMS, 1.6 BINARY SEARCH CHAPTER REVIEW 1 CHAPTER 2 GRAPHS AND NETWORKS 2.1 MODELLING WITH GRAPHS 2.2 GRAPH THEORY 2.3 SPECIAL TYPES OF GRAPH 2.4 REPRESENTING GRAPHS AND NETWORKS USING MATRICES CHAPTER REVIEW 2 CHAPTER 3 ALGORITHMS ON GRAPHS 3.1 KRUSKAL'S ALGORITHM 3.2 PRIM’S ALGORITHM. 3.3 APPLYING PRIM'S ALGORITHM TO A DISTANCE MATRIX 3.4 THE NEAREST NEIGHBOUR ALGORITHM 3.5 USING DIJKSTRA'S ALGORITHM TO FIND THE SHORTEST PATH CHAPTER REVIEW 3 REVIEW EXERCISE 1 10 16 22 24 29 30 38 42 50 57 60 64 n 76 aca CHAPTER 4 ROUTE INSPECTION 81 4.1 EULERIAN GRAPHS 82 4.2 USING THE ROUTE INSPECTION ALGORITHM 85 CHAPTER REVIEW 4 1 CHAPTER 5 THE TRAVELLING SALESMAN PROBLEM 95 5.1 THE CLASSICAL AND PRACTICAL TRAVELLING SALESMAN PROBLEMS 96 5.2 USING A MINIMUM SPANNING TREE METHOD TO FIND AN UPPER BOUND 100 5.3 USING A MINIMUM SPANNING ‘TREE METHOD TO FIND A LOWER BOUND 107 5.4 USING THE NEAREST NEIGHBOUR ALGORITHM TO FIND AN UPPER BOUND aw CHAPTER REVIEW 5 116 CUTS at 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 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 cr specify the problem into the main exercises + Problem-solving boxes provide tips and strategies interpret results auediteiean + Challenge questions provide extra stretch j 3. Transferable skills 9 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 * 1 ALGORITHMS Each chapter is map specticaton content for easy reference Each chapter stars with alist of Learning ob) The Prior nowledge check helps make Suro you ae ready fo start the erctee ‘The rel wold apoications ofthe mathematics you are abot to learn are highlighted atthe start ofthe cnapte Glossary terms wil be dentited by bald lu text on ta first appearance ‘iarstenbe sae we signposted where they naturally occur Inthe exerosee and ‘amples Ghatenge boxes ave yous chance tackle Some more au ‘questions Sap by stop worked ‘examples focus onthe ey types of questions youl need wo tackle Exam-style questions boxes nihight areas wnere students are flagged with © Problem-solving Dotted SEE) sees ca Saaemaee| | apewan CUCL Probie solvng baxsa provide ris, tips and strategies, and Watch out ero carey grades so they increase in iticuty and graduaty beng you up to exam stares fen ose marks ther exams Trarcses ae packed wih exam sive Altar every few chapters, a Reviow exercise Felps you consolte your teaming with I ots of exam-sive questions Exam prai Mathematis Intemational Advanced Subsidy! ‘vanced Level Decision Mathematis 1 Review exercise [Atul practice paper at the back of ‘ie book hips you prepare forthe real thing vil vili QUALIFICATION AND ASSESSMENT OVERVIEW 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 Mathernatics 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, aC ey Di: Decision Mathematies1 |33}%of1AS —|75 ‘Thour30mins | January and June PapercodeWOMI1/01 | 162 %of AL Fist assessment june 2019 14S: International Advanced Subsidiary, IAL: International Advanced A Level. Assessment objectives and weightings ceri Recall select and use their knowledge of mathematical fact, concepis and techniques ina AO} | variety of contests. ue “Construct rigorous mathematical arguments and proofs through use of precise statements ‘noe. | loscl deduction and inference and bythe manipulation of mathematical expressions, so including the construction of extended arguments for handling substantial problems presented in unstructured frm, Recall select and use their knowledge of standard mathematical models to represent ‘h03_ | situations inthe rea word; recognise and understand given representations involving ron 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. CComprehend translations of common realistic contexts into mathematics; use the results of ‘204 | calculations to make predictions, or comment on the context; and, where appropriate, read 5% page: out a quick “> pages 13-16 the three bin-packing algorithms and understand their strengths and s rmine the ord x, and x, giving your answers to 3 sf. + International GCSE Mathem Ce Pea) ey & 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 di Je fra It can be quite challenging to write a sequence of instructions for someone else to follow accurately. Here are some more examples: [Atthe end ofthe stret turn right and 20 right ver the crossroads tke the Und eater the school, thom GED 1) ED oonrsis ‘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 eyele (in which case the number is ‘unhappy’) Show that: a 70is happy b 4is unhappy a 740? =49 44 297 9+ 72 = 130 PER+O=10 5487289 eae B+ 922045 5070 is happy Pee 242 50 4 is unhappy ns Cr EO 2) ELE) wrcrencroon a Apply this algorithm, 1 Letn=1,4=1,B=1. 2 Print A and B, 3 Let C=A+B 4 Print C. 5 Letn=n+1,4=B,B=C 6 Ifn<5, goto step 3. 7 Ifn=5, stop. b Describe the numbers that are generated by this algorithm, —— —____ eee) Sep [» [a Pi i 1 2 ut 3 2 4 2 5 rales 6 _[Gotostep 3 3 3 4 2 5 sl2|3 6 _[Gotostep3 3 5 4 S 5 4[3al[s 6 [Gotostep 3 3 6 4 8 5 a |Site 6 | Contime to step 7 7 [Stop b This algorithm produces the first few numbers in t Pai ee Sy EDD sere This algorithm multiplies the two numbers A and B. 1 Make a table with two columns. Write 4 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: in the left-hand column, the number that is half of A, ignoring remainders in the right-hand column, the number that is double B 3. Repeat step 2 until you reach the row which has a | 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 4B. Apply this algorithm when: a A=29and B= 34 b A= 66 and B= 56 a 4 B 28 34 7 136 3 272 1 344 Total 286 So 29 x 34 = 986 4 33 | So 66 x 56 = 3696 LGORITHMS Crate a 1 Use the algorithm in Example 3 to evaluate: a 244 x 125 b 125 x 244 © 256 x 123 2. The box below describes an algorithm. 1. Write the input numbers in the form $ and oe 2 Lete=ad. 4 Print ¢. a Apply this algorithm with the input numbers 2} and 14. b_ What does this algorithm do? 3 The box below describes an algorithm 1 LetA=1n=1 3 LetA=d4+2n41 § Irn <10, got02 2 Print 4 4 Letn=n41. 6 Stop. a Apply the algorithm, b Describe the numbers produced by the algorithm, ©® 4 The box below describes an algorithm. 1 Input 4, 5 Letras. LD This gorithm requires yi You to use the modulus 2 Let C=4to3dp. 6 Goto2, Fanta een wat _ isthe positive difference 3 If r-C| = 107 go to7. 7 Printr. fenccascitin 4 Lets=4(r+C)to3dp. 8 Stop. For example: [32-7] =3.8 a Use a trace table to apply the algorithm above when: i A=2S3andr=12 ii A=79andr=10 b What does the algorithm produce? @® How charts You need to be able to apply an algorithm given as a flow chart. ™ Ina flow chart, the shape of each box tells you about its function, Cc) <> Starv/End Instruction Decision 1275 and r= 50 ‘The boxes in a flow chart are linked by arrowed lines. As with an alg you need to follow each step in order. im written in words, ata) Mey EE ED oes ‘The flow chart below describes an algorithm, Box! (sta) Box? Let Bors | Letn=net Box 4 Box 5 No Box 6 Yes Box 7 Stop a Apply this algorithm using a trace table, b Alter box 4 to read ‘Let £'= 3n’ and apply the algorithm again. How does this alter the output of the algorithm? ate E_ | Bxé bl_# E_ | Bxé o 0 7 z Ne o EI Ne 2 4 No 2 a No 3 G No = 2 Ne 4 e No 4 12 | _Ne Ej 70 | _No 5 5 | No é 12 | No GB 18 | _No 7 4 | Ne e 2 Ne 6 16 |_No 6 24 | No = 76 [No = 27_|_No 10 [| 20 | Yes 10 | _30 Output is 2, 4, 6, 8 10, 12, Output is 3, 6, 2, 12, 15, 16, 14,16, 18, 20 21, 24, 27, 30 This gives the first ten multiples of 3 rather than the first ten multiples of 2. LGORITHMS Crate SEO 5) EE vernon This flow chart can be used to find the roots of an equation of the form ax? + bx + ¢=0. Sta Input a. Leld= tac is Yes Print no ral root Yes Prin “equal wots are Lex= Print roots are’, andy, Demonstrate this algorithm for these equations: a 6x?=5x-11=0 b x2-6r49=0 © 4x24 34820 afta [6 [| « [ d@ [deo[d=or] x [ x 6 [= =| 269 [| wo | No = = ofa [se | 4 [acolo « 1 P-e[s [o | w [ve [3 equal roots are 3 ela. [« [4 law 4 [3 [6 [0 [vs no real roots Pai ee Sy onsen Apply the algorithm shown by the flow chart on the right to the data: 1m, = 10, y= 15,us= 9, y= 7, us= Bork What does the algorithm do? Box? »[4|f [rem nese Boxt| 1 | 10 how Box2| 2 Box 3 5 Box 4 Ne Box Box Yes Boxe| 3 Box 2 Box Lea=T Box 4 Yes ak Box 5. 3 — ry Yes Box 6 Yes Be Box2| 4 ‘No Box 7 | Output is 7 igorithm selects the smallest number EID rroncnsame 1 Apply the flow chart in Example 5 to the following equations. a Ae 1204920 b -62 + 134520 © 3yt-8rt 1150 2 a Apply the flow chart in Example 6 to the following sets of data. i my = 28, my = 26, uy = 23, my = 25, us =21 Hh m= 11, w= 8,05 =9, b If box 4 is altered to how will this affect the output? ‘© Which box would need to be altered if the algorithm was to be applied to a list of 8 numbers? LGORITHMS 3 The flow chart describes an algorithm that Crate ‘can be used to find the roots of the equation 2s +x 15=0, a Use a= 2 fo find a root of the equation b Use a = 2010 find a root of the equation, Comment on your answer. ‘The flow chart on the right describes how to apply Euclid’s algorithm to two non-zero integers, aand b. a Apply Euclid’s algorithm to: i 507 and 52 (2 marks) 884 and 85 (2 marks) iii 4845 and 3795 (2 marks) b Explain what Euctie’s algorithm does. marks) 5 The flow chart describes an algorithm. a Copy and complete this table, using the flow chart with A = 18 and B=7. Input a Print b Input a,b, where a > b t Let P= integer part of ab Print h 4 B | ace? Output b Explain what is achieved by this flow chart. © Given that 4 = KB for some positive integer 4, write down the output of the flow chart. Print (4 marks) @ marks) Stop) (1 mark) aD aaa Sy @®) Bubble sort ‘A common data processing task is to sort an unordered list (alist 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. ™ Ina 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 + Ifthe 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 Thisis the bubble sort algorithm: 1 Start at the beginning of the working list and cp 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 SE nee 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, een CEEEED sre ciementsntneust 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 ina fizzy drink rise to in order, the top. This is how the algorithm got. its name, You need to learn the bubble sort algorithm. LGORITHMS Crate sonysis Example QJ stu ‘Use a bubble sort algorithm to arrange the list below into ascending order. 4 18, 37 u 1S 30 GEIST 1S 20 tsk comparsen seap | LED) inyourexam you maybe ated to show S i ‘each comparison for one pass, but generally Bue you will only be required to give the state of 18 24G7 115 30 3rd comparison: swap eae 18 24 1 GPIB)20 Ath comparison: swap 18 241 15 @7 3D) Sth comparison swap 824M 1S 3037 Eadol at pass ‘ter the second pass the Ist becomes 18 i 18 24 3037 ter the tind pas the fe io 15 18 2430.37 AMter th tt 18 18 24 30.37 aches oe tee SRE OIER 15 30 2ncl comparison: leave uth pass the lst 1s 50 the list Is in order. SEEN 2) ID soins A list of 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, ¢ Show the order of the letters at the end of the second pass. ‘a Starting at the begining of the lst, compare the first two letters. Ift are in alphabetical order, leave them in position, otherwise swap them. Continue through the lst, to the end, comparing every pair of letters in the same way. bA_L G HM. Ist comparison: leave M 2nd comparison: swap a G M_ 3rd comparison: leave a G M 4th comparison: leave AG M 5th comparison: swap AG M_ 6th comparison: leave AG M 7th comparison: swap AG th comparison: swap AG ° > o Tea) ey SEIN?) ELD worm Use a bubble sort to arrange these numbers into descending order. 3957-729 TB SD 72 29 17 24 48 39< 57 so swap 57G9 739 17 24.46 30< 7200p) QUEM . , 57 7262317 24 48 38.4 39 sone e e 57 72 38G9D 24 49 39417 soleae 57 72 393907 B48 17 < 24 30 suap 57 72 39.29 287 BB) 17 < 48 sosnop 57 72 3939 24 48.17 ater tse pass: 97 72 3959 24 4017 exercise (OY) us See 1 Apply a bubble sort to arrange each list below into: a ascending order b descending order 13 6 Is M WB 2% 19 iN FE T W O R KS For parti, order ii AS D3 D2 Al B4 Cc? C2. OBB alphabetically then numerically. For each part, you need to show the state of the list only at Poca sees 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 © 3 A list of n items is to be written in ascending order using a bubble sort. State the minimum number of passes needed. b Describe the circumstances in which this number of passes would be sufficient. € State the maximum number of passes needed. Describe the circumstances in which this number of passes would be needed. LGORITHMS Crate © 4 Hereisa 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) @ Quick sort The quick sort algorithm can be used to arrange alist 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. Inaq 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. GED iran itemis equalto the + The other sublist contains items greater than the pivot. pivot itcan goin either subst. 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 be the first pivot. 2 Write down all the items that are less than the pivot, keeping their order, in a sublist. 3 Write down the pivot, 4 Write down the remaining items (those greater than the pivot) in a sublist. 5 Apply steps 1 10 4 to each sublist, 6 When all items have been chosen as pivots, stop. ‘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. Deda a LS ETD sears Use the quick sort algorithm to arrange the numbers below into ascending order. 2 4 42 29-23 13-8 398 2 24 42 29 D 13 6 39 36. Fornnitems, the pivot will be the “th item, rounding up if necessary. There are 9 numbers in thelist so the rip lb 9 5 othe pt the Sth number in the list. Circle it. Write all the numbers less than 23. Write the pivot in a box, then write the remaining numbers. ‘Now select a pivot in each sublist. There are now four sublists so we choose four pivots (circled). We can choose only two pivots this time. Each ‘number has been chosen as a pivot, so the list isin order Example @)) EXITED rrooien-sowme Use the quick sort algorithm to arrange the list below into descending order. 37-20 17 26 44 41 27 28 5017 There are 10 items inthe list so the midpoint willbe 1°*2 5.5, and so the pivot isthe 6th number in the ist. Cirle it Numbers greater than the pivot ae tothe left ofthe pivot, those smaller than the pivot are tothe right, keeping the numbers in ordet Numbers equal to the pivot may go either side, but must be dealt with in the same way each time you do a pass. || \ Two pivots are chosen, one for each sublist. 37 20 17 26 44 @D 2 2 50 v1 | 44 @ [Hi] 37 20 17 @e27 ww 17 Now three pivats are selected. We now choose the next two pivots, even CETTE colour is used here to make eee oes ee [The final pivots are chosen to give the list 9€ used in your exam. "inorder LGORITHMS Crate i 1 Usea 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: ascending order b descending order 2 17 2 30 NW 20 14 7 3 Sort the letters below into alphabetical order using: aa bubble sort b aquick sort NH R K S$ C€ J E M PUL 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 SL 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 5 A list of » tems is to be written in ascending order using the bubble sort algorithm, a Find an expression, in terms of 1, 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) ¢ Decide whether a bubble sort or a quick sort will be quicker in the following cases: 1 2 3 7 4 5 6 203 4 5 6 7 1 Explain how you made your decisions. (4 marks) Cae aca US) © 6 The table shows a list of nine names of students in a dance cass, Hassler | Sauver | Finch |Giannini] Mellor | Clopton | Miranti | Worth | Argi H s F Gc | Me|c |™m iw A a Explain how to carry out the fist pass of a quick sort algorithm to order the list alphabetically. @ marks) b Carry out the first two passes of a quick sort on this ist, writing down the pivots used in each pass. G marks) Challenge Ee CN rca rwovaniow A pack of playing cards has 52 cards, splitinto 4 suits: peal Hearts ¥ Diamonds # Clubs & Spades @ AV.2, KW, A 28, There ae 13 card in each suit, a follows: 1h 4, KO, Ka Ace (1), 2,3, 4,5, 6,7, 8,9, 20, ack (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: 41. Shuffle the pack thoroughly and hold it Face up. 2 Remove the 27th card and place it face up. This isyour 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 orde? ©) 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 « and length , but varying heights, and stacking them into bins of width « and length b, using the minimum number of bins. LGORITHMS Crate 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. ig algorithms are: first-fit, first-fit decreasing and full-bi ™ The three bin-pac Iti useful to first find afower bound forthe number qa of bins needed. There is no guarantee that you will be ‘An optimal solution fs one that cannot be improved upon. Forbin able to pack the items into this number of bins, but it siftell eat you've ounil irasicclad Packing, an optimal solution will use the cen ens Ove rone et c n eoi smallest possible number of bins SE 22) ED emuss Nine boxes of fixed cross-section have heights, in metres, as follows, 03 07 08 O8 10 LI LI 12 15 ‘They are to be packed into bins with the same fixed cross-section and height 21m. Determine the lower bound for the number of bins needed. O3+07+08+08+10+M 411412 +15 285m 85 7 5 = 4.25 bins 2 minimum of 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 item: 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 I each time, Advantage: It is quick to apply. Disadvantage: It is not likely to lead to a good solution. CDE a aan CMe aay LS IIE eccvervcrn Use the first-ft 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) BY) C(l4), D9) BG) 9). GS) HIS) 16)—(7)_—— KS) Bint Bin2 Bin3 Bin4 Bin5 Bing This used 6 bing and there are (24547412 = 26 units of waste of space. ™ 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 lst Advantages: You usually get a fairly good solution. ED sectteop St) Itis easy to apply. TEE aa Disadvantage: You may not get an optimal solution. Example @) TED awirsis Apply the first-fit decreasing algorithm to the data given in Example 13. Sort the data into descending order HUIS) Ctt4) DCO) F¢®) AB) KG) BI7) J(7) ECE) NG) GCS) Bint Bin2 Bin 3 Bind Bin This used 5 bins and there are 2+ 4 = 6 units of wasted spa Cy Crate = 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-it algorithm, Advantage: You usually get a good solution. Disadvantage: It is difficult to do, especially when the numbers are plentiful and awkward. ED cerry A) BY) C10) DUI), B3) FI), G4) HG) 112)—J14)_— KD) The items above are to be packed in bins of size 25. a Determine the lower bound for the number of bins. Apply the full-bin algorithm, € Is your solution optimal? Give a reason for your answer. a = 25=444 So lower bound Is 5 bins. hat sum to) Bint Bin2 Bin3 Bind Bin Bint Bin2 Bin3 Bind Bind © The loner bound is 5, and 5 bins were used, 50 the solution Is optimal rT) Pad Tt Example @) ‘execurWve FUNCTION A plumber needs to cut the following lengths of copper pipe. (Lengths are in metres) A@8) BOS) C4) DUI) EU3) FOS) GOS) HO) 108) 10.9) The pipe comes in lengths of 2.5m. a Calculate the lower bound of the number of lengths of pipe needed. Use the first-fit decreasing algorithm to determine how the required lengths may be cut from the 2.5m lengths. © Use full-bin packing to find an optimal solution, 9 C8408 414411415409 408409408 +09 25 = 3.86 So at least 4 lengths are required — Sorting into descending order CH14), EC.3), DIL, FOOD), HOD), 410.2), N08), BOB), 40.8), (0.2) Bint Bin2 Bin3 Bind Bind | By Inspection, Ci) + DIN) = 2.5 FOS) + M08) + 808) 10.2) + G08) + 0.8) A ful-bin solution is Bint Bin2 Bin3 Bind LGORITHMS Crate 1 Is 4 23 8 27 19 3 2% 3% 3 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 i the first-it decreasing algorithm iii the full-bin algorithm, 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. Picceofmwic [A] B|C|[D/E|F|G|H|I]J]|K]LIM Length (minutes) | 30 | 30 | 30 | 45 | 45 | oo | oo | oo | 0 | 75 | 90 | 120 | 120 a Apply the first-ft 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, ¢ 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. Use the full-bin algorithm to determine the number of days she needs to use. State which. music is played on each day. A small ferry loads vehicles into 30m lanes. The vehicles are loaded bumper to bumper. Vehicle [Length (m) Vehicle [Length (my A car 4m F car 4m. B earand trailer] 7m Glory Lm Cc [lorry Bm H | lony lm D van’ om I van om. EB [tomy 13m J lorry Tim 4 Describe one difference between the firs-fit and full-bin methods of bin packing. (I mark) b Use the first-fit algorithm to determine the number of lanes needed to load all the vehicles onto the ferry. (4 marks) ¢ Use a full-bin method to obtain an optimal solution using the minimum number of lanes. Explain why your solution is optimal (4 marks) ‘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 15m, The following lengths are required. A3m D4m G5m J 7m B3m E4m HSm K8m c4m F4m 1 sm L8m 2 Pa ate US) ‘The lengths are arranged in aseending 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. G marks) © 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) 5 ight computer programs need to be copied onto 40 GB USB sticks. ‘The size of each program is given below. Progam [A|B[C|D|[E|F[G|H Sie Gb) [8 | 16 | i7 [1 | 2 [24 | 35 | 35 a Use the first. decreasing algorithm to determine which programs should be recorded onto each USB stick. (B marks) b Calculate a lower bound for the number of USB sticks needed @ marks) a Consider the programs over ¢ Explain why itis not possible to record these programs ‘on the number of USB sticks found in part b, (I mark) BD Binary search You need to be able to carry out a binary search. 208 in size. 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 frst. = Ina binary search, we look at halving the size of the list each ti 1e we perform a pass. a 1 We call this the pivot. Like with the quick sort, we round this up if itis 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. + Ina binary search, we locate the midpoint of the list using Here is the binary search algorithm to locate an item in a list: 1 Select the midpoint ofthe list using “++ and round up if necessary. This isthe pivot 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 € If the pivot is before the item we are locating, then we look in the second half of the lis. 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. LGORITHMS Crate Use the binary search algorithm to try to locate these names in the list that follows, a Robinson b Davies 1 Acharya 6 Laing rary 2 hncetock > Lose 3 Cheung 8 Robinson 4 Covtzee 9 Saludo 5 Fowler 10 Xiao ; 3 6 Ling Retiree str Ling, so he at reds to is 2 Robinson 3 Sao 4 oo (422 = 25) ar nme 3 Sto Retin before Se othe bt rece tiene 2 Rosson af (222 #19) and nanes The search is complete. Robinson has been found in the list b The middle name is the ("2*" = 5.5) th name 6 Laing Davies is before Laing so the list reduces to: 1 Acharya 2 Blackstock 3 Cheung 4 Coetzee | 3 router The mace rans tbe (222 =) ana 3 cheng Doses oer Chang othe traces to r cocae 2 Fowler 24 CHAPTER 1 The middle name is the ("75 = 13) 2nd name: contr eltetore nope 2 Foner Davies is before Fowler so the list reduces to: 1 Coetzee The list has only one item which Is not Davies. — ED D> = 1_ Use the binary search algorithm to try to locate these names in the list that follows: a Connock b Walkey © 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 a2 bs 13 37 715 918 21 24 49 613 817 10 20 1224 ©® 3 The binary search algorithm is applied to an ordered list of » items. Find the maximum number of times the algorithm is run when n is equal to: a 100 b 1000 © 10000 4a Use the quick sort algorithm to put the list below into ascending order, 1 Adam 6 Ramin 1 Of 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 ess, 20. Hongmei b Use the binary search algorithm to try to locate: ii David i George Jess © 1_ Use the bubble-sort algorithm to sort, in ascending order, the list m7 1 2 8 16 1 giving the state of the list at each stage. (4marks) LGORITHMS &®2 Crate a Use the bubble-sort algorithm to sort, in descending order, the list 25042 31H giving the state of the list on each occasion when two or more values are interchanged (swapped), (4marks) b Find the maximum number of interchanges needed to sort a list, of six pieces of data using the bubble-sort algorithm (2 marks) 8 4 13 79 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. (Smarks) Ml 103-77) 81 OR HKD IS 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. (S marks) bi. Use the firstfit decreasing bin-packing algorithm to fit the data into bins of size 200. (marks) ii Explain how you decided in which bin to place the number 77. (1 mark) ‘Trishna wishes to record eight television programmes. The lengths of the programmes, in minutes, are: 75 100 52 92-30 84D ‘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. € Determine whether she can do this using only 5 DVDs, giving reasons for your answer. (Gmarks) A DIY enthusiast requires the following 14 pieces of wood as shown in the table. Lengthinmeres | 04 [06] 1 | 12] 14] 16 Number of pieces | 3 | 4 | 3 [| 2 | 1 [1 ‘The DIY store sells wood in 2m and 2.4m lengths. He considers buying six 2m lengths of wood. a Explain why he will not be able to cut all of the lengths he requires from these six 2m lengths (marks) b He eventually decides to buy 2.4m lengths. Use a first-fit decreasing bin-packing algorithm to show how he could use six 2.4m lengths to obtain the pieces he requires (4 marks) € Obtain a solution that requires only five 2.4m lengths (4marks) 25 Pe ata US) 7 The algorithm described by the flow chart below is tobe @JESY) this question uses the applied to the five pieces of data below. eae Re CATEEN a t= 6.1, 1 = 6.9, uy = 5.7, us = 4.8, Us = 5.3 is the positive difference between xand y,eg.|5~ 61] = LL a Obtain the final output of the algorithm using the five values given for t 10 us. (marks) b In general, for any set of values 1 to ws, explain what the algorithm achieves, (2 marks) Start Box! Box? ieiet Box Mels—4) is Bord -— Temp?” state what the algorithm achieves now. (i mark) 8 A plumber is cutting lengths of PVC pipe for a bathroom. ‘The lengths needed, in metres, are: 03 20 13 16 03 13 02 Of 20 os The pipe is sold in 2m 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 (Amarks) 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. (3marks) Does the answer to part b use the minimum number of 2 m lengths? ‘You must justify your answer. (2 marks) LGORITHMS Crate 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, (S marks) 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 (4marks) ¢ Use the binary search algorithm to locate the name Kim in the list you obtained inb. You must make your method clear. (4marks) a cea LS eed 1 Analgorithm is a finite sequence of step-by-step instructions carried out to solve a problem. 2. Ina 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 Ina 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. Ina 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 @ 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 Abinary search will search an ordered list to find out whether an item is in the list. fit isin the list, it wil locate its position in the list. Ina binary search, the pivot is the middle item of the list. Ifthe target item is not the pivot, the pivot and half of the list are discarded. The list length halves at each pass. The middle of items is found by "+, rounding up fnecessary. ee eed After completing this chapter you should be able to: know how graph: s can be used to create mathemati s > pages30-33 | | —= ~~ Beam with basic graph theory terminology rpuges3e3e il YY C en ecaiecdtesscne ~~ |) Mitsukoshimae ) 11), Uy;LLBJUB) aE Nihombashi Re ( Kyobashi | The 22 — Ginza- ver 10M F points esses ne seman. i is graph models an underground # train network. The lines show which stations are connected but thei lengths do not represent distances neal life, Hibiya Line ii) cyfH a a 08/109! 07 7A SL AR Fp rr 10 © come: Lo, Explain why a Possible spanviing trees are: e > 4 F E B > 4 F € e There are many other possible spanriing trees. = Acomplete graph is a graph in which every vertex is directly connected by a single edge to each of the other vertices. CEEED the complete graph with w vertices is written a5 Ky. K; K, Ke = Isomorphic graphs are graphs which show the same information but may be drawn differently. me asi PUEe Un aa Ec) 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. Gx) =D «~~~ Show that the two graphs below are isomorphi Both graphs have the same number of vertices First graph Second graph Vertex | Degree | Vertex | Degree N 4 Ss 4 P 3 u 3 K 2 v 2 ie 2 a 2 L 1 R 1 M 1 ir 1 2 1 w 1 N can be paired with 8, P can be paired with U, K can be paired with V. L can be paired with X. J can be paired with R M can be paired with T, Qcan be paired with W. Since the pairing can be. graphs are isomomphi If graphs are isomorphic 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 4 r R B M @ c N Ss D L v E @ w F P w G K x Ure UO a cy raid CEE) BED cores 1 State which of the following graphs are trees. a 7 b . N e : 4 | @® 2 There are 11 spanning trees for the graph shown below. Draw them all 4 a fo F D 3. For the graph on the right, identify a complete subgraph B that has 4 vertices, c 4 D F E 4 Identify which of graphs 4, Band Care isomorphic to graph D. . . ~ | Nb ; © 5 4 Define the terms: i tree (1mark) spanning tree, (mark) b Explain why itis not possible to construct a spanning tree for this graph (1 mark) a Draw Ky (2 marks) bb State the degree of each vertex in the graph K;, (Lmark) ¢ Find the total number of edges in the graph Ky. (2 marks) ‘graphs with three edges. sree there are 11 such graphs. A me asi) GRAPHS AND NETW ry @ 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. SEES) LED orerrevn Use an adjacency matrix to represent this graph. A D The matrix associated with a weighted graph is called a distance matrix. = Ina distance matrix, the entries represent the weight of each arc, not the number of arcs. Example @) EEE wrenpneranon Use a distance matrix to represent this network. 8 23 Een aL) raid Example @) EXE wresencraron Use a distance matrix to represent this directed network. EXE rec 1 Usean adjacency matrix to represent the graph below. D fe 2. Draw a graph corresponding to each adjacency matrix. a ABCDE 5 A BCD 4/o 1 0 1 0 4/o 1017 Bi oui Bll 0 0 1 clo 10 2 0 co 0 21 pit 1201 er) z/o 10 1 0 © A BCD a ABCD 4/o 101 4/o 201 bli o 1 1 B)2 0 1 0 clo 104 co 101 Pr) Dil 0 1 0 Cre aiid CSU aN Lcd 3. Draw the network corresponding to each distance matrix. ees not a distance matrix. 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) ‘© Draw the spanning tree referred to in part b, (2 marks) 1 A,B, Cand D are four towns. The distance matrix shows the direct distances by road between the towns in kilometres. Draw a weighted graph to show this information. Ure UO a cy raid 2. Which of these graphs are isomorphic? a b an | © 3a Drawa 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 i not connected and simple fii, not connected and not simple. AY x 4a Describe the difference between a distance matrix and an adjacency matrix. b Use a distance matrix to represent the network below. e 30 € Drawa spanning tree for this network and state the weight of your spanning tree ©® 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 2 in this digraph. cy Ne asi © 7 The diagram shows a graph. Identify: ia path from B to D fi a cycle © Sketch i a spanning tree for this graph fia complete subgraph of this graph. Write down the valeney of vertex A PUEe Un aa Ec) 8 a Explain why itis not posible to dra a graph with exaetly four vertices with degrees 3, 1, 2 and 1 A connected graph has exactly four vertices and 10 edges, The degrees of the vertices are A? = 3k, k-+ 1, 8k and k—4 respectively. b Find the value of &. © 9% A Hamiltonian cycle for this graph begins AGB. 4 D a Complete the Hamiltonian eyele. G b For the graph below, write down a Hamiltonian cycle starting from A. 4 B (i mark) (mark) (mark) (1 mark) (2 marks) (i mark) (3 marks) (2marks) (2 marks) Ure UO a cy raid mNovarioN, CREATIVITY Cars ‘The diagram shows a connected graph. The regions of the graph are shaded in different colours. Let V denote the number of vertices, E denote the number of edges, and R denote the number of regions ina connected graph. a For the graph above, verify that + R— 'b Draw graph with one vertex and four edges, and verify that V+ R= E=1 ‘© Explain why the relationship + R- = 1 holds for any graph with one vertex. 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 Gis a connected graph, and that G’ is the graph formed by contracting one edge of G, show that if the relationship V+ R-E= Lholds for G’, then it must hold for G. @ Using your results from parts cand d, show that the relationship V+ R- E= holds forall connected graphs. eed 1 A graph consists of points (called vertices or nodes) connected by lines (edges or ares). 2 Ifa graph has a number associated with each edge (usually called its weight), then the graph is known as a weighted graph or network. 3A 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 vertexis ‘odd it has odd degree. a7 rome asi PUEe Un aa Ec) ‘Awalk is a route through a graph along edges from one vertex to the next. 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. Acyele 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 AHamiltonian 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 Aloop is an edge that starts and finishes atthe 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 x the number of edges. As a consequence, the number of odd nodes must be even. This result is called Euler's handshaking lemma 16 Atree is 2 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 Acomplete 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 Ina distance mat , the entries represent the weight of each arc, not the number of arcs. 3 ALGORITHMS Os 2) BT cae After completing this chapter you should be able to: © Use Kruskal 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’ algorithm to find the shortest path between two vertices in a network > pages 64-71 Map apps model roads as arcs on a graph, and add weightings depending on traffic conditions. By finding the shortest path on the graph, the app can compute the quickest route toa destination a State the order of vertex C. b Draw a distance matrix for this network Find a spanning tree with total weight less than 40. State clearly which arcs are included in your spanning tree and its total weight. ‘Decision 1 chapter 2 Ce arse} PLES as) 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. ast In 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. = Kruskal’s algorithm can be used to find a minimum spanning tree: BEEN) ELESD ccorcsncnon Use Kruskal’s algorithm to find a minimum spanning tree for this network. List the ares in the order that you consider them. State the weight of your tree. Sarat Dev alien ne. 40. a BD(6), AB(7), CDE). Start with DE. um connector. MeO Rear Gry ai Add BC. Canes Reject AD (it would make the cycle AEDA). Add BD. All vertices are connected so this is a minimum spanring tree, Its weight Is 5 +446+5 = 20 GE?) ED Use Kruskal’s algorithm and show that there are four minimum spanning trees for this network. State their weight. By inspection, the order of the arcs is ADI), BCC), ACO}, CDA), EFI), CEC) DE\\2), DFU2), BE) Start wth AD 4,8 D Add BC. Ca arse Add AC Reject CD (it forms a cycle ACDA). Add BF. Add CE. (using AC and CE} The other three solutions are: using AC and DE) (sing CD and CE) (using CD and DE) Th MeL ery weight of each tree is, 8484104141249 LS Tear} COGaitoky EID reanesnrne 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, State what is meant by: i atre (mark) iia minimum spanning tree. (1 mark) b_Use Kruskal’ algorithm to find a minimum spanning tree for this network. (Gmarks) ¢ Draw the minimum spanning tree found in part b. (1 mark) State, giving a reason, whether or not this minimum spanning tree is unique. (mark) ©® 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, arse} LES a ard 4 The diagram shows nine villages and the distances between them in kilometres, A cable TV company plans to link up the villages, 28 Haversham Pluntpirce AT Edwards Shrewsbury Find a minimum spanning tree for the network using Kruskal’ algorithm. List the ares in the order that they were added to the tree. (4marks) b Use your answer to part a to find the minimum length of cable required to link all the villages together. (1 mark) @® Prim’s algorithm * rims algorithm can be used to find a minimum spanning tree: 1 Choose any vertex to start the tree. ip (acta as 2 © Select an are of least weight that joins a vertex already esate sgmanracar eee in the tree to a vertex not yet in the tree. cipriineateteers # If there isa choice of ares of equal weight, choose any considering adding an are from of them. an unconnected vertex tothe 3 Repeat step 2 until all the vertices are connected. graph, a cycle wll never be formed and so we don't need 4 List the arcs in the order that they were added. to check for cycles. xx) sau 5 1 EDD ore risatgonnmusng CaP ; input abe : Y z which is which. Use Prim’s algorithm to find a minimum spanning tree for the network above. List the ares in the order in which you add them to your tree. Te SR) ai 5 Choose to start the tree at A Add the arc of least weight, AF, to the tree. GBD wictice that with Prim’ algorithm the tree always grows ina connected fashion. The arcs do not jump around as they sometimes do with Kruskat’s algorithm, Ce arse} LES a ard IED rons same 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, in kilometres, between eight weather monitoring stations, The eight stations need to be linked together with underground cables. a Use Prim’s algorithm, starting at 4, to find a minimum spanning tree. You must make your order of are 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) ‘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, (marks) ‘© Unforeseen problems with the link between villages 1 and X mean that the cost of connecting them rises to $3400, Explain how this affects your minimum spanning tree. (2 marks) 5 a Explain why it is not necessary to check for eycles when using Prim's algorithm. (1 mark) SKILLS REASONING ‘ARGUMENTATION b Use Prim’s algorithm, starting at , to find a minimum spanning tree for this network. ‘You must make your order of arc selection clear. (3 marks) © State, with a reason, whether this minimum spanning tree is unique. (2marks) ESR) COGaitoky Ey Networks (especially large ones) are often described using distance matrices. This isa convenient 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. 1 The distance matrix form of Prim’s algorithm is: CEE) ED os Apply Prim’s algorithm to the distance matrix to find a minimum spanning tree, Start at A. The first are is AC Ce ari) Te ay The minimum spanning tree ts: 4 a Ez Clans Its weight is 12 + 23415471 = 121 The arcs added were AC, AD, BD, BE. LS Tear} COGaitoky 59 GE) ED erence 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, 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 784 140.8 Nottingham | 2624 39.2 89.6 1184 Lincoln 160 59.2 = 144 137.6 Stoke 784 89.6 144 704 Manchester 140.8 184 137.6 704 = 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 ares in order of selection and state the weight of your tree. B®) 3 The matrix shows the costs, in euros per 1000 words, of translating appliance instruction manuals between eight languages. Fl a7 61 67168 73 G/- 7% 9 Isl 199 - -~ 2 H | 2 - BK a Use Prim’s algorithm, starting from language D, to find the cost of translating (marks) 10 the seven other languages. an instruction manual of 3000 words from D it ara} LES a ard b- Draw your minimum spanning tree. (mark) A manual is written in language £ 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. © Givea reason why: i it might be decided not to translate directly from Eto G ii it might be decided to translate directly. (2 marks) 4 The table shows the distances, in kilometres, between nine oil rigs and the depot . Pipes are to be laid to connect the rigs and the depot. a Use Prim’s algorithm, starting at, to find ¢ minimum spanning tree for the network. You must make the order of are selection clear. (marks) bX must now be directly connected to D and to F. Based on this condition, use Prim’s algorithm, starting at 4, to find a minimum spanning tree, You must make the order of are selection clear. (2 marks) © 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. marks) © 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. 2 Select an are of least weight which joins a new vertex Do not confuse the ae ate eal nearest neighbour algorithm with ; . Prim’s algorithm. In Prim’ algorithm 3 Repeat step 2 until all of the vertices are added Ret Sen isnt erates the vertices in your growing tree. The path may not be optimal, but isa key part in the Inthe nearest neighbour algorithm, travelling salesman problem. Parise curictere tenet athe In Example 4, we saw Prim’s algorithm applied toa last vertex chosen. distance matrix. Let us now see the nearest neighbour algorithm applied. MeO Rear Gry ai Cesamote GY snus a Apply the nearest neighbour algorithm to the distance matrix to find a short path connecting all vertices. : Start at A. B c 5 7 4 + c|® = 2887 [| 4 dila3 6 @ 75 oo 1 2a) Annee BB BF do] 6 @ =. 62 CHAPTER 3 Te ay 2 3 1 Bc DE ae a pla - #7 6 7” The path ereated is: 4 B E 12 28 Its weight is 12 + 28 + 15 + 71 = 126 LS Tear} COGaitoky 1 Apply the nearest neighbour algorithm to find a short path connecting all vertices for the following matrices: a Startatd b Startat § 2 Afier applying the nearest neighbour algorithm, adding an are 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 BOC DE FE a | 2 30 215 B | 20 10 32 16 cfs wo - 3519 pb} 32 25 15 20 34 E 2 35 16 Flis 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. 4A BC DE Al 153 98 124 115 B | 153 74 131 149 c | 98 7 82 103 D lim 131 82-134 E 15 149° 103-134 Ce arse} LES a ard €B) 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. CESED vikstrais stra’s algorithm can be used to find the shortest path ‘pronounced ‘Dike-Stra! from S to T through a network: The algorithm makes use of labels, Start at the initial vertex ‘and move through 1 Label the start vertex, S, with the final label, 0. 2 Record a working value at every vertex, ¥, that is directly connected to the vertex, that has just received its final label, ¥. ‘© Working value at ¥ = final label at + weight of are X¥ fie enae piatlag ‘If there is already a working value at ¥, itis 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. (IP two vertices have the same smallest enone ETE working value, either may be given its final label first.) hae te Final label ils 4 Repeat steps 2.and 3 until the destination vertex, T, receive: fixed’ and its working final label. values are no longer 5 To find the shortest path, trace back from Tto S. If B already conser oun lies on the route, include are 4B whenever: Mineuey und the final label of B = final label of 4 = weight of are 4B estination vertex is reached, EID Seco algorithm using GeoGebra, wun Use Dijkstra’s algorithm to find the shortest route from S to Tin the network below. CEEEED crate ne orig cea you aa eet Tat Vertex [ Order of labelling | Final label Working values MeO Rear Gry The network A D ai A 7 4 7 ea Ce arse} Te ay 5 4 5, D +/e s-TpY<« PEE 3 64 8 4 5, D = a 14 12 a 14 2 a[4[s 5 4 5 [sje] ———+ 1/18 sTeVs EE” ~~ \e QD vos corct needa dont ot 7 of diagrams to show your working. a 2 evel ‘Working through just one diagram ier and completing all the boxes will claj2 12 make the method clear. A + Example 7 MeO Rear Gry COGaitoky The length of the shortest route from Sto Tis 1 To find the shortest route, start at T and trace back looking at final values and are lengths. Check the ares into T: 11 2 # 12 50 CTs nat on the route, M1 4 6 s0 BT's not on the route. 1-8 To get to Tin I! you must have come from D, nye working back from D. The working is 50 DT'is on the route, ea) to explain how you obtained your n-8= or final route, you donot need to 8-424 BD show all ofthis working, You can 4-222 CB identify the shortest route from your fully labelled diagram by inspection, 2-0-2 sc So the shortest route is SCBDT, length 11 = You can use Dijkstra’s algorithm to find the shortest route between the start vertex and any other vertex with a final label. reuse Use Dijkstra’s algorithm in this network to find the length of the shortest route: a from AtoH b from Ato G. List the routes you use. ‘The final diagram looks lke this. It shows all the working needed to make the method clear. ‘The lowest working values at Band at Care both 8, 0 iS 15 AGE either can be chosen first. 321 8 > 6 8 To 8 DES 2 OE SNP fa 16 15) a 3 8 6 3 S FEE Check that your method ie bo «an be followed cleary. Ce ark} LES a ard The length of the shortest route from A to Hi 29. There are two shortest routes: ABDEH and ACFH, b From the diagram, the length of the shortest route from 4 to Gis 24 The route is ABDG G already has a final value, so you do not need to implement the algorithm ‘again. Just work backwards from G to 4. * Itis 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, EEEION ©) ED essorncscmeicanon The network below represents part of a road system in a city. Some roads are one-way and these are indicated by directed ares. The number on each are represents the time, in minutes, to travel along that are. a Show that there are two quickest routes. Bg D4 Le from A to I. Explain how you found : your routes from your labelled diagram. > PS AM AS 7 Road His closed due to roadworks. 5 4 5 E b Find the quickest route from A to [, avoiding HI. a The final diagram looks like this: te] 4 PE) on fas ie 5 4 oe “fis . 5 *\cCeE Z Fie lia 5 Hl6h7 Y 14 19 17 fz 8 z 2 2 7 Tey. EEE TPE [7s 7 bows GED creminers check the orderin which the GERENPTNENS numbers appear inthe list of working values. Notice that 5 does not appearas a working value Itis 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 LS Tear} COGaitoky The bo quickest routes are ACDFGHI amd ACDEFGHT CLEEDD tis cvestion you since ‘are told to explain how you found HL HE the route from your diagram, so you on GH need to show these calculations. FG FG DF EF cD DE Ac on AC Both are of length 19 minutes. b Removing HI from the network would leave a final value of 20 at Z Start at [and find the route of length 20. 4 EL 5-2-3 CD 2-0=2 AC So the quickest route from A to I, avoiding HI, is ACDEI, of length 20 minutes. EXE ED oar 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 ® 2 The network shows part of a road system in acity. The number on each are gives the time, in minutes, it takes to travel along that are. Use Dijkstra’ algorithm to find: a the quickest route from 4 to @ and its length b the quickest route from A to L and its length ¢ the quickest route from M to 4 and its length the quickest route from P to A and its length. aie} 3. Use Dijkstra’ algorithm to 4 aor LES a ard the shortest route, and its length, from A to Fin this directed network. y The network represents the lengths, in metres, of all the roads in a building site. A bulldozer is needed for one day at T. There are two bulldozers available on-site, one at Sy, and the other at S: One of the two bulldozers will be moved to T In order to minimise the cost it is decided to move the bulldozer that is closest to T. Use Dijkstra’s algorithm to determine which bulldozer should be moved. 4 (7 marks) Stuer Its possible to solve this problem with only one application of Dijkstra’ algorithm. Think carefully about the starting point. a Use Dijkstra’s algorithm to find the shortest route from A to H. Indicate how you obtained your shortest route from your labelled diagram, (6 marks) b Find the shortest route from Ato HyiaG. (2 marks) ¢ Find the shortest route from Ato H, not using CE, (2 marks) Use Dijkstra’s algorithm to find the shortest route from S to Tin this directed network. State the length of your route. (6 marks) LS Tear} COGaitoky @®) 7 A navigation app uses real-time data to determine driving times between different locations. The diagram shows a network of driving times, in minutes, along roads joining ten locations. a Use Dijkstra’s algorithm to find the quickest route from $ to T, and state the total driving time for this route. (6 marks) A driver is following this quickest route, Due to traflic 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: before the start of the journey ii when the driver reaches point H. (4 marks) Chapter review @) PROBLEM-SoLUING © _1 The network represents a theme park Kiddizone _ g00 Scaryzone with seven zones. The number on each are shows a distance in metres, ‘Tranwways are to be built to link the Entrance seven zones and the entrance. a Find a minimum spanning tree using: i Kruskalsalgorithm —(4marks) ii Prim’s algorithm, starting at the putas entrance. (4marks) ‘You must make your order of are selection clear. b Draw your tree and state its weight. (2 marks) GP) 2 The network represents eight observation points in a wildlife reserve and the possible paths connecting them, The number on each are is the distance, in kilometres, along that path. It is decided to link the observation points by paths but, in order to minimise the impact on the wildlife reserve, the least total length of path is to be used. a Find a minimum spanning tree for the network using: i Prim’s algorithm, starting at (4marks) fi Kruskal’s algorithm. (Amarks) In each case, list the ares in the order in which you consider them. Casi LES a ard 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) 3. The table shows the distances, in mm, A B C D E F between six nodes A to Fin a network. at 87 a. Use Prim’s algorithm, starting at 4, Bia = a TS 8 to find a minimum spanning tree for e)m i a this table of distances. Dp | a7 il 67 a7 ‘You must explain your method = a e 4 aL Di a carefully and indicate clearly the F M7 22 order in which you selected the ares. (marks) b Draw a sketch showing the minimum spanning tree and find its length. (2 marks) © 4 Itisintended 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 387 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 ares in your final tree, (marks) b Calculate the minimum total length of cable required. (2 marks) @s A pe we 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 | Es | EK FI | Fs | Gt [HK] JK 29 [27 [30 [19 | 9 | 26 | iv [as [8 [12 | 24 | 20 | 1a | 14 | 22 [26 a Use a quick sort to write these ares in order of weight, smallest first. (4 marks) @« (REATITY LS Tear} COGaitoky b Use Kruskal’s algorithm to find a minimum spanning tree for this network. (GB marks) € Draw your minimum spanning tree and state its total weight (2 marks) For any connected network, = number of edges in the minimum spanning tree v= number of vertices in the network. Write down the relationship between ¢ and v (marks) A company is to install power lines to buildings on a large industrial estate. The lines are to be laid by the side of the roads on the estate, The estate is shown here asa network, The buildings are designated A, B, C, ... Nand the distances between them are given in hundreds of metres. The manager wants to minimise the total length of power line to be used. a Use Kruskal’ 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) ‘A weighted network is shown. The number on each are indicates the weight of that are. a Use Dijkstra’s algorithm to find a path of least weight from 4 to K. State clearly’ i the order in which the vertices were labelled ii how you determined the path of least weight from your labelling. b List all alternative paths of least weight. © Describe a practical problem that could be modelled by the network and solved using Dijkstra’s algorithm, a arse} LES a ard © _8 The network here shows the distances, in kilometres, between nine cities. Use Dijkstra’s algorithm to determine the shortest route, and its length, between cities Sand 7. You must indicate clearly the order in which the vertices are labelled and how you used your labelled diagram to decide hich cities to include in the shortest route, @® 29 4 Find a minimum spanning tree for this network using: Prim’ algorithm ecard Kruskal’ algorithm, {86087808 fy Compare the application of the two algorithms in this case. State which is easier. € Describe a condition under which Prim’s algorithm may be quicker to apply than Kruskal’s algorithm 10. The table below shows the flight distances, in kilometres, between eight cities: Alice Springs (4), 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 Starting at 4, 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 vist all eight cities, starting from C. One way of visiting all eight cities isto create a minimum spanning tree, then starting at C, traverse each are twice. Another way of visiting all eight cities is to use the nearest neighbour algorithm and, once completed, to return directly to C. Using your answers to part a and b which method would give the shortest way of visiting all ight cities, SR ad Pata eed 1 Aminimum 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 rejectit. 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. ¥, that is directly connected to the vertex that has just received its final label, X: final label at V + 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 4B on the route if Bis already on the route and final label B — final label 4 = weight of arc 4B 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 Itis possible to use Dijkstra’s algorithm on networks with directed arcs, such as a route with one-way streets, a Review exercise 1 An algorithm is described by the flow chart below. Rela > i Lacauthto2dp t TLetd=largestinteaer = ¢ t Latent Lafmane Tato=h Laher a Given that a= 645 and b = 255, draw a table to show the results obtained at each step when the algorithm is applied. © b Explain how your solution to part a would be different if you had been given that a= 255 and b= 645. (2) € State what the algorithm achieves, (2) @©) 4 + Decision 1 Sections 1.1, 1.2 Nine pieces of wood are required to build a small cabinet. The lengths, in om, of the pieces of wood are listed below. 10.15 55 40 75 25 55 60 55 Planks can be purchased in one-metre lengths, fala estat a Calculate a lower bound for the number of planks that will be needed to make the cabinet. Q b Use the first-fit bin packing algorithm, to determine how many planks are needed. 8) © Use the full-bin algorithm to determine how many planks are needed. @ 4d Explain why it is not possible to make the cabinet using fewer planks than the number found in parte. Q «Decision 1 Section 1.5, 55 80 25 84 25 34 17 75.3 5 a The list of numbers above is to be sorted into descending order. Perform a bubble sort to obtain the sorted list, giving the state of the list after each complete pass, @ ‘The numbers in the list represent masses, in grams, of objects which are to be packed into bins that hold up to 100g. b Determine the least number of bins. needed. a © Use the first-fit decreasing algorithm to fit the objects into bins which hold up to 100g 45 56 37 79 46 18 90 81 SI a Using the quick sort algorithm, perform one complete iteration towards sorting these numbers into ascending order. @ b Using the bubble sort algorithm, perform one complete pass towards sorting the original list into descending order. 8 ‘Decision 1 Sections 1.3, 1.4 Palast as @® 5 ‘The following list gives the names of some students who have represented Britain in the International Mathematics Olympiad. Roper (R), Palmer (P), Boase (B), Young (Y), Thomas (1), Kenney (K), Morris (M), Halliwell (FH), Wicker (W), Garesalingam (G), Use the quick sort algorithm to sort the names above into alphabetical order. (4) # Decision 1 Section 1.4 ‘A simple graph has 6 vertices. a Explain why if the graph has two vertices of order 5, it cannot have any vertices of order I Q) b_ Draw a simple graph with exactly six vertices with degrees 4, 4,3, 3, 1 and | @ + Decision 1 Section 2.2, a Draw the graph Ks a b State the number of edges ina minimum spanning tree for the graph K;, o € State the number of edges in a Hamiltonian cycle for the graph Ks, o + Decision 1 Section 2.3, a Define a Hamiltonian cycle @ A Hamiltonian cycle for this graph begins AB. B c 4 1D é E b Complete the Hamiltonian cycle. 4) + Decision 1 Section 2.2 ®» 10 ‘The diagram shows 7 locations 4, B, D, E, F and G which are to be connected by pipelines. The ares show the possible routes. The number on each are gives the cost, in thousands of euro, of laying that particular section. a Use Kruskal’ algorithm to obtain a minimum spanning tree for the network, giving the order in which you selected the arcs. b_ Draw your minimum spanning tree and find the least cost of pipelines. (3) + Decision 1 Sections 2.3, 3.1 © a The table shows the distances, in metres, between six nodes 4, B, C, D, Eand Fof a network. i Use Prim’s algorithm, starting at 4, to solve the minimum connector problem for this table of distances. Explain your method and indicate the order in which you selected the edges. () fi Draw your minimum spanning tree and find its total length. 5) 7 8 State whether your minimum, spanning tree is unique. Justify your answer, @ b A connected network NV has seven vertices, i State the number of edges ina minimum spanning tree for N. (1) A minimum spanning tree for a connected network has n edges. State the number of vertices in the network, a € Decision 1 Section2.3,3.3 © 11 The matrix represents a network of roads between six villages A, B,C, D, and F Each value in the table represents the distance, in km, along these roads. 4 B c D E F a Show this information on a diagram. 8) b_ Use Kruskal’ algorithm to determine the minimum spanning tree. State the order in which you include the ares and the length of the minimum spanning tree. Draw the minimum spanning tree @ € Starting at D, use Prim’s algorithm on the matrix given to find the minimum. spanning tree. State the order in which you include the ares. @ Decision 4 Sections 2.4, 3.1, 3.3 fala estat © 22 a Describe two differences between Prim’s algorithm and Kruskal’s algorithm, 2 b Find a minimum spanning tree for the network below using: i Prim’s algorithm, starting with vertex G @ ii Kruskal’s algorithm. @ In each case, write down the order in which you made your selection of ares. © State the weight of a mi spanning tree, wo ‘Decision 1 Sections 3.1,3.2,3.3 a Use Dijkstra’s algorithm to find the shortest route from Sto Tin this, network, Show all necessary working by drawing a diagram. State your shortest route and its length. O) b Explain how you determined the shortest route from your labelling. (2) © Itis now necessary to go from Sto T via H, Obtain the shortest route and its length. Q Decision 4 Section 3.5, fetes © 14 The diagram shows a network of roads. a Use Dijkstra’s algorithm to find Erica wishes to travel from A to Las the quickest route from 4 to Land quickly as possible. The number on each explain clearly how you determined the edge gives the time, in minutes, to travel quickest route from your labelling. along that road, b Show that there is another route which also takes the minimum time. ‘€ Decision 1 Section 3.4 1a Explain why any simple graph with two or more vertices must contain at least two vertices with the same degree. b The diagram shows an edge-colouring of K,, where every edge has been coloured either red or blue. 4 B F c E D For the above edge-colouring, itis possible to find sets of three vertices which are all linked by edges of the same colour. Here are two examples: er ; : same colour. Hi Prove that for any edge-colouring of the Ki, with two colours it will be possible to find a set of three vertices which are al linked by edges of the same colour. By constructing a suitable graph, show that this result isnot true for K, 2.2.2.3 73 fala estat 2 Peter wishes to minimise the time spent driving from his home at H, to a campsite at G. The network above shows a number of towns and the time, in minutes, taken to drive between them. The volume of traffic on the roads into G is variable, and so the length of time taken to dive along these roads is expressed in terms of x, where x= 0, Use Dijkstra’ algorithm to find two routes from H to G (one via A and one via B) that minimise the travelling time from HT to G. State the length of each route in terms of x. bb Find the range of values of x for which Peter should follow the route via A. H ‘€ Decision 1 Section 3.5 4 ROUTE | yd seat) Pe ead ‘After completing this unit you should be able to: © Use the orders of nodes to determine whether graph is Eulerian, semi-Eulerian or non-Eulerian +p © Use the route inspection algorithm to find the shortest route in a network irre ara’ 1a Find the sum of the order in this graph a on the sum of the orders and the number of arc » the num of add nodes. Explain why the number of odd no any graph must be even, @) Eulerian graphs You can determine whether a graph is Eulerian, semi-Eulerian, or non-Eulerian, by considering the degrees of the vertices. ™ An Eulerian graph or network is one which contains a trail that includes every edge and starts and finishes at the same vertex. This trail is called an Eulerian circuit, Any connected graph whose vertices are all even is Eulerian. ® Asemi-Eulerian graph or network is one which contains a trail that includes every edge but starts and finishes at different vertices. Any connected graph with exactly two odd vertices is semi-Eulerian. Ca ate} Cua eas ‘The degree ofa vertex isthe number of ar that are incident to it Vertices with even degree are called even vertices, and those with odd degree are called odd vertices. € Decision 1 Section 22 ‘called an Eulerian cycle. However, itis not a true cycle since, in general, vertices will be visited more than once. CED aes vertex and end at the other odd vertex. Eulerian and semi-Eulerian graphs can be drawn without removing your pen from the paper, and without repeating any arcs. start. End start ci Exactly wo vertices have odd degree, so this All vertices have even degree, so this graph is Eulerian. An Eulerian cycle covering every edge exactly once can start and end at any vertex More than two vertices have odd degree, so this traph is neither Eulerian nor semi-Eulerian. I is ot possible to draw this graph without removing ‘yout pen from the paper or repeating an edge. GOR 1) ED wrsrenerron graph is semi-Eulerian. tral covering every edge exactly once must start at one odd vertex and end atthe other aA — This graph is not connected so ts neither Euler to draw this graph without removing your pen from the paper or repeating an edge. nor semi-Eulerian. t's not possible a State whether this graph is Eulerian, semi-Eulerian or neither. b If possible, find a trail that traverses each edge of this graph exactly once, Ca east Cais 2 [Netex [a] [Cl D[E [Degreel2[s]3]ela There are exactly two odd vertices, so the—— graph is semi-Eulerian we ata eats GEEIL2) ED esscancon A connected graph has $ nodes. The orders of the nodes are 4, 6, 3, p and 2. a Explain why the graph cannot be Eulerian, b Explain why the graph must be semi-Eulerian, © Give the number of edges contained in the network in terms of p, 4 Draw a graph with two nodes which is neither Eulerian nor semi-Eulerian, 1a The graph hs Eulerian since n odd node. It cannot be very node of an Eulerian graph must have even order b The number of odd nodes must be even 20 p must be odd, The graph will have exactly two odd nodes, 50 is semi-Evlerian © Sum ol the orders of the nodes = 2 x number of edges. Cans dae on 1 List the valency of each vertex and hence determine if each of the graphs below is i Bulerian ii semi-Eulerian ii neither. For those that are Eulerian or semi-Eulerian, find a route that traverses each edge exactly once. a B E b i Ie L 4 é R 7 c Ir K 7 » o x Cm arse} Cua eas 2 a Show that each of the graphs below is Eulerian, b Ineach case, find a route that starts and finishes at 4 and traverses each edge exactly once. i £ @ ii 4 B B c c E tI A e F ¢ D 3. a Show that each of the graphs below is semi-Eulerian, b Ineach case, find a route, starting and finishing at different vertices, that traverses each edge exactly once. ik s ii Z i : Tr v H Me w 1. x GB) 4 a Explain why itis impossible to draw a graph with 6 vertices such that the orders of the nodes are 4, 5, 6, 7, 8 and 9, (2 marks) b A.connected graph has 5 nodes and 9 ares. The ord 2x, dv - 1, dx and 6x. i Find the value of x. ii State whether the graph is Eulerian, semi-Eulerian or neither, giving a reason for S of the vertices are 2x +1, ‘your answer. (4 marks) ¢ Draw a semi-Eulerian graph with 6 vertices. (2 marks) 5 Here is the adjacency matrix for a graph ABCDE a State, with reasons, whether of not the graph is connected. “ajo 1 100 b State, with reasons, whether the graph is Eulerian, Bll o 10 0 semi-Eulerian or neither. cli 10 0 0 ¢ Draw the graph. Dio ooo 1 elo 0010 ® 6 Here is the adjacency matrix of a connected graph. _|4 BODE Determine whether the graph is Eulerian, semi-Eulerian Ajo bo oO or neither, giving reasons for your answer. Bi/t oo 1 0 clooo1t pio 1 102 Fillo 120

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy