170 likes | 1.03k Views
V = { a, b, c, d, e, f, g, h, i, j, k, l }. E = { ( a, b ) , ( a, e ) , ( b, e ) , ( b, f ) , ( c, j ) , ( c, g ) , ( c, h ) , ( d, h ) , ( e, j ) , ( g, k ) , ( g, l ) , ( g, h ) , ( i, j ) }. Graph. A graph G is a set V ( G ) of vertices ( nodes ) and a set E ( G ) of
E N D
V = { a, b, c, d, e, f, g, h, i, j, k, l } E = { (a, b), (a, e), (b, e), (b, f), (c, j), (c, g), (c, h), (d, h), (e, j), (g, k), (g, l), (g, h), (i, j) } Graph A graphG is a set V(G) of vertices (nodes) and a set E(G) of edges which are pairs of vertices. a b c d e f g h i j k l
TW 45 BOS NW 35 ORD SFO DL 247 JFK AA 903 DL 335 UA 877 AA 1387 UA 120 MIA AA 49 AA 523 LAX DFW AA 411 A Directed Graph In a directed graph (digraph), edges are ordered pairs. From Goodrich and Tamassia (1998)
George Paul Linda Ringo Yoko John Applications of Graphs Graphs describe relationships The Internet Streets / Highways (Roadmaps) Molecules Flow Charts Social Networks Geometric Surfaces (CAD) Circuits Parts in an Assembly …
A pseudograph is a multigraph that allows self-loops (edges from a vertex to itself). 2 1 3 5 6 4 More General Graphs A multipgraphallows multiple edges between two vertices. a c b d f
deg(w) = 1 e 2 degree(u) = 2 e 1 incident on u and v c source b a e destination d Edges & Degrees w u u and v are adjacent endpoint v in-degree(b) = 3 out-degree(b) = 4
∑ deg(v) = 2 | E | v V 4 2 K has ( ) = 6 edges 4 If G is directed: ∑ ∑ indeg(v) = outdeg(v) = | E | v V v V Handshaking Theorem Let G = (V, E) be an undirected simple graph. | E | ≤ | V | · (| V | – 1) / 2 | E | ≤ | V | · (| V | – 1)
a b c d Simple path: a, e, k, p, l, q m, h, d, c, g e f h g (no repeated vertices) m j k l p q n o Path A path of length k is a sequence v , v , …, v of vertices such that (v , v ) for i = 0, 1, …, k – 1 is an edge of G. 0 1 k i i+1 b, c, d not a path Non-simple path: a, b, e, f, g, b, g, l
Cycle A cycle is a path that starts and ends at the same vertex. A simple cycle has no repeated vertices. a b c d e f h g m j k l k, j, n, k, p, o,k is not simple. p q n o
Subgraph A subgraphH of G is a graph; its edges and vertices are subsets of those of G. a b c d e f h g m j k l p q n o V(H) = {b, d, e, f, g, h, l, p, q} E(H) = {(b, e), (b, g), (e, f), (d, h), (l, p), (l, q)}
a d f g b c f e C 3 C 2 a C d e 1 b c Connectivity G is connected if there is a path between every pair of vertices. If G is not connected, the maximal connected subgraphs are the connected componentsof G.
It is weakly connected if the underlying undirected graph is connected. c f a b e d Strong & Weak Connectivity A directed graph is strongly connected if every two vertices are reachable from each other. b a e f d c
If G is connected, then | E | ≥ | V | – 1. If G is a tree, then | E | = | V | – 1. If G is a forest, then | E | ≤ | V | – 1. Property of Connectivity Let G = (V, E) be an undirected graph.
Adj 1 2 2 3 5 2 1 3 1 3 3 1 2 4 5 4 3 5 5 4 5 1 3 4 Adjacency Lists If G is directed, the total length of all the adjacency lists is | E |. If G is undirected, the total length is 2 | E |. Space requirement: (|V| + |E|). Preferable representation.
A = (a ) ij 2 1 if (i, j) E(G) a = 1 3 ij 0 otherwise 1 2 3 4 5 5 4 • 0 1 1 0 1 • 1 0 1 0 0 • 1 1 0 1 1 • 0 0 1 0 1 • 1 0 1 1 0 2 Space: (|V| ). Adjacency Matrix Preferred when the graph is small or dense.
Test adjacency of u and v (min(deg(u), deg(v)) (1) 2 Space (|V|+|E|) (|V| ) Lecture notes modified over Dr. Fernandez-Baca’s Operation Time Operation Adjacency List Adjacency Matrix Scan incident edges (deg(v)) (|V|) Scan outgoing edges (outdeg(v)) (|V|) Scan incoming edges (indeg(v)) (|V|)