CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Motivation Digraphs, Undirected graphs, graphs with self loops, weighted graphs Paths, cycles, connectedness, free trees, spanning trees, minimum spanning trees. Complete graphs, bipartite graphs. CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Motivation Graphs are used to model a great many different kinds of problems to be solved: Transportation network management, Data flow networks, the Internet. Associations and assignments: compatibility of people for dating. Database schema representation. Semantic structures in language. We need good ways to represent and manipulate data used for these purposes. CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
Directed Graphs (Digraphs) A directed graph or digraph consists of a set of vertices and a set of edges. G = V, E V = { v1, v2, . . . , vn } E = { e1, e2, . . . , em } ei = va(i), vb(i) In Sahni, self loops (e.g., vk, vk ) are not permitted. However, in many applications, they are permitted (for example, finite-state automata). In general a digraph is similar to a binary relation. CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Example Digraph G = V, E V = { a, b, c, d } E = { a, b , a, d , a, c , c, d , d, c } CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Graphs as diagrams A vertex is typically drawn as a dot or a circle. An edge is typically drawn as an arrow. a c b d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Undirected Graphs An undirected graph is a graph in which each edge is considered to be unordered. For an undirected graph: ei = { va(i), vb(i) } For a directed graph: ei = va(i), vb(i) An undirected graph is equivalent to a digraph for a symmetric binary relation. Arrowheads are unnecessary. CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
Example Undirected Graph G = V, E V = { a, b, c, d } E = { { a, b }, { a, d }, { a, c } } a c b d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Paths A path in a digraph is a sequence of edges such that each edge after the first begins at the vertex where the previous edge arrives a, b , b, d , d, c a c b d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
Drawing a House (Puzzle) CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
Puzzle: Seven Bridges of Königsberg PREGEL KNEIPHOFF CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
Multigraph for the Bridges of Königsberg CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Euler Paths An Euler path for a graph is a path that uses every edge of the graph precisely once. To draw an Euler path: Start at a vertex. Traverse each edge exactly once. (Never lift the pencil). If any vertex has odd degree, it must be either the start or end of the Euler path, if there is one. No Euler path can have more than 1 start and 1 end. CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Self Loops G = V, E V = { a, b, c, d } E = { a, b , b, b, a, c, d, d } a c b d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Cycles A cycle in a digraph is a path such that the last vertex of the last edge equals the first vertex of the first edge. A simple cycle is one that visits each of its vertices once. I.e., there is one outgoing edge and one ingoing edge for each vertex on the path. CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
Connected Graphs An undirected graph is connected provided every pair of vertices has some path in the graph that begins at one and ends at the other. a Is this graph connected? c b d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Free Trees An undirected graph is a free tree if (a) it is connected, and (b) it has no cycles. A free tree is unrooted. G = V, E , V = { a, b, c, d }, E = { a, b , a, d, a, c } a c b d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Subgraphs Let G1 = V1, E1 be a graph, and let G2 = V2, E2 be a graph such that V2 V1 E2 E1 Then G2 is a subgraph of G1. a a G1 c c b G2 d d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Spanning Trees Let G1 = V1, E1 be a graph, and let G2 = V2, E2 be a subgraph of G1 such that G2 is a tree and V2 = V1.. Then G2 is a spanning tree for G1. a a c c b b d d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Complete Graphs A undirected graph G = V, E is complete provided ( (v, w) V V such that v w), {v, w } E. b a K5 c e d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Bipartite Graphs A undirected graph G = V, E is bipartite provided V can be divided into two distinct subsets V1 and V2 such that every edge of G connects an element of V1 to an element of V2 G is bipartite iff V1, V2 s.t. (V = V1 V2 ) (V1 V2 = ) ( (v, w) V V) ({v, w } E ( (v V1 w V2 ) (v V2 w V1 ) ) ) . b a K2,3 c e d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -
CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 - Weighted Digraphs G = V, E V = { a, b, c, d } E = { a, b, 3 , a, d, 8 , a, c, 0 } a 3 c 8 b d CSE 373, Copyright S. Tanimoto, 2002 Graphs 1 -