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

Graphs

8 GRAPHS
Graphs are among the most ubiquitous models of relations and process dynamics in computer science,
physical, biological and social systems. Vehicle routing, distance minimizations, graph and map coloring,
task scheduling, and data compression are among some those that can be represented by graphs. This
module will project the idea of graph theory and demonstrate its importance in mathematics, computer
science, and technology.

Objectives:

After completing this module, you should be able to:

1. Describe graphs.
2. Construct graph based on the given vertices and edges.
3. Differentiate the different kinds of graphs.
4. Explain the different kinds of graphs.
5. Analyze and apply graph to solve a problem.

DISCRETE STRUCTURES 1 74
Graphs

Introduction

Uses of Graph Theory in CS

 Car navigation system


 Efficient database
 Build a bot to retrieve info off WWW
 Representing computational models
 Many other applications.

This course focuses more on the properties of abstract graphs rather on graph algorithms.

Graph

 A graph G consists of two finite sets: a nonempty set V(G) of vertices and a set E(G) of edges,
where each edge is associated with a set consisting of either one or two vertices called its
endpoints.

The correspondence from edges to endpoints is called the edge-endpoint function.

An edge with just one endpoint is called a loop, and two or more distinct edges with the same
set of endpoints are said to be parallel. An edge is said to connect its endpoints, two vertices
that are connected by an edge are called adjacent, and a vertex that is an endpoint of a loop is
said to be adjacent to itself.

An edge is said to be incident on each of its endpoints, and two edges incident on the same
endpoint are called adjacent.

A vertex on which no edges are incident is called isolated.

Graphs illustrated

Graphs have pictorial representations in which the


vertices are represented by dots and the edges by line
segments.

A given pictorial representation uniquely determines a


graph.

The dots are called vertices (plural of vertex) and the


line segments joining vertices are called edges.

A loop is when an edge connects a vertex to itself.

Parallel is when two edges connect the same pair of vertices.

Isolated is a vertex unconnected by an edge to any other vertex in the graph.

DISCRETE STRUCTURES 1 75
Graphs

Example:

Write the vertex set and the edge set, and give a
table showing the edge-endpoint function.

Find all edges that are incident on v1, all vertices


that are adjacent to v1, all edges that are adjacent
to e1, all loops, all parallel edges, all vertices that
are adjacent to themselves, and all isolated
vertices.

Solution:

Write the vertex set and the edge set, and give a table showing the edge-endpoint function.

V = {v1, v2, v3, v4, v5, v6}

E= {e1, e2, e3, e4, e5, e6, e7}

Find all edges that are incident on v1, all vertices that are adjacent to v1, all edges that are
adjacent to e1, all loops, all parallel edges, all vertices that are adjacent to themselves, and all
isolated vertices.

e1, e2, and e3 are incident on v1.


v2 and v3 are adjacent to v1.
e2, e3, and e4 are adjacent to e1.
e6 and e7 are loops.
e2 and e3 are parallel.
v5 and v6 are adjacent to themselves.
v4 is an isolated vertex.

DISCRETE STRUCTURES 1 76
Graphs

Example:

Draw the pictorial representation of the graph specified

V= {v1, v2, v3, v4}

E= {e1, e2, e3, e4}

Solution:

Directed Graph

 A directed graph, or digraph, consists of two finite sets: a nonempty set V(G) of vertices and a
set D(G) of directed edges, where each is associated with an ordered pair of vertices called its
endpoints.
 If edge e is associated with the pair (v, w) of vertices, then e is said to be the (directed) edge
from v to w.
 Each edge of a directed graph can be drawn as an arrow going from the first vertex to the
second vertex of the ordered pair.
 i.e., A digraph is a graph whose edges are all directed.

Some applications of Directed Graph

 one-way streets
 flights
 task scheduling

DISCRETE STRUCTURES 1 77
Graphs

A graph G=(V,E) such that

Each edge goes in one direction:

Edge (a, b) goes from a to b, but not b to a.

Telephone, electric power, gas pipeline, and air transport systems can all be
represented by graphs, as can computer networks—from small local area networks to the global
Internet system that connects millions of computers worldwide.

Questions that arise in the design of such systems involve choosing connecting edges to
minimize cost, optimize a certain type of service, and so forth.

Example:

Draw the pictorial representation of the graph specified

V= {0, 1, 2, 3, 4, 5, 6}

E= {(0, 2), (0, 4), (0, 5), (1, 0), (2, 1), (2, 5), (3, 1), (3, 6), (4, 0), (4, 5), (6, 3), (6, 5)}

Solution:

Example:

Find the vertex set and edge set of the given


directed graph.

Solution:

V={u, v, w, x, y}

E={(u, v), (u, x), (v, w), (v, y), (x, w), (w, y)}

DISCRETE STRUCTURES 1 78
Graphs

Simple Graph

 A simple graph is a graph that does not have any loops or parallel edges. In a simple graph, an
edge with endpoints v and w is denoted {v, w}.
 In a simple graph, no two edges share the same set of endpoints, so specifying two endpoints is
sufficient to determine an edge.

Example:

Draw all simple graphs with the four vertices {u, v, w, x} and two edges, one of which is {u, v}.

Solution:

