Graphs

28
Graphs A Graph G = (V, E) consists of V, a nonempty set of vertices (or nodes) and E, a set of edges. Each edge has either one or two vertices associated with it, called its endpoints. An edge is said to connect its endpoints. A very simple Computer Network : An example of a simple graph It is also an undirected graph (edges have no Tampa Chicago Miami Denver LA No two different edge connect the same pair of vertices

description

Denver. Chicago. LA. Miami. Tampa. Graphs. A Graph G = (V, E) consists of V, a nonempty set of vertices (or nodes ) and E, a set of edges . Each edge has either one or two vertices associated with it, called its endpoints. An edge is said to connect its endpoints. - PowerPoint PPT Presentation

Transcript of Graphs

Page 1: Graphs

GraphsA Graph G = (V, E) consists of V, a nonempty set of vertices (or nodes) and E, a set of edges. Each edge has either one or two vertices associated with it, called its endpoints. An edge is said to connect its endpoints.

A very simple Computer Network : An example of a simple graph

It is also an undirected graph (edges have no direction).

Tampa

Chicago

Miami

Denver

LA

No two different edge connect the same pair of vertices

Page 2: Graphs

Tampa

Chicago

Miami

Denver

LA

Now each edge has a direction associated to it. The edges are called directed edges and the graph is called a directed graph.

A directed edge is associated with an ordered pair of vertices (u, v). The edge is said to start at u and end at v.

Note that e = (u, v) and f = (v, u) are two different directed edges

Page 3: Graphs

Chicago

Miami

Denver

LA

There are multiple edges (edges connecting the same pair of vertices).

The graph is not simple and is called (undirected) multigraphs.

Page 4: Graphs

Tampa

Chicago

Miami

Denver

LA

There are loops in the graph, and the graph is sometimes called a pseudograph.

Page 5: Graphs

Example: Acquaintanceship Graph

Use graph to represent various relationships between people.

John

Mary

Helen

Charles

Doug

Edge connecting two people when they know each other.

The graph is undirected with no multiple edges, or loops.

Page 6: Graphs

Example: Call Graphs

Use graph to model telephone calls made in a network (say a long distance telephone network).

352-343-3424

352-343-1453

352-343-6745

352-343-2563

Each directed edge (u, v) represents a call from u to v.

Vertices are phone numbers.

A directed graph

Page 7: Graphs

Example: The Web Graph

The World Wide Web can be modeled as a directed graph.

A vertex represents a web page and a directed edge (u, v) represents a link on u pointing to v.

WebCT

Cot3100Homepage

Slides

Extra Credit Assignment

Each directed edge (u, v) represents a link on u pointing to v.

Vertices are web pages.

A directed graph

Page 8: Graphs

Graph TerminologyTwo vertices u and v in an undirected graph G are called adjacent (or neighbors) in G if u and v are endpoints of an edge of G.

If e is associated with { u, v }, the edge e is called incident with the vertices u and v. The edge e is also said to connect u and v, and u and v are endpoints of e.

The degree of a vertex in an undirected graph is the number of edges incident with it (a loop contributes twice to the degree of that vertex).

Page 9: Graphs

John

Mary

Helen

Charles

Doug

deg ( Mary) = 3, deg(John) = 1, deg(Charles)=2, deg(Doug)= 2 and

deg(Helen) = 2.

Page 10: Graphs

The Handshaking TheoremLet G = (V, E) be an undirected graph with e edges. Then

2 e = Σv deg(v)

If we add all the degrees (of vertices), each edge will be counted twice. Hence the result.

Corollary: An undirected graph has an even number of vertices of odd degree.

2 e = Σv deg(v) = Σ v:odd deg(v) + Σ v:even deg(v)

Page 11: Graphs

John

Mary

Helen

Charles

Doug

deg ( Mary) = 3, deg(John) = 1, deg(Charles)=2, deg(Doug)= 2 and

deg(Helen) = 2.

The sum of all degrees is 10

There are 5 edges.

There are two vertices with odd degree.

Page 12: Graphs
Page 13: Graphs

352-343-3424 out-degree=1, in-dgree=2

352-343-1453In-degree=3out-degree=2

352-343-6745 out-degree=4

352-343-2563 in-degree = 3, out-degree=1

Page 14: Graphs
Page 15: Graphs
Page 16: Graphs
Page 17: Graphs

Cycles n vertices, v1, v2, ….., vn and edges

{ v1, v2 }, …, {vn-1, vn }

Page 18: Graphs
Page 19: Graphs
Page 20: Graphs
Page 21: Graphs
Page 22: Graphs

e

f

g

a bc

d

{a, b, d }, {c, e, f, g}

K3, 4

Page 23: Graphs
Page 24: Graphs

Males, or warehouses

females, or suppliers

Page 25: Graphs

If a is in V1, then, b, d, e must be in V2 (why?)

Then, c is in V1 and there is no inconsistency.

So we can rearrange the graph as follows:

Page 26: Graphs
Page 27: Graphs
Page 28: Graphs