Paths and Networks Ch 6 Graph: collection of points called vertices Vertex: a point on a graph Vertices: plural of vertex Edge: a line that starts and ends at vertices Loop: an edge that starts and ends at the same edge. Odd vertex: has an odd number of edges Even vertex: has an even number of edges Loop: counts as two edges Path: a route along edges that starts at a vertex and ends at a vertex Circuit: a path that starts and ends at the same edge Connected graph: any two of its vertices, at least one path connecting them Disconnected graph: not connected Definition: A path that includes each edge of a graph exactly once is called an Eulerian path, and an Eulerian path that is also a circuit is called an Eulerian circuit. Theorem: A graph has an Eulerian circuit if and only if it is connected and all of its vertices are even. A graph has an Eulerian path if and only if it is connected and has either no odd vertices or exactly 2 odd vertices. If 2 of the vertices are odd, then any Eulerian path must begin at one of the odd vertices and end at the other. AA@Valencia B 11 Page 1 Example: Check if the graph represents an Eulerian circuit, if yes, draw it. G A E H B F C D For eulerizing a graph: Circle all the odd vertices. Pair each odd vertex off with another odd vertex that is close to it in the graph. For each pair of odd vertices, find the path with the fewest edges connecting them in the original graph, and then duplicate the edges along this path. Example: Find an eulerization of the graph AA@Valencia B 11 Page 2 Definitions: A circuit that begins at some vertex, goes through every other vertex exactly once, and returns to the starting vertex is called a Hamiltonian circuit. The traveling salesman problem: The problem of finding a Hamiltonian circuit in a complete weighted graph for which the sum of the weights of the edges is a minimum is called the traveling salesman problem. The Nearest Neighbor Algorithm Start at the vertex on which the circuit is supposed to begin and end. At each vertex in the circuit, the next vertex in the circuit should be chosen to be the nearest vertex that has not been visited with the least weight. If there is a tie, weigh the next vertices for each previous vertex in the tie and proceed from there. When all of the vertices have been visited, return to the starting vertex. The Greedy Algorithm: Begin by choosing the edge of least weight and marking the edge. If there is a tie between 2 edges, choose anyone. At each stage, the next edge marked should be the unmarked edge of least weight unless it creates a circuit that does not visit every vertex or unless it results in three marked edges coming out of the same vertex in the graph. If there is a tie choose anyone. When the marked edges form a Hamiltonian circuit, the algorithm has been completed. The approximate solution is the marked circuit that begins at the starting vertex, travels along the marked edges in “either direction” and returns to the same starting vertex. AA@Valencia B 11 Page 3 Example: Use both algorithms to find the best the least weighted Hamiltonian circuit AA@Valencia B 11 Page 4 Example 2: The table below shows the distance, in miles, between different locations in Orlando, that UPS driver uses on a given day. Downtown East side Downtown 0 10 East side 10 0 Airport 18 8 436 13 3 Buggy Creek 22 12 Avalon Park 25 15 Airport 18 8 0 5 4 15 436 13 3 5 0 9 12 Buggy Creek 22 12 4 9 0 24 Avalon Park 25 15 7 12 24 0 1. Draw a weighted graph corresponding to this situation 2. Use any algorithm to the route with the least mileage. AA@Valencia B 11 Page 5 Definition: Any graph that is connected and contains no circuit is called a tree. A subgraph that is a tree containing all of the vertices of the graph is called a spanning tree for the graph. Definition: A minimum spanning tree for a weighted graph is a spanning tree for which the sum of the weights of the edges is a minimum. Prim’s Algorithm for Finding a Minimum Spanning Tree 1. Start at any vertex in the graph. This vertex will be the starting tree for the algorithm. 2. Find the nearest vertex to the current tree that is not already contained in the current tree. I other words, from among those vertices not in the current tree, find the one that may be connected to a vertex in the current tree by an edge of the least weight. Connect this vertex to the current tree by the edge of the least weight connecting them. If there is a tie between nearest vertices, choose any one of them. 3. Continue the procedure in step 2 until all of vertices are contained in the tree. Example: For the given picture below, find a spanning tree with the least weight. You may want to use the Prim’s algorithm AA@Valencia B 11 Page 6 AA@Valencia B 11 Page 7