Each possible edge of a simple graph corresponds to a subset of two vertices. Given four vertices
and two edges, there are (42)= 6 such subsets in all: {u, v}, {u, w}, {u, x}, {v, w}, {v, x}, and {w, x}.

One edge of the graph is specified to be {u, v}, so any of the remaining five from this list can be
chosen to be the second edge. The possibilities are shown on the next page.

Complete Graph

 Let n be a positive integer. A complete graph on n vertices, denoted Kn, is a simple graph with n
vertices and exactly one edge connecting each pair of distinct vertices.
 A Complete Graph is a graph that has the maximum number of edges

For undirected graph with n vertices, the maximum number of edges is n(n-1)/2

For directed graph with n vertices, the maximum number of edges is n(n-1)

Example:

Given the vertex set and edge set

V = {0,1,2,3}

E = {(0,1),(0,2), (0,3),(1,2),(1,3), (2,3)}

n = n(n-1)/2 = 6 edges

Find the complete graph.

Solution:

DISCRETE STRUCTURES 1 79
Graphs

Example:

Given the vertex set and edge set

V = {0,1,2,3}

E = {{0, 1}, {0, 2}, {0, 3}, {1, 0}, {1, 2}, {1, 3}, {2, 0}, {2, 1}, {1, 3}, {3, 0}, {3, 1}, {3, 2} }

n = n(n-1) = 12

Find the complete graph.

Solution:

Complete Bipartite

 A simple graph G is called bipartite if its vertex set V can be partitioned into two disjoint sets V1
and V2 such that every edge in the graph connects a vertex in V1 and a vertex in V2 (so that no
edge in G connects either two vertices in V1 or two vertices in V2). When this condition holds,
we call the pair (V1, V2) a bipartition of the vertex set V of G.
 i.e., A Complete Bipartite Graph is a graph where each vertex in one of the subsets is connected
by exactly one edge to each vertex in the other subset, but not to any vertices in its own subset.

Example:

Given the two sets G1 = {v1, v3, v5} and G2 = {v2, v4, v6}, and every edge connects a vertex in G1
and a vertex in G2.

DISCRETE STRUCTURES 1 80
Graphs

Subgraph

 A graph H is said to be a subgraph of a graph G if, and only if, every vertex in H is also a vertex in
G, every edge in H is also an edge in G, and every edge in H has the same endpoints as it has in G.
 A subgraph of G is a graph G’ such that

V(G’)  V(G)

E(G’)  E(G)

Example:

Given the graph G, some of the subgraphs of G’ are

Degree

 Let G be a graph and v a vertex of G. The degree of v, denoted deg(v), equals the number of
edges that are incident on v, with an edge that is a loop counted twice.
 The total degree of G is the sum of the degrees of all the vertices of G.

Example:

Since an edge that is a loop is counted twice, the degree of a vertex can be obtained from the
drawing of a graph by counting how many end segments of edges are incident on the vertex.

DISCRETE STRUCTURES 1 81
Graphs

Example:

Find the degree of each vertex of the graph G shown below. Then find the total degree of G.

Solution:

deg(v1) = 0 since no edge is incident on v1 (v1 is isolated).

deg(v2) = 2 since both e1 and e2 are incident on v2.

deg(v3) = 4 since e1 and e2 are incident on v3 and the loop e3 is also incident on v3 (and
contributes 2 to the degree of v3).

total degree of G = deg(v1) + deg(v2) + deg(v3) = 0 + 2 + 4 = 6.

In-degree – Out-degree

 In a digraph D=(V,A), the in-degree of a vertex v is the number of edges leading to v, denoted by
d-(v);
 The out-degree of a vertex v is the number of edges leading away from v, denoted by d+(v).
 The degree of a vertex is the sum of its in-degree and its out-degree.

Example:

Find the in-degree and out-degree of each vertex in the


directed graph G.

Solution:

The in-degrees in G are

deg−(a) = 2, deg−(b) = 2, deg−(c) = 3, deg−(d) = 2, deg−(e) = 3, and deg−(f ) = 0.

The out-degrees are

deg+(a) = 4, deg+(b) = 1, deg+(c) = 2,deg+(d) = 2, deg+(e) = 3, and deg+(f ) = 0.

DISCRETE STRUCTURES 1 82
Graphs

Because each edge has an initial vertex and a terminal vertex, the sum of the in-degrees
and the sum of the out-degrees of all vertices in a graph with directed edges are the same. Both
of these sums are the number of edges in the graph.

DISCRETE STRUCTURES 1 83
Graphs

References:

1. Kenneth H. Rosen. Discrete Mathematics and Its Applications, 7th Edition. McGrawHill, 2012
2. Gary Weiss Damian Lyons, et al., Fundamentals of Discrete Structures, 2nd edition, Pearson
Learning Solutions, 2012.
3. Susanna S. Epp, Discrete Mathematics with Applications, Brooks Cole; 4th edition, 2011.
4. James L. Hein, Discrete Structures, Logic, and Computability, 3rd edition, Jones & Bartlett
Publishers, 3rd edition, 2009.
5. Kolman, B., Busby, R. C., Ross, S. C. Discrete Mathematical Structures, 6th Edition. Prentice Hall,
2008.

DISCRETE STRUCTURES 1 84

You might also like