Download presentation

Presentation is loading. Please wait.

1
Representing Graphs Wade Trappe

2
Lecture Overview Introduction Some Terminology –Paths Adjacency Matrix

3
Paths and Cycles, pg. 1 Definition: Let v 0 and v n be vertices in a graph. A path from v 0 to v n of length n is an alternating sequence of n+1 vertices and n edges beginning with v 0 and ending with v n, where e i starts at v i-1 and ends at v i. (v 0, e 1, v 1, e 2, v 2, …, v n-1, e n, v n ) Example: (1, e 1, 2, e 2, 3, e 3, 4, e 4, 2) 2 1 3 5 4 6 7e1e1 e3e3 e2e2 e5e5 e7e7 e6e6 e8e8 e4e4 Length 4 path

4
Paths and Cycles, pg. 2 Definition: A connected graph is a graph in which we can get from any vertex to any other vertex via a path. Formally, a graph G is connected if given any vertices v and w in G, there is a path from v to w. 2 1 3 5 4 6 7e1e1 e3e3 e2e2 e5e5 e7e7 e6e6 e4e4 Not Connected e8e8 Connected

5
Paths and Cycles, pg. 3 Obviously, a not-connected graph consists of several pieces. These pieces are subgraphs, or components. Definition: Let G=(V,E) be a graph. We call (V’, E’) a subgraph of G if: For every edge, if e’ is starts at v’ and ends at w’, then Note: You don’t have to include edges! A single vertex is a subgraph! The definition of a subgraph just requires that if you do select an edge, then you must have both ends of it!

6
Paths and Cycles, pg. 4 There are many choices for subgraphs! 1 A Subgraph 2 Another Subgraph 2 1 e1e1 G 2 1 A subgraph Without edges 2 1 e1e1 The entire Graph is a Subgraph!

7
Paths and Cycles, pg. 5 Definition: Let v and w be vertices in a graph. –A simple path from v to w is a path from v to w with no repeated vertices. –A cycle is a path of nonzero length from v to v with no repeated edges –A simple cycle is a cycle from v to v in which, except for the beginning and end, there are no repeated vertices. Example: We will look again at the original graph as an example.

8
Paths and Cycles, pg. 6 2 1 3 5 4 6 7e1e1 e3e3 e2e2 e5e5 e7e7 e6e6 e8e8 e4e4 (6,5,2,4) is a simple path It is not a cycle! (2,6,5,2,4,3,2) is not a simple path It is a cycle, but is not a simple cycle.

9
Konigsberg Bridges, pg. 1 Consider two islands lying in the Pregel River in Konigsberg, connected to each other and the river banks. The challenge: start at A,B,C or D and walk over each bridge exactly once then return the start. B D A D BC A D

10
Konigsberg Bridges, pg. 2 The bridge can be modeled as a graph, where edges are bridges. The Konigsberg Bridge problem is now: Find a cycle in the graph that includes all of the edges and all of the vertices. A cycle in a graph that includes all of the edges and all of the vertices of G is called an Euler Cycle. Note: There are an odd number of edges incident on vertex A… so, if you leave A and come back to A, you use an even amount of vertices… hence, you can’t solve the Konigsberg Bridge problem. The degree of a vertex v, denoted d(v) is the number of edges incident on v. (A loop counts twice).

11
About the Degree… Sum of all the degrees in a graph is an even #: If G is a graph with m edges and vertices {v 1, …, v n } then d(v i ) = 2m. Proof: When we sum over the degrees of all the vertices, we count each edge (v i, v j ) twice… Once when we count it as (v i,v j ) in the degree of v i and then once again when we count it as (v j, v i ) in the degree of v i.

12
Representation of Graphs, pg. 1 Rather than always draw pictures, it is generally useful to have a data-structured representation for graphs. This is where the adjacency matrix A comes in. The row i, column j entry describes the amount of edges that touch node i and node j. a b ed c

13
Representation of Graphs, pg. 2 The powers of A count the number of paths of various lengths: –The (i,j)-th entry in the matrix A n is the number of paths from i to j of length n. Example: a d a and a b a gives the 2 a a paths.

Similar presentations

© 2023 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google