0% found this document useful (0 votes)
28 views32 pages

Lecture 7

Uploaded by

amirtamo3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views32 pages

Lecture 7

Uploaded by

amirtamo3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Assiut University

‫قومية‬ ‫كلية‬
‫ل معتمدة من الهيئة ال عتماد‬
‫ضمان جودة التعليم واال‬

Course Title: Discrete Structures


Course Code: CS201

Prof. Dr. Khaled F. Hussain


Graphs and Graph Models
• DEFINITION: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.
Graphs
• Undirected graphs are a type of graph where the edges that
connect nodes (or vertices) do not have a specific direction.
• This means that you can traverse an edge in either direction.
Graphs (Cont.)
• A graph in which each edge connects two different vertices and where no two edges connect the same pair of
vertices is called a simple graph.
Graphs (Cont.)
• Graphs that may have multiple edges connecting the same vertices are called multigraphs.
Graphs (Cont.)
• Graphs that may include loops, and possibly multiple edges connecting the same pair of vertices or a vertex to
itself, are sometimes called pseudographs.
• Loops: edges that connect a vertex to itself.
Graphs (Cont.)
• A directed graph (or digraph) (V ,E) consists of a nonempty set of vertices V and a set of directed edges (or
arcs) E. Each directed 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.
Graphs (Cont.)
• Directed graphs that may have multiple directed edges from a vertex to a second (possibly the same) vertex
are used to model such networks. We called such graphs directed multigraphs. When there are m directed
edges, each associated to an ordered pair of vertices (u, v), we say that (u, v) is an edge of multiplicity m.
Graphs (Cont.)
• Graph Terminology
Graph Models
• SOCIAL NETWORKS
• In these graph models, individuals or organizations are represented by vertices;
relationships between individuals or organizations are represented by edges.
Graph Models (Cont.)
• Influence Graphs: In studies of group behaviour, it is observed that certain people can influence the thinking
of others. A directed graph called an influence graph can be used to model this behavior. Each person of the
group is represented by a vertex. There is a directed edge from vertex a to vertex b when the person
represented by vertex a can influence the person represented by vertex b.
Graph Models (Cont.)
• Collaboration Graphs: A collaboration graph is used to model social networks where two people are
related by working together in a particular way.
• In an academic collaboration graph, vertices represent people (perhaps restricted to members of a
certain academic community), and edges link two people if they have jointly published a paper. The
collaboration graph for people who have published research papers in mathematics was found in 2004 to
have more than 400,000 vertices and 675,000 edges.

• Call Graphs: Graphs can be used to model telephone calls made in a network.
• Each telephone number is represented by a vertex and each telephone call is represented by a directed edge.
• The edge representing a call starts at the telephone number from which the call was made and ends at the telephone
number to which the call was made.
• We need directed edges because the direction in which the call is made matters.
• We need multiple directed edges because we want to represent each call made from a particular telephone number to a
second number.
Graph Models (Cont.)
• The Web Graph: The World Wide Web can be modelled as a directed graph where each Web page is
represented by a vertex and where an edge starts at the Web page a and ends at the Web page b if there is a
link on a pointing to b. Because new Web pages are created and others removed somewhere on the Web
almost every second, the Web graph changes on an almost continual basis.

• Citation Graphs: Graphs can be used to represent citations in different types of documents. In such graphs,
each document is represented by a vertex, and there is an edge from one document to a second document if
the first document cites the second in its citation list.

• Road Networks: Graphs can be used to model road networks. In such models, vertices represent intersections
and edges represent roads.

• ….etc.
Graph Terminology
• Two 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 e of G.
• Such an edge e is called incident with the vertices u and v and e is said to connect u and v.

• The set of all neighbours 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 that are adjacent to at least one vertex in A. So, N(A)
= Uv∈A N(v).

• The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a
vertex contributes twice to the degree of that vertex. The degree of the vertex v is denoted by deg(v).
Graph Terminology (Cont.)
• EXAMPLE:
• deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1, deg(e) = 3, and deg(g) = 0.
• The neighborhoods of these vertices are 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}, and N(g) = ∅.
Graph Terminology (Cont.)
• EXAMPLE
• deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, and deg(d ) = 5.
• The neighborhoods of these vertices are N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b}, N(d) = {a, b, e},
and N(e) = {a, b, d}.
Graph Terminology (Cont.)
THE HANDSHAKING THEOREM Let G = (V ,E) be an undirected graph with m edges. Then
2𝑚 = ෍ 𝑑ⅇ𝑔 𝑣
𝑣𝜖𝑉
(Note that this applies even if multiple edges and loops are present.)

• Example: How many edges are there in a graph with 10 vertices each of degree six?
• Solution: Because the sum of the degrees of the vertices is 6 ・ 10 = 60, it follows that 2m = 60 where m
is the number of edges. Therefore, m = 30.
Graph Terminology (Cont.)
• When (u, v) is an edge of the graph G with directed edges, the vertex u is called the initial vertex of (u, v), and v
is called the terminal or end vertex of (u, v). The initial vertex and terminal vertex of a loop are the same.
• In a graph with directed edges the in-degree of a vertex v, denoted by deg− (v), is the number of edges with v as
their terminal vertex. The out-degree of v, denoted by deg+ (v), is the number of edges with v as their initial
vertex. (Note that a loop at a vertex contributes 1 to both the in-degree and the out-degree of this vertex.)
• EXAMPLE: Find the in-degree and out-degree of each vertex in the graph G with directed edges.
• 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.
Graph Terminology (Cont.)
• THEOREM: Let G = (V ,E) be a graph with directed edges. Then

