Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Week11 2graph011

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

CS 182: Graphs 1 (Week 11.2 – KR 10.1 - 10.

3)

Elisha Sacks and Sarah Sellke


Graphs

▶ Introduction:
▶ Examples of Graph Models
▶ Graph Terminology
▶ Basic Graph Properties: The Handshaking Theorem
▶ Graph Representations
▶ Important Types of Graphs:
▶ Complete Graphs
▶ Cycles and Wheels
▶ Bipartite Graphs
▶ Directed Graphs
Graphs

b h z
u v
y g
d c
a
x w f
e
▶ A graph consists of a set of vertices and a set of edges.
▶ A vertex is a primitive object (a and b).
▶ An edge is an unordered pair of vertices (u and v ).
▶ Graphs are drawn as circles connected by curves.
▶ Applications label the vertices and edges with data.
▶ Example: vertices are cities and edges are driving distances.
Simple Graph

A simple graph has no loops and no multiple edges:


▶ No loops: Each edge connects two different vertices.
▶ No multiple edges: No two edges connect the same pair of
vertices.
▶ We will use the term graph to denote a simple graph.
Multigraphs and Pseudographs

▶ Multigraphs have multiple edges connecting the same two


vertices.
▶ A pseudograph include loops, as well as multiple edges
connecting the same pair of vertices.
Graph Models: Social Networks

Figure: A friendship graph


Graph Models: Biological Applications

Niche Overlap Graphs model competition between species in an


ecosystem:
▶ Vertices represent species.
▶ An edge connects two vertices when they compete for food
resources.
Terminology 1

b h z
u v
y g
d c
a
x w f
e
▶ The vertices of an edge are its endpoints (u has a and b).
▶ An edge and its endpoints are incident (u and a).
▶ The endpoints of an edge are adjacent (a and b).
▶ An adjacent vertex is a neighbor (b, d, and e for c).
▶ The number of neighbors is the vertex degree (3 for c).
▶ Vertices and edges are also called nodes and links.
Terminology 2

▶ The set of all neighbors of a vertex v of G = (V , E ), denoted


by N(v ), is called the neighborhood of v .
▶ If A is a subset of V , we denote by N(A) the set of all vertices
in G thatSare adjacent to at least one vertex in A. So,
N(A) = v ∈A N(v ).

[Example 1] Find the degree and the neighborhood of each vertex


in Graphs G and H.
Example 1
Find the degree and the neighborhood of each vertex in Graphs G
and H.

▶ G: deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1,


deg(e) = 3, deg(g) = 0. N(a) = {b, f }, N(b) = {a, c, e, f },
N(c) = {b, d, e, f }, N(d) = {c}, N(e) = {b, c , f },
N(f) = {a, b, c, e}, N(g) = {}, N({a,b, c}) = {a,b,c,d,e,f}
▶ H: deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, deg(d) = 5.
N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b},
N(d) = {a, b, e}, N(e) = {a, b ,d}.
Handshake Theorem

b h z
u v
y g
d c
a
x w f
e
The sumXof the degrees of the vertices equals twice the number of
edges. deg (v ) = 2|E |
v ∈V

Proof Each edge contributes to the degrees of two vertices.


Our graph has 6 edges and 12 neighbor relations.
Using the Handshake Theorem

Example 2: How many edges are there in a graph consisting of 10


vertices, each of degree three?
Using the Handshake Theorem

Example 2: How many edges are there in a graph consisting of 10


vertices, each of degree three?
Solution: Because the sum of the degrees of the vertices is
3 × 10 = 30, the handshaking theorem tells us that 2m = 30.
Hence, the number of edges is m = 15.
Using the Handshake Theorem

Example 3: If a graph has 5 vertices, can each vertex have degree


3?

Solution: This is not possible. By the handshaking theorem, the


sum of the degrees of the vertices is 3 × 5 = 15 which is odd.
Matrix Representation
2

1 4 3

