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.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Transportation Problem (TP) and Assignment Problem (AP)
Greed is good. (Some of the time)
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Module 5 – Networks and Decision Mathematics Chapter 24 – Directed Graphs.
Chapter 3 The Greedy Method 3.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These.
Copyright © Cengage Learning. All rights reserved.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Chapter 2 Graph Algorithms.
Graph Theory Topics to be covered:
Representing and Using Graphs
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we can find a path that goes over all.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Can you connect the dots as shown without taking your pen off the page or drawing the same line twice.
Lesson Objective: Understand what an algorithm is and be able to use them to solve a simple problem.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Chapter 10 Graph Theory Eulerian Cycle and the property of graph theory 10.3 The important property of graph theory and its representation 10.4.
1 Network Models Transportation Problem (TP) Distributing any commodity from any group of supply centers, called sources, to any group of receiving.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
D1 stuff The tail wags the dog. M1A1 A1 A1 We mark your best effort.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graphs Upon completion you will be able to:
Great Theoretical Ideas in Computer Science for Some.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
I can describe the differences between Hamilton and Euler circuits and find efficient Hamilton circuits in graphs. Hamilton Circuits I can compare and.
1.Which of the following is NOT an algorithm? a.A set of instructions used to build a wardrobe b.A flow chart used to solve a quadratic equation c.A note.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Grade 11 AP Mathematics Graph Theory Definition: A graph, G, is a set of vertices v(G) = {v 1, v 2, v 3, …, v n } and edges e(G) = {v i v j where 1 ≤ i,
AS Decision Maths Tips for each Topic. Kruskal and Prim What examiner’s are looking for A table of values in the order that they are added and the total.
AS Maths Decision Paper January 2011 Model Answers.
1 Ch18. The Greedy Methods. 2 BIRD’S-EYE VIEW Enter the world of algorithm-design methods In the remainder of this book, we study the methods for the.
Greedy Technique.
Redraw these graphs so that none of the line intersect except at the vertices B C D E F G H.
The minimum cost flow problem
Section 2: Multiple choice
Chapter 2: Business Efficiency Lesson Plan
Planar Graphs & Euler’s Formula
The Taxi Scheduling Problem
The tail wags the dog. M1A1 A1 A1 We mark your best effort
Chapter 2: Business Efficiency Lesson Plan
Minimum-Cost Spanning Tree
Critical Path Analysis
Graphs Chapter 13.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Shortest Path.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Section 2: Multiple choice
ITEC 2620M Introduction to Data Structures
Route Inspection Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we introduce a vertex.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

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 order, swap them.  The list is in order when a pass is completed without any swaps.

How do you do a quick sort?

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.

What does a Binary Search do?

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.

How is a binary search implemented?

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.

Describe the 3 bin packing algorithms.

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.

How is the first fit algorithm implemented?

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.

How is the first fit decreasing algorithm implemented?

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

How is the full bin packing algorithm implemented?

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.

What are the advantages and disavantages of....

First fit algorithm

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

First fit decreasing algorithm

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

Full bin packing algorithm

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

Define the following:

Graph

 Consists of vertices which are connected by edges.

Subgraph

 Part of a graph

Weighted graph

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

Degree/ Valency/ Order of a vertex

 The number of edges incident to a vertex.

Path

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

Walk

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

Cycle

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

Connected vertices

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

Connected Graph

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

Loop

 An edge that starts and finishes at the same vertex

Simple graph

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

Directed edges

 An edge that has a direction associated with it.

Digraph

 A graph containing directed edges.

Tree

 A connected graph with no cycles.

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

Bipartite Graph

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

Complete Graph

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

Complete bipartite graph

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

Isomorphic graphs

 Show the same information but are drawn differently.

Adjacency Matrix

 Records the number of direct links between vertices.

Distance Matrix

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

Minimum spanning tree

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

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

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

What is Kruskal’s algorithm?

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.

What is Prim’s algorithm?

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.

Why are no cycles formed using Prim’s algorithm?

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

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

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.

What is Dijkstra’s algorithm used for?

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

What is Dijkstra’s Algorithm?

Dijkstra’s Algorithm: (from S to T) 1. Label the start vertex with the final label 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.

What is a Eulerian (traversable) graph?

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

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

 A graph with precisely two odd valencies.

When is a graph not traversable?

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

What does the route inspection algorithm do?

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.

What is the route inspection algorithm?

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.

What does a precedence table show?

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

What are the 2 uses of Dummies?

 A dummy activity can be used to show that an activity depends on two activities, E.g 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.

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

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.

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

What is the early event time?

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

What is the late event time?

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

What do the two boxes represent in an activity network?

Early Event Time Late Event Time

What is a Critical Activity?

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.

What is a critical path?

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.

Find the critical paths in this activity network 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

What is the total float of an activity?

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.

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

What is the purpose of a Gantt chart?

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.

What assumptions are made when drawing a scheduling diagram?

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.

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.

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

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

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

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.

What is the Objective Function?

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

What are Constraints?

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.

What is the feasible region?

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’).

What is the optimal solution?

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.

Locating the Optimal Solution

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.

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.

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.

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.

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.

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.

What is a matching?

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.

What is a maximal matching?

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

What is an alternating path?

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.

What is the maximal matching algorithm?

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.

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.