Presentation is loading. Please wait.

Presentation is loading. Please wait.

DECISION 1. How do you do a Bubble Sort? Bubble Sort:  You compare adjacent items in a list;  If they are in order, leave them.  If they are not in.

Similar presentations


Presentation on theme: "DECISION 1. How do you do a Bubble Sort? Bubble Sort:  You compare adjacent items in a list;  If they are in order, leave them.  If they are not in."— Presentation transcript:

1 DECISION 1

2 How do you do a Bubble Sort?

3 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.

4 How do you do a quick sort?

5 Quick Sort:  Select a pivot  Split the items into 2 sub-lists: those less than the pivot and those greater than the pivot.  Keep doing this to each resulting sub-list. When items are written down, keep them in the order they were in in the original list.

6 What does a Binary Search do?

7 Binary Search:  Will search an ordered list to find out whether an item is in the list.  If the item is in the list, it will locate its position in the list.

8 How is a binary search implemented?

9 Binary Search:  The pivot is the middle item in the list [(1+n) /2]  If the target item is not the pivot, the pivot and half of the list are discarded.  The list halves at each pass.

10 Describe the 3 bin packing algorithms.

11 Bin packing:  First fit – takes items in the order given  First fit decreasing – requires the items to be in descending order before applying the algorithm  Full-bin – uses inspection to select items that will combine to fill bins, remaining items are packed using the first fit algorithm.

12 How is the first fit algorithm implemented?

13 First fit:  Take items in the order given.  Place each item in the first available bin that can take it, start from bin 1 each time.

14 How is the first fit decreasing algorithm implemented?

15 First fit decreasing:  Reorder the items so that they are in descending order.  Apply the first fit algorithm to the reordered list.

16 How is the full bin packing algorithm implemented?

17 Full bin:  Use observation to find combinations of items that will fill a bin, pack these items first.  Any remaining items are packed using the first fit algorithm.

18 What are the advantages and disavantages of....

19 First fit algorithm

20  Advantage – it’s quick to do  Disadvantage – it’s not likely to lead to a good solution

21 First fit decreasing algorithm

22  Advantages – you usually get a fairly good solution it’s easy to do Disadvantage – May not get an optimal solution

23 Full bin packing algorithm

24  Advantage – usually a good solution  Disadvantage – Difficult to do, especially when there are lots of awkward numbers.

25 Define the following:

26 Graph

27  Consists of vertices which are connected by edges.

28 Subgraph

29  Part of a graph

30 Weighted graph

31  A graph that has a number (a weight) associated with each edge.

32 Degree/ Valency/ Order of a vertex

33  The number of edges incident to a vertex.

34 Path

35  A finite sequence of edges such that:  The end vertex of one edge in the sequence is the start vertex of the next.  And no vertex appears more than once.

36 Walk

37  A path in which you are permitted to return to vertices more than once.

38 Cycle

39  A closed path.  i.e. The end vertex of the last edge is the start vertex of the first edge.

40 Connected vertices

41  Vertices are connected if there is a path between them.

42 Connected Graph

43  A graph is connected is all its vertices are connected.

44 Loop

45  An edge that starts and finishes at the same vertex

46 Simple graph

47  A graph in which there are no loops and no more than one edge connecting any pair of vertices.

48 Directed edges

49  An edge that has a direction associated with it.

50 Digraph

51  A graph containing directed edges.

52 Tree

53  A connected graph with no cycles.

54 Spanning Tree  A sub-graph that links all the vertices together and covers the full network.  Also a tree (so no loops or cycles).

55 Bipartite Graph

56  Consists of two sets of vertices, X and Y.  The edges only join vertices in X to vertices in Y.

57 Complete Graph

58  A graph in which every vertex is directly connected by an edge to each of the other vertices.  If the graph has n vertices the connected graph is denoted k n.

59 Complete bipartite graph

60  Is a graph is which there are r vertices in set X and s vertices in set Y.  Denoted k r,s

61 Isomorphic graphs

62  Show the same information but are drawn differently.

63 Adjacency Matrix

64  Records the number of direct links between vertices.

65 Distance Matrix

66  Records the weights on edges.  Where there is no weight, this is indicated by ‘-’

67 Minimum spanning tree

68  Is a spanning tree such that the total length of its arcs is as small as possible.

69 What do Kruskal’s and Prim’s algorithms do?

70  They find the shortest, cheapest or fastest way of linking all the nodes in one system.  (They find the minimum spanning tree).

71 What is Kruskal’s algorithm?

