Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graph A graph G is a set V(G) of vertices (nodes) and a set E(G) of edges which are pairs of vertices. abcd e i fgh jkl V = { a, b, c, d, e, f, g, h, i,

Similar presentations


Presentation on theme: "Graph A graph G is a set V(G) of vertices (nodes) and a set E(G) of edges which are pairs of vertices. abcd e i fgh jkl V = { a, b, c, d, e, f, g, h, i,"— Presentation transcript:

1 Graph A graph G is a set V(G) of vertices (nodes) and a set E(G) of edges which are pairs of vertices. abcd e i fgh jkl 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) }

2 A Directed Graph In a directed graph (digraph), edges are ordered pairs. TW 45 UA 120 AA 49 AA 411 AA 523 AA 1387 DL 335 UA 877 AA 903 DL 247 NW 35 From Goodrich and Tamassia (1998) SFO ORD BOS JFK LAX DFW MIA

3 Applications of Graphs Graphs describe relationships The Internet Streets / Highways (Roadmaps) Molecules Social Networks Geometric Surfaces (CAD) Circuits Parts in an Assembly … John Yoko Ringo George Paul Linda Flow Charts

4 More General Graphs A multipgraph allows multiple edges between two vertices. a bdf c A pseudograph is a multigraph that allows self-loops (edges from a vertex to itself). 1 5 4 2 3 6

5 Edges & Degrees u w v e e 1 2 endpoint incident on u and v degree(u) = 2 deg(w) = 1 b a d e c destination source in-degree(b) = 3 out-degree(b) = 4 u and v are adjacent

6 Handshaking Theorem Let G = (V, E) be an undirected simple graph. ∑ deg(v) = 2 | E | v  Vv  V If G is directed: ∑∑ v  Vv  Vv  Vv  V indeg(v) = outdeg(v) = | E | | E | ≤ | V | · (| V | – 1) / 2 K has ( ) = 6 edges 4 4242 | E | ≤ | V | · (| V | – 1)

7 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 g a e j n b f k dc o h l p m q Non-simple path: a, b, e, f, g, b, g, l Simple path: a, e, k, p, l, q m, h, d, c, g (no repeated vertices) b, c, d not a path

8 Cycle a e j n b f k dc o g h l p m q A cycle is a path that starts and ends at the same vertex. A simple cycle has no repeated vertices. k, j, n, k, p, o,k is not simple.

9 Subgraph a e j n b f k d c o g h l p m q A subgraph H of G is a graph; its edges and vertices are subsets of those of G. 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)}

10 Connectivity G is connected if there is a path between every pair of vertices. a b d f e c If G is not connected, the maximal connected subgraphs are the connected components of G. efg a c b d C C C 1 3 2

11 Strong & Weak Connectivity A directed graph is strongly connected if every two vertices are reachable from each other. a f e c d b It is weakly connected if the underlying undirected graph is connected. f e a d c b

12 Property of Connectivity Let G = (V, E) be an undirected graph. 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.

13 Adjacency Lists 2 13 54 23513 1245 35 134 If G is directed, the total length of all the adjacency lists is | E |. 1 2 3 4 5 Adj If G is undirected, the total length is 2 | E |. Space requirement:  (|V| + |E|). Preferable representation.

14 Adjacency Matrix 2 13 54 ij A = (a ) a = ij 1 if (i, j)  E(G) 0 otherwise 10 1 1 0 1 21 0 1 0 0 31 1 0 1 1 40 0 1 0 1 51 0 1 1 0 1 2 3 4 5 Space:  (|V| ). 2 Preferred when the graph is small or dense.

15 Operation Time Operation Adjacency List Adjacency Matrix Scan incident edges  (deg(v))  (|V|) Test adjacency of u and v  (min(deg(u), deg(v))  (1) Scan outgoing edges  (outdeg(v))  (|V|) Scan incoming edges  (indeg(v))  (|V|) Lecture notes modified over Dr. Fernandez-Baca’s Space  (|V|+|E|)  (|V| ) 2


Download ppt "Graph A graph G is a set V(G) of vertices (nodes) and a set E(G) of edges which are pairs of vertices. abcd e i fgh jkl V = { a, b, c, d, e, f, g, h, i,"

Similar presentations


Ads by Google