5
▶ A graph with n vertices can be represented by an n-by-n
matrix m in which mij = 1 when vi vj and 0 otherwise.
▶ The matrix m is symmetric.
▶ The space complexity is O(n2 ).
 
0 1 0 0 0

 1 0 1 0 0 


 0 1 0 1 1 

 0 0 1 0 1 
0 0 1 1 0
List Representation

1 4 3

5
▶ A graph can also be represented with an array of edge lists.
The ith element lists the vertices that are neighbors of vi .
▶ Example: ((2), (1, 3), (2, 4, 5), (3, 5), (3, 4))
▶ The space complexity is O(m + n) for a graph with n vertices
and m edges.
▶ Edge lists are generally superior for sparse graphs and inferior
for dense graphs.
Special Types of Graphs

k4 c4 w5 h3

▶ The complete graph kn has edges between all pairs of vertices.


▶ The cycle cn has n edges that form a closed simple curve.
▶ The wheel wn is a cycle plus a center vertex that is adjacent
to the other vertices.
▶ The n-dimensional hypercube hn consists of
▶ 2n vertices representing the 2n bit strings of length n.
▶ n2n−1 edges, with two vertices being adjacent only when the
bit strings they represent differ in exactly one bit position.
Bipartite Graphs 1

Definition: A simple graph G is bipartite if V can be partitioned


into two disjoint subsets V1 and V2 such that every edge in the
graph connects a vertex in V1 and a vertex in V2 . That is, no
edges connect two vertices in V1 or in V2 . We call the pair (V1 ,
V2 ) a bipartition of the vertex set V of G .
Bipartite Graphs 2

A simple graph is bipartite if and only if it is possible to color the


vertices red or blue so that no two adjacent vertices have the same
color.
Is G a bipartite graph? yes (V1 = {a, b, d}, V2 = {c, e, f , g })
Is H a bipartite graph? no (there are too many edges)
Bipartite Graphs 3
A B

▶ A complete bipartite graph Km,n is a graph that has its vertex


set partitioned into two subsets of m and n vertices, with an
edge between two vertices if and only if one vertex is the first
subset and the other is in the second subset.
▶ A matching is a subset of a bipartite graph in which every
vertex has degree one.
Our graph is bipartite with A black and B red.
Our graph is neither complete nor a matching.
Directed Graphs: Introduction

Figure: Model a network using a directed multigraph.

Definition: A directed graph (or digraph) G = (V, E) consists of a


set V of vertices and a set E of directed edges.
▶ Each edge is associated with an ordered pair of vertices.
▶ The directed edge associated with the ordered pair (u,v) is
said to start at u and end at v.
Graph Models: Social Networks

Figure: An influence digraph


Directed Graphs 1

b h

g
a d c
f
e
▶ A directed graph has ordered pairs of vertices as edges.
▶ An edge ab is drawn as an arrow from a to b.
▶ The tail of ab is a and the head is b.
▶ The matrix and edge list representations carry over.
Directed Graphs 2

▶ The in-degree of a vertex v, denoted deg − (v ), is the number


of edges which terminate at v.
▶ deg − (a) = 2, deg − (b) = 2, deg − (c) = 3
▶ deg − (d) = 2, deg − (e) = 3, deg − (f ) = 0
▶ The out-degree of v, denoted deg + (v ), is the number of
edges with v as their initial vertex.
▶ deg + (a) = 4, deg + (b) = 1, deg + (c) = 2
▶ deg + (d) = 2, deg + (e) = 3, deg + (f ) = 0
Directed Graphs 3
TheoremX3: Let G = (V,
XE) be a graph with directed edges. Then
|E | = +
deg (v ) = deg − (v )
v ∈V v ∈V
Proof:
▶ The first sum v ∈V deg + (v ) counts the number of outgoing
P
edges over all vertices and
▶ the second sum v ∈V deg − (v ) counts the number of
P
incoming edges over all vertices.
▶ Both sums equal the number of edges in the graph.

You might also like