72 Kruskal’s Algorithm: 1. Sort all the arcs into ascending order of weight. 2. Select the arc of least weight to start the tree. 3. Consider the next arc of least weight: If it would form a cycle with the arcs already selected, reject it. If it does not form a cycle, add it to the tree. 4. Repeat step 3 until all vertices are connected.

73 What is Prim’s algorithm?

74 Prim’s Algorithm 1. Choose any vertex to start the tree. 2. Select and arc of least weight that joins a vertex that is already in the tree to a vertex that is not yet in the tree. ( if there is a choice of arcs of equal weight, choose randomly ) 3. Repeat step 2 until all the vertices are connected.

75 Why are no cycles formed using Prim’s algorithm?

76  Because when you are adding arcs using Prim’s algorithm, you are only joining nodes that already aren’t in the tree, so a cycle can never be created.

77 How do you apply Prim’s algorithm to a distance matrix?

78 Prim’s on a distance matrix: 1. Choose any vertex to start the tree 2. Delete the row in the matrix for the chosen vertex. 3. Number the column in the matrix for the chosen vertex. 4. Put a ring around the lowest undeleted entry in the numbered columns. (choose randomly if there is equal choice). 5. The ringed entry becomes the next arc to be added to the tree. 6. Repeat steps 2, 3, 4 and 5 until all the rows are deleted.

79 What is Dijkstra’s algorithm used for?

80  Dijkstra’s algorithm is used to find the shortest, cheapest or quickest route between two vertices.

81 What is Dijkstra’s Algorithm?

82 Dijkstra’s Algorithm: (from S to T) 1. Label the start vertex with the final label 0. 2. Record a working value at every vertex that is directly connected to the vertex that just received its final label. 3. Look at the working values for all the vertices without a final label. Select the smallest working value. This now becomes the final label at that vertex. 4. Repeat steps 2 and 3 until the destination vertex receives its final label. 5. To find the shortest path, trace back from T to S.

83 What is a Eulerian (traversable) graph?

84  A graph in which all the vertices have an even valency.

85 What is a semi-Eulerian (semi- traversable) graph?

86  A graph with precisely two odd valencies.

87 When is a graph not traversable?

88  A graph is not traversable if it has more than two odd valencies.

89 What does the route inspection algorithm do?

90 Route inspection:  Finds the shortest route that traverses every arc at least once and returns to the starting point.  If all the vertices have an even valency the length of the shortest route will be equal to the weight of the network.

91 What is the route inspection algorithm?

92 Route inspection algorithm: 1. Identify any vertices with an odd valency. 2. Consider all the possible pairings of these vertices. 3. Select the complete pairing that has the least sum. 4. Add a repeat or the arcs indicated by this pairing to the network.

93 What does a precedence table show?

94 Precedence table:  Shows which tasks must be completed before others are started.

95 What are the 2 uses of Dummies?

96  A dummy activity can be used to show that an activity depends on two activities, E.g. 0 1 2 3 A B D C This shows that activity C depends on activity A as well as activity B. The problem here is how to represent C, which depends on both A and B.

97  Every activity must be uniquely represented in terms of its events.  This requires that there can be at most one activity between any two events. A dummy may be required to satisfy this condition.

98 E.g.  Suppose that S depends on P, Q and R. 6 Q 8 R S P This is not allowed because there are two activities between events 6 and 8.

99 Using a dummy allows the dependence to be shown while ensuring that all activities are uniquely determined by their events. 68 Q R S 7 P Dummy

100 What is the early event time?

101 Early Event Time:  Is the earliest time of arrival at the event allowing for the completion of all preceding activities.

102 What is the late event time?

103

104 Late Event Time:  Is the latest time that the event can be left without extending the overall time needed for the project.

105 What do the two boxes represent in an activity network?

106 Early Event Time Late Event Time

107 What is a Critical Activity?

108 Critical Activity:  An activity is described as a critical activity if any increase in its duration results in a corresponding increase in the duration of the whole project.

109 What is a critical path?

110 Critical Path:  Is a path from the source node (start) to the sink node (end) which entirely follows critical activities.  A critical path is the longest path contained in the network.  At each node on the critical path: early event time = late event time It is possible to have more than one critical path in a network.

111 Find the critical paths in this activity network. 9 9 7 8 12 9 9 14 0 0 4 4 A (4) B (5) C (3) E (1) F (4) H (5) D (3) G (2) There are 2 critical paths. The critical activities are: A, B, D, G and H A-B-D-G is a critical path The other critical path is: A-B-H

112 What is the total float of an activity?

113 Total Float:  The total float of an activity is the amount of time that its start may be delayed without affecting the duration of the project.  The total float of any critical activity is 0.

114 Total Float Latest finish time DurationEarliest start time Duration Early Late To calculate the float you ‘float’ from bottom to top. From Bottom Float to top

115 What is the purpose of a Gantt chart?

116 Gantt Charts:  Provide a graphical way to represent the range of possible start and finish times for all activities on a single diagram.  The number scale shows elapsed time.  The critical activities are shown as rectangles at the top.  The total float of each activity is represented by the range of movement of its rectangle on the chart, which is shown as a dotted box.

117 What assumptions are made when drawing a scheduling diagram?

118 You assume that:  Each activity is completed by a single worker in the time given as the duration of the activity.  Once an activity has started, it must be completed by a worker.  Once a worker has completed an activity, they become immediately available to start another activity.

119 Also:  You should always use the first available worker.  If there is a choice of tasks for the worker, assign the one with the lowest value for the latest finish time as shown on the activity network.

120 How do you calculate the lower bound for the number of workers needed to complete a project within its critical time?

121 Lower bound:  Is given by the smallest integer greater than or equal to: Sum of all the activity times Critical time of the project.

122 (In linear programming). What are the decision variables?

123 Decision Variables:  Are the numbers of each of the things that can be varied.  E.g. The number of fruit cakes made, the number of chairs made, etc.  The variables are usually given letters such as x, y and z to represent them in inequalities.

124 What is the Objective Function?

125 Objective Function:  Is the aim of the problem.  E.g. To maximise profit or minimise cost.

126 What are Constraints?

127 Constraints:  Are the things that will prevent you making, or using, an infinite number of each of the variables.  Each constraint will give rise to one inequality.

128 What is the feasible region?

129 Feasible region:  The values for the decision variables that satisfy each constraint.  Or in graphical linear programming, the feasible region is the region that contains all the feasible solutions.  On a graph the feasible region satisfying several inequalities must be left unshaded. (And marked with an ‘R’).

130 What is the optimal solution?

131 Optimal Solution:  Is the feasible region that meets the objective function, i.e. The largest profit or lowest cost. There might be more than one optimal solution.

132 Locating the Optimal Solution

133 Formulating a problem in linear programming: 1. Define the decision variables (x, y, z, etc. ) 2. State the objective function. (minimise or maximise +algebraic expression). 3. Write the constraints as inequalities.

134 Using an Objective Line  Draw the objective line by putting your objective function equal to a value. (Preferably one that is a multiple of your x and y value).  Eg - 5x + 2y = 40  40 is a multiple of 2 and 5.

135 Objective Line  Plot this line on your graph.  Keeping you ruler parallel to the objective line, place your ruler on the objective line and slide your ruler across the feasible region.

136 Objective Line  For a maximum point, look at the last point covered by an objective line as it leaves the feasible region.  For a minimum point, look for the first point covered by an objective line as it enters the feasible region.

137 Vertex Testing  The optimal point will occur at one or more of the vertices of the feasible region. To identify the optimal point: 1. Find the coordinates of each vertex in the feasible region. 2. Substitute these values into your objective function. 3. Select the pair of coordinates that gives the optimal value for the objective function.

138 Integer Solutions  If the question requires a whole number value and the optimal point is not an integer value, then points around this will need to be tested using the objective function, to find the optimal integer solution.  The optimal integer solution must still be in the feasible region.

139 What is a matching?

140 Matching:  A matching is the 1 to 1 pairing of some, or all, of the elements of one set, X, with elements of a second set, Y.

141 What is a maximal matching?

142 Maximal Matching:  A maximal matching is a matching in which the number of arcs is as large as possible.

143 What is an alternating path?

144 Alternating Path:  Starts at an unmatched node on one side of the bipartite graph and finishes at an unmatched node on the other side.  It uses arcs that are alternately ‘in’ or ‘not in’ the initial matching.

145 What is the maximal matching algorithm?

146 Maximal Matching Algorithm: 1. Start with any (non-trivial) initial matching. 2. Search for an alternating path. 3. If an alternating path can be found, use it to create an improved matching by changing the status of the arcs. If an alternating path can’t be found, stop. 4. List the new matching, which consists of the result of applying the alternating path with any unchanged elements of the initial matching. 5. If the matching is now complete, stop. If not, return to step 2. Change status just means switch the symbols over.

147 Finding the maximal matching  Each time you apply the maximum matching algorithm and find an alternating path, you increase the number of matched pairs by one.  If there is more than one pair of unmatched nodes, you will need to find more than one alternating path.  Each subsequent application of the algorithm requires you to start from the current matching.


Download ppt "DECISION 1. How do you do a Bubble Sort? Bubble Sort:  You compare adjacent items in a list;  If they are in order, leave them.  If they are not in."

Similar presentations


Ads by Google