෍ deg − 𝑣 = ෍ deg + 𝑣 = 𝐸
𝑣∈V 𝑣∈V
Some Special Simple Graphs
• Complete Graphs: A complete graph on n vertices, denoted by Kn, is a simple graph that contains exactly
one edge between each pair of distinct vertices.
Some Special Simple Graphs (Cont.)
• Cycles: A cycle Cn, n ≥ 3, consists of n vertices v1, v2, . . . , vn and edges {v1, v2}, {v2, v3}, . . . , {vn−1, vn},
and {vn, v1}.
Some Special Simple Graphs (Cont.)
• Wheels: We obtain a wheel Wn when we add an additional vertex to a cycle Cn, for n ≥ 3, and connect this
new vertex to each of the n vertices in Cn, by new edges.
Some Special Simple Graphs (Cont.)
• n-Cubes An n-dimensional hypercube, or n-cube, denoted by Qn, is a graph that has vertices representing
the 2n bit strings of length n. Two vertices are adjacent if and only if the bit strings that they represent differ in
exactly one bit position.
Some Special Simple Graphs (Cont.)
• 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.
• For example, consider the graph representing marriages between men and women in a village, where each
person is represented by a vertex and a marriage is represented by an edge. In this graph, each edge connects a
vertex in the subset of vertices representing males and a vertex in the subset of vertices representing females.
• The following figure show a bipartite graph, because its vertex set can be partitioned into the two sets V1 =
{v1, v3, v5} and V2 = {v2, v4, v6}, and every edge of C6 connects a vertex in V1 and a vertex in V2.
Some Special Simple Graphs (Cont.)
• THEOREM: A simple graph is bipartite if and only if it is possible to assign one of two different colors to
each vertex of the graph so that no two adjacent vertices are assigned the same color.
• Example: Use the Theorem to determine whether the following graph is bipartite.
• Solution: Yes

• Example: Use the Theorem to determine whether the following graph is bipartite.
• Solution: No
Representing Graphs
• Adjacency lists, which specify the vertices that are adjacent to each vertex of the graph.

• EXAMPLE: Use adjacency lists to describe the following simple


graph
Representing Graphs (Cont.)
• EXAMPLE: Use adjacency lists to describe the following Directed
Graph
Representing Graphs (Cont.)
• The adjacency matrix A (or AG) of G, with respect to this listing of the vertices, is the n x n zero–one matrix
with 1 as its (i, j )th entry when vi and vj are adjacent, and 0 as its (i, j )th entry when they are not adjacent.
1 𝑖𝑓 𝑣𝑖 , 𝑣𝑗 𝑖𝑠 𝑎𝑛 ⅇ𝑑𝑔ⅇ 𝑜𝑓 𝐺
𝑎𝑖𝑗 = ቊ
0 𝑜𝑡ℎⅇ𝑟𝑤𝑖𝑠ⅇ
• EXAMPLE: Use an adjacency matrix to represent the graph in the following Figure.
• Solution: We order the vertices as a, b, c, d. The matrix representing this graph is
Representing Graphs (Cont.)
• Draw a graph with the adjacency matrix with respect to the ordering of vertices a, b, c, d.
Representing Graphs (Cont.)
• The adjacency matrix of a simple graph is symmetric, that is, aij = aji , because both of these entries are 1 when
vi and vj are adjacent, and both are 0 otherwise. Furthermore, because a simple graph has no loops, each entry
aii, i = 1, 2, 3, . . . , n, is 0.
• Adjacency matrices can also be used to represent undirected graphs with loops and with multiple edges.
• A loop at the vertex vi is represented by a 1 at the (i, i)th position of the adjacency matrix.
• When multiple edges connecting the same pair of vertices vi and vj, or multiple loops at the same vertex,
are present, the adjacency matrix is no longer a zero–one matrix, because the (i, j )th entry of this matrix
equals the number of edges that are associated to {vi , vj }.
• EXAMPLE: Use an adjacency matrix to represent the following graph
Representing Graphs (Cont.)
• TRADE-OFFS BETWEEN ADJACENCY LISTS AND ADJACENCY MATRICES
• When a simple graph contains relatively few edges, that is, when it is sparse, it is usually preferable to
use adjacency lists rather than an adjacency matrix to represent the graph.
• Now suppose that a simple graph is dense, that is, suppose that it contains many edges, such as a graph
that contains more than half of all possible edges. In this case, using an adjacency matrix to represent the
graph is usually preferable overusing adjacency lists.
Representing Graphs (Cont.)
• Incidence matrices. Let G = (V ,E) be an undirected graph. Suppose that v1, v2, . . . , vn are the vertices and
e1, e2, . . . , em are the edges of G. Then the incidence matrix with respect to this ordering of V and E is the n ×
m matrix M = [mij ], where
1 when edge ⅇ𝑗 is incident with 𝑣𝑖
𝑚𝑖𝑗 = ቊ
0 otherwise.
• Example: Represent the following graph with an incidence matrix.

You might also like