Download presentation
Presentation is loading. Please wait.
Published byἈσκληπιός Βάμβας Modified over 6 years ago
1
Lecture 11: Connectivity Paths in Undirected & Directed Graphs
Graph Isomorphisms Counting Paths between Vertices Euler and Hamilton Paths Euler Paths & Circuits Hamilton Paths & Circuits Gray Code Traveling Salesperson Problem Other Graph Algorithms Shortest Path Algorithms Prims Minimal Spanning Tree Backtracking
2
Introduction of Connectedness
3
Paths in Graphs
4
Connected Components of a Graph
5
Connectedness in Directed Graphs
6
Test for Isomorphism
7
Counting Paths Between Vertices
8
The Seven Bridges of Konigsberg
Graph theory began with the analysis of a puzzle involving the bridges in the town of Konigsberg, Prussia (currently Kaliningrad, Russia) by the mathematician Leonhard Euler The problem was to find a walk through the city that would cross each bridge once and only once. The islands could not be reached by any route other than the bridges, and every bridge must have been crossed completely every time (one could not walk half way onto the bridge and then turn around and later cross the other half from the other side). Euler showed that there is no solution. The traversal of any graph in which every edge is used exactly once is called an Euler Circuit. Euler observed that a necessary condition for the existence of Eulerian circuits is that all vertices in the graph have an even degree. A graph where every vertex has an even degree is called Eulerian graph.
9
Graph Coloring Algorithm
In graph theory, graph coloring is a special case of graph labeling; it is an assignment of labels traditionally called "colors" to elements of a graph subject to certain constraints. In its simplest form, it is a way of coloring the vertices of a graph such that no two adjacent vertices share the same color; this is called a vertex coloring. Determining if a graph can be colored with 2 colors is equivalent to determining whether or not the graph is bipartite, and thus computable in linear time using breadth-first search. Course Scheduling (Timetable) Problem as Graph Coloring - vertex = course edge = conflict color = time of course A B E D C A B E D C A B C D E A - * * * B * - * * * C * * - * D * * * - * E * * -
11
Hamilton Circuit
12
Graph Depth-First Traversal (DFT) Algorithm Implementation
pseudo-code DFT( node vk ) { // deal with current node for each node, vi if (node_avail(vi)) then DFT(vi) } node_avail( vi ) is a boolean function that returns true if node vi is available for traversal, which means that vi has not been traversed, and vi is adjacent to vk.
13
Gray Code 1 1 1 1 0 0 0 1 1 1 1 0
14
Depth-First Search A B A C A D A E B A B G C A C F D A D F D H E A E G
Depth-First traversal is a type of backtracking in a graph. If we use an alpha-numeric order for node traversal we can define a unique ordering of the nodes encountered in a connected graph. A B A C A D A E B A B G C A C F D A D F D H E A E G E H F C F D F H F I G B G E G H H D H E H F H G H I I F I H A H D B F C E I G Starting at node A we can traverse every other node in a depth-first order, making sure that we do not enter any node more than once. A B G E H D F C I We move forward from A to C and then we have to backtrack to F and move forward to I. Edge list representation
15
Backtracking Technique
Backtracking is used to solve problems in which a feasible solution is needed rather than an optimal one, such as the solution to a maze or an arrangement of squares in the 15-puzzle. Backtracking problems are typically a sequence of items (or objects) chosen from a set of alternatives that satisfy some criterion. 1 2 3 4 6 10 14 15 5 7 8 9 6 11 12 13 10 14 15
16
Backtracking Implementation
Backtracking is a modified depth-first search of the solution-space tree. In the case of the maze the start location is the root of a tree, that branches at each point in the maze where there is a choice of direction.
17
Prim's Algorithm Given a weighted graph G consisting of a set of vertices V and a set of edges E with weights, where Prepare a vertex set and an edge set to hold elements selected by Prim's Algorithm. 1. Choose an arbitrary starting vertex vj 2. Find the smallest edge e incident with with a vertex in the vertex set whose inclusion in the edge set does not create a cycle. 3. Include this edge in the edge list and its vertices in the vertex list. 4. Repeat Steps 2 and 3 until all vertices are in the vertex list. C D F E A G B 4 2 3 5 1 2 Exercise Prim's Algorithm on this example weighted graph starting with vertex B and again starting at vertex F. Did you get the same spanning tree? If the trees were distinct, did they have the same value?
18
Single Source Shortest Path
Given a weighted graph G find the minimum weight path from a specified vertex v0 to every other vertex. 2 1 3 4 5 6 v1 v0 v5 v4 v3 v2 The single source shortest path problem is as follows. We are given a directed graph with nonnegative edge weights G = (V,E) and a distinguished source vertex, The problem is to determine the distance from the source vertex to every vertex in the graph.
19
Dijkstra's Algorithm for SSSP
v1 v2 v3 v4 v5 {2} {24} {241} {2413} v1 v2 v3 v4 v5 {2} {24} {241} {2413} v1 v2 v3 v4 v5 node minimum list path v1 v2 v3 v4 v5 {2} {24} {241} v1 v2 v3 v4 v5 v1 v2 v3 v4 v5 {2} v1 v2 v3 v4 v5 {2} {24} 2 1 3 4 5 6 v1 v0 v5 v4 v3 v2
20
Hamiltonian Circuits Problem
A Hamiltonian circuit or tour of a graph is a path that starts at a given vertex, visits each vertex in the graph exactly once, and ends at the starting vertex. Some graphs do not contain Hamiltonian circuits. v1 v2 v6 v4 v5 v3 v1 v2 v6 v4 v5 v3 A state space tree for this problem is as follows. Put the starting vertex at level 0 in the tree, call this the zero'th vertex on the path. At level 1, consider each vertex other than the starting vertex as the first vertex after the starting one. At level 2, consider each of these vertices as the second vertex, and so on. You may now backtrack in this state space tree.
21
Backtracking in a State Space Tree
function ok(i)return boolean j:index isok:boolean begin if i=n-1 and not W(v(n-1),v(0)) then isok:=false elsif i>0 and not W(v(n-1),v(i)) then else isok:=true; j:=1; while j<i and isok loop if v(i)=v(j) then isok:=false; j:=j+1; end loop; end if; end ok; procedure hamiltonian(i:index) j : index; begin if ok(i) then if i=n-1 then display(v(0..n-1)) else for j in 2..n loop v(i+1):=j; hamiltonian(i+1); end loop; end if; end hamiltonian; 1. The ith vertex on the path must be adjacent to the (i-1)st vertex on the path. 2. The (n-1)st vertex must be adjacent to the 0'th vertex. 3. The ith vertex cannot be one of the i-1 vertices.
22
Sample Problem 1 2 5 7 6 4 8 3 v1 v2 v3 v5 v6 v7 v4 v8 : :
state space tree graph : :
23
Floyd's Algorithm for Shortest Paths
V1 V2 V5 V4 V3 1 5 2 6 3 procedure floyd(W,D:matype) is begin D:=W; for k in 1..n loop for i in 1..n loop for j in 1..n loop D(i,j):=min(D(i,j),D(i,k)+D(k,j)); end loop; end floyd; Floyd's algorithm is very simple to implement. The fact that it works at all is not obvious. Be sure to work through the proof of algorithm correctness in the text.
24
Traveling Salesperson Problem
The branch-and-bound problem solving method is very similar to backtracking in that a state space tree is used to solve a problem. The differences are that B&B does not limit us to any particular way of traversing the tree and (2) is used only for optimization problems. A B&B algorithm computes a number (bound) at a node to determine whether the node is promising. The number is a bound on the value of the solution that could be obtained by expanding the state space tree beyond the current node.
25
Types of Traversal When implementing the branch-and-bound approach there is no restriction on the type of state-space tree traversal used. Backtracking, for example, is a simple type of B&B that uses depth-first search. A better approach is to check all the nodes reachable from the currently active node (breadth-first) and then to choose the most promising node (best-first) to expand next. An essential element of B&B is a greedy way to estimate the value of choosing one node over another. This is called the bound or bounding heuristic. It is an underestimate for a minimal search and an overestimate for a maximal search. When performing a breadth-first traversal, the bound is used only to prune the unpromising nodes from the state-space tree. In a best-first traversal the bound cab also used to order the promising nodes on the live-node list.
26
An Example TSP Solution using Branch and Bound
The candidate tour obtained using the greedy method could be an optimal tour. This is usually not the case. We will now look at problem for which the initial candidate tour is not a minimal tour. The initial tour is A-F-E-D-B-C-A with a total length of 32. The sum of the minimum costs of leaving every node is 29 so we know that a minimal tour cannot have length less than 29.
27
The live-node list is ordered by bounding value and then by level of completion. That is, if two nodes have the same bounding value we place the one that is closer to completion ahead of the other node. This is because the bounding value of the of the node closer to completion is more likely to be closer to the actual tour length.
28
The node shown in red were expanded from an active node (F3) with a possible tour length of 29. However the completed tours turned out to be significantly larger.
29
Expanding D3 we find an actual tour that is shorter than our initial tour. We do not yet know if this is a minimal tour but we can remove nodes from our live-node list that have a bounding value of >= 31. Now we expand D2 to find that it leads to tours of length >= 33.
30
Expansion of E2 eliminates this path as a candidate for a minimal tour.
31
When the live-node list is empty we are finished
When the live-node list is empty we are finished. In this example a minimal tour is A-C-E-D-B-F-A with a length of 31 we have found a tour that is shorter than the original candidate greedy tour.
32
Greedy TSP public static void doGreedyTSP(int p) { int k = 0; do
itour[k] = p; tour[k] = L[p]; used[itour[k]] = true; p = minAvail(p); k += 1; } while (k < n); } 3 1 6 C B A G itour used tour D E F H L
33
Introduction
34
Definition of a Planar Graph
There is no maximum degree of a particular vertex in a planar graph. Is there a maximum allowed minimum degree of the vertices of a simple planar graph? YES! While some subset of the vertices of a simple planar graph can be of arbitrarily large degree, at least one of the vertices of a simple planar graph must have a degree not exceeding 5.
35
K3,3 is not Planar
36
Eulers Formula Let G be a connected planar simple graph with e edges and v vertices. Let r be the number of regions in a planar representation of G. Then r = e - v + 2.
37
Euler's Formula Corollaries
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.