1 / 13

Representing Graphs

Representing Graphs. Wade Trappe. Lecture Overview. Introduction Some Terminology Paths Adjacency Matrix. Paths and Cycles, pg. 1.

kiora
Télécharger la présentation

Representing Graphs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Representing Graphs Wade Trappe

  2. Lecture Overview • Introduction • Some Terminology • Paths • Adjacency Matrix

  3. Paths and Cycles, pg. 1 • Definition: Let v0 and vn be vertices in a graph. A path from v0 to vn of length n is an alternating sequence of n+1 vertices and n edges beginning with v0 and ending with vn, where ei starts at vi-1 and ends at vi. (v0, e1, v1, e2, v2, …, vn-1, en, vn) • Example: (1, e1, 2, e2, 3, e3, 4, e4, 2) 3 e2 Length 4 path e3 2 e4 4 e1 7 e6 1 e8 e5 e7 5 6

  4. Connected e8 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. Not Connected 3 e2 e3 2 e4 4 e1 7 e6 1 e5 e7 5 6

  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. 2 2 2 1 Another Subgraph e1 e1 A Subgraph 1 1 The entire Graph is a Subgraph! G 2 1 A subgraph Without edges Paths and Cycles, pg. 4 • There are many choices for subgraphs!

  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. (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. Paths and Cycles, pg. 6 3 e2 e3 2 e4 4 e1 7 e6 1 e8 e5 e7 5 6

  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. A A B B C D D 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 {v1, …, vn} then Sd(vi) = 2m. • Proof: When we sum over the degrees of all the vertices, we count each edge (vi, vj) twice… Once when we count it as (vi,vj) in the degree of vi and then once again when we count it as (vj, vi) in the degree of vi.

  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. b a c d e

  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 An 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.

More Related