Common Mistakes Examples of typical mistakes Correct version Quick sort Only choosing one pivot per iteration. At each iteration, one pivot per sublist should be chosen. e.g. Use a quick sort to sort the following data into ascending order. 3, 5, 7, 2, 6, 4, 1, 9, 8, First pivot is 6 3, 5, 2, 1, 4, 6 7, 9, 8 giving list 1 { 3, 5, 2, 1, 4} and list 2 {7, 9, 8} pivot for list 1 is 2 giving list 3 {1} and list 4 {3, 5, 4} and so on separating the sort into individual lists and usually dealing with all the left hand lists before moving on to the right hand lists. First pivot is 6 3, 5, 2, 1, 4, 6, 7, 9, 8 Choosing one pivot in each sublist 2 and 9 1, 2 3, 5, 4, 6, 7, 8, 9 Choosing one pivot in each sublist 1, 5 and 8 1, 2, 3, 4, 5, 6 7, 8, 9 and so on. Not selecting a pivot if the numbers in the sublist are already in the correct order. e.g. Use a quick sort to sort the following data into ascending order. 3, 4, 6, 7, 5, 9 The first pivot is 6 List is in order so stop. 3, 4, 6, 7, 5, 9 The first pivot is 6 Choosing one pivot in each sublist 4 and 9 choosing one pivot in each sublist 3, 5 and 7. All pivots chosen, the list is in order so stop. Binary search Forgetting to discard the pivot as well as half of the list. e.g. Locate the name Smith in the following list 1) Brown 2) Davies 3) Hall 1
1 5 First pivot is 3 2 Hall reject top of list. 3) Hall 3 5 4 2 Jones reject top of list 1 5 First pivot is 3 2 Hall reject, pivot and top of list. 4 5 5 2 Smith, name found. 4 5 5 2 Smith, name found. Bin packing Forgetting to offer later items to bin 1 first then bin 2 and so on. e.g. Put the data below into bins of size 10 using the first fit algorithm. 7, 8, 2, 3 Bin 1: 7 + 3 Bin 2: 8 + 2 Minimum Connector (Minimum Spanning Tree) The 7 and 8 are correctly placed, but the third number, 2, should have been placed in bin 1, giving Bin 1 : 7 + 2 Bin 2 : 8 Bin 3 : 3 Forgetting to state which arcs have been rejected when using Kruskal. e.g. Use Kruskal s algorithm to find a minimum spanning tree for the network below. Arcs: AB, DF, AC, EF, CD Arcs: AB, DF, AC, EF, reject BC, reject DE, CD. 2
In Prim s algorithm, only considering vertices connected to the last vertex added to the tree. e.g. Use Prim s algorithm, starting at A, to find a minimum connector for the network above. Draw your tree. AB, BC, CD, DF, FE AB, AC, CD, DF, FE. Dijsktra s algorithm When a vertex has been given its final label, all vertices directly connected to it, no matter where they are, should be given a working value. So the algorithm reaches out from one vertex to the other vertices. The error some candidates make is to not record any working values until the vertices on the left have been completed and then to look at what feeds into the next vertex. e.g. Use Dijkstra s algorithm to find the shortest route from S to B, use the diagram below to make your working clear. Shortest route is S A C B length 6. Shortest route is S A B length 7. 3
Route Inspection (Chinese postman) If there are four odd nodes, all possible pairings of those four nodes must be considered, not just the more likely ones. (Remember the diagram is not drawn to scale!) e.g. Use the Chinese postman algorithm to find the length of the shortest inspection route for the network below. AB + CD = 25 + 90 = 115 AC + BD = 67 + 34 = 101 AD + BC = 52 + 60 = 112 So length is 328 + 101 = 429 m So length is 328 + 115 = 443 m Critical Path Analysis The critical activities have zero total float. They do go from double domino to double domino but this alone is not enough to pick out the critical activities. e.g. State the critical activities from the activity network below. Critical activities are A and D. 4
Critical activities are A, C and D because they go from double to double. Graphical Linear Programming Straight lines must be drawn with a ruler. The lines should be labelled. Lines such as x = 2y are often drawn as y = 2x. Don t forget the non-negativity constraints. If the objective line method is used, an objective line needs to drawn on the graph. Matchings The alternating path must both start, and finish, at an unmatched vertex. The change status step must be clearly shown. 5