0% found this document useful (0 votes)
2 views

DS Lecture 17 Graphs

The document outlines a lecture on Discrete Structures focusing on various types of graphs, including complete graphs, cycles, wheels, and bipartite graphs. It explains how to represent graphs using adjacency lists and matrices, as well as concepts like sub-graphs, paths, distances, and eccentricity. Additionally, it provides examples and theorems related to graph properties and representations.

Uploaded by

fa21-bse-123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DS Lecture 17 Graphs

The document outlines a lecture on Discrete Structures focusing on various types of graphs, including complete graphs, cycles, wheels, and bipartite graphs. It explains how to represent graphs using adjacency lists and matrices, as well as concepts like sub-graphs, paths, distances, and eccentricity. Additionally, it provides examples and theorems related to graph properties and representations.

Uploaded by

fa21-bse-123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Department Of Computer Science, CUI

Lahore Campus

CSC102 - Discrete Structures


By
Mahwish Waqas
12/19/2021 CSC102 - Discrete Structures 2

Lecture Outline

• Graphs
• Special Graph Structures
• Sub Graph
• Adjacency List and Adjacency Matrix
• Incidence Matrix
• Path and Distance Matrix
12/19/2021 Discrete Structures 3

Special Graph Structures


• Special cases of undirected graph structures:
• Complete graphs 𝐾𝐾𝑛𝑛
• Cycles 𝐶𝐶𝑛𝑛
• Wheels 𝑊𝑊𝑛𝑛
• Bipartite graphs
12/19/2021 Discrete Structures 4

Complete Graphs
• For any 𝑛𝑛 ∈ 𝑁𝑁, a complete graph on n vertices, denoted
by 𝐾𝐾𝑛𝑛 , is a simple graph with n nodes in which every node
is adjacent to every other node.∀𝑢𝑢,𝑣𝑣∈𝑉𝑉 : 𝑢𝑢 ≠ 𝑣𝑣 ↔ {𝑢𝑢, 𝑣𝑣} ∈ 𝐸𝐸.

• A simple graph for which there is at least one pair of


distinct vertex not connect with edge is called non
complete.
• Note that 𝐾𝐾𝑛𝑛 has 𝑛𝑛(𝑛𝑛 − 1)/2 edges. K4
12/19/2021 Discrete Structures 5

Cycles
• For any 𝑛𝑛 ≥ 3, a cycle on n vertices, denoted by 𝐶𝐶𝑛𝑛 , is a
simple graph where 𝑉𝑉 = 𝑣𝑣1 , 𝑣𝑣2 , … , 𝑣𝑣𝑛𝑛 𝑎𝑎𝑎𝑎𝑎𝑎 𝐸𝐸 = {{𝑣𝑣1 ,
𝑣𝑣2 }, {𝑣𝑣2 , 𝑣𝑣3 }, … , {𝑣𝑣𝑛𝑛−1 , 𝑣𝑣𝑛𝑛 }, {𝑣𝑣𝑛𝑛 , 𝑣𝑣1 }}.

• How many edges are there in 𝐶𝐶𝑛𝑛 = 𝑛𝑛. C4


12/19/2021 Discrete Structures 6

Wheels
• For any 𝑛𝑛 ≥ 3, a wheel 𝑊𝑊𝑛𝑛 , is a simple graph obtained by
taking the cycle 𝐶𝐶𝑛𝑛 and adding an extra vertex 𝑉𝑉ℎ𝑢𝑢𝑢𝑢 and n
extra edges where {{𝑣𝑣ℎ𝑢𝑢𝑢𝑢 , 𝑣𝑣1 }, {𝑣𝑣ℎ𝑢𝑢𝑢𝑢 , 𝑣𝑣2 }, … , {𝑣𝑣ℎ𝑢𝑢𝑢𝑢 , 𝑣𝑣𝑛𝑛 }}.

• How many edges are there in 𝑊𝑊𝑛𝑛 = 2𝑛𝑛. W3


12/19/2021 Discrete Structures 7

Bipartite Graph
• A graph G = {V, E} is bipartite graph (two parts) if and only
if 𝑉𝑉 = 𝑉𝑉1 𝑈𝑈 𝑉𝑉2 𝑤𝑤𝑤𝑤𝑤𝑤𝑤𝑤𝑤 𝑉𝑉1 ∩ 𝑉𝑉2 = ∅ and ∀𝑒𝑒∈𝐸𝐸 : ∃𝑣𝑣1 ∈ 𝑉𝑉1 , 𝑣𝑣2 ∈
𝑉𝑉2 : 𝑒𝑒 = {𝑣𝑣1 , 𝑣𝑣2 }
• The graph vertices can be divided into two parts in such a
way that all edges go between the two parts. (No edge in
G connects either two vertices in V1 or two vertices in
V2).
12/19/2021 Discrete Structures 8

Example
12/19/2021 Discrete Structures 9

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.
12/19/2021 Discrete Structures 10

Example
• Is this bipartite?
a b

g
c

f
e d
12/19/2021 Discrete Structures 11

Example
• Bipartite Graph
12/19/2021 Discrete Structures 12

Example
12/19/2021 Discrete Structures 13

Example
12/19/2021 Discrete Structures 14

Complete Bipartite Graphs


A complete bipartite graph Km,n is a graph that has its vertex
set partitioned into two subsets of m and n vertices, respectively
with an edge between two vertices iff one vertex is in the first
subset and the other vertex is in the second subset.
12/19/2021 Discrete Structures 15

Sub-graphs
• A sub-graph of a graph G = (V ,E) is a graph H = (W, F),
where W ⊆ V and F ⊆ E.
• A sub-graph H of G is a proper sub-graph of G if 𝐻𝐻 ≠ 𝐺𝐺.

G H
12/19/2021 Discrete Structures 16

How to Represent a Graph?


• Mathematically, a graph G is represented by two sets:
vertex set V and edge Set E.
• G = (V, E), a tuple of two sets.
• How to represent a graph by computer?

• V = { a, b, c, d, e, f }

• E = {{a,b},{a,c},{b,c},
{b,e},{b,f},{c,f}}
12/19/2021 Discrete Structures 17

Adjacency List
• A table with 1 row per vertex, listing its adjacent vertices.
12/19/2021 Discrete Structures 18

Adjacency Matrix
• Matrix 𝐴𝐴 = [𝑎𝑎𝑖𝑖𝑖𝑖 ], where 𝑎𝑎𝑖𝑖𝑖𝑖 is 1 if {𝑣𝑣𝑖𝑖 , 𝑣𝑣𝑗𝑗 } is an edge of G,
and is 0 otherwise.
12/19/2021 Discrete Structures 19

Adjacency List for Directed Graph


12/19/2021 Discrete Structures 20

Adjacency Matrix for Directed Graph


12/19/2021 Discrete Structures 21

Adjacency Matrix for Directed Graph


12/19/2021 Discrete Structures 22

Example
Draw a undirected graph with the adjacency matrix

0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0

with respect to the ordering of vertices a, b, c, d.


12/19/2021 Discrete Structures 23

Example

Find the adjacency matrix of pseudograph?


12/19/2021 Discrete Structures 24

Incidence Matrix
• Let 𝐺𝐺 = (𝑉𝑉, 𝐸𝐸) be an undirected graph. Suppose that
1,2, … , 𝑛𝑛 are the vertices and 𝑒𝑒1 , 𝑒𝑒2 , … , 𝑒𝑒𝑚𝑚 are the edges of
G. Then the incidence matrix with respect to this ordering
of V and E is 𝑛𝑛 × 𝑚𝑚 matrix M = [𝑚𝑚𝑖𝑖𝑖𝑖 ], where
1 𝑤𝑤𝑤𝑤𝑤𝑤𝑤 𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒 𝑒𝑒𝑗𝑗 𝑖𝑖𝑖𝑖 𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖𝑖 𝑜𝑜𝑜𝑜 𝑖𝑖.
• 𝑚𝑚𝑖𝑖𝑖𝑖 = �
0 𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜𝑜
12/19/2021 Discrete Structures 25

Example
12/19/2021 Discrete Structures 26

Path
• A path is a sequence of edges that begins at a vertex of a
graph and travels from vertex to vertex along edges of the
graph.

• Find a path between a and e.


12/19/2021 Discrete Structures 27

Path
Find a path between a and e.

• a, d, c, f , e is a simple path of length 4, because {a, d}, {d, c},


{c, f }, and {f, e} are all edges.
• a, e is a simple path of length 1, because {a, e} is the edge
connecting both vertices.
• a, b, f , e is a simple path of length 3, because {a, b}, {b, f}, and
{f, e} are all edges.
12/19/2021 Discrete Structures 28

Graph Distance
• The graph distance between two vertices in a graph is the
number of edges in a shortest path connecting them.

• Also known as the geodesic distance.

• There may be more than one shortest path between two


vertices.

• If we compute the distance between every pair of vertices


of graph G, we can construct a distance matrix D.
12/19/2021 Discrete Structures 29

Eccentricity
• The eccentricity 𝒆𝒆(𝒗𝒗) of a vertex 𝒗𝒗 in a connected graph
𝑮𝑮(𝑽𝑽, 𝑬𝑬) is max 𝒅𝒅(𝒖𝒖, 𝒗𝒗), for all 𝒖𝒖 ∈ 𝑽𝑽. In other words, a
vertex’s eccentricity is equal to the distance from itself to
the vertex farthest away.

• The minimum eccentricity of all vertices in a graph is


called the radius of the graph,

• The maximum eccentricity of all vertices in a graph is the


diameter of the graph.
12/19/2021 Discrete Structures 30

Example
Draw a undirected graph with the adjacency matrix

0 1 1 0
1 0 1 1
1 1 0 1
0 1 1 0

with respect to the ordering of vertices a, b, c, d.


Find distance matrix of graph, eccentricity of each vertex,
diameter and radius of graph.
12/19/2021 Discrete Structures 31

Example (Solution)

Un-directed Graph

Eccentricity of Radius and Diameter


each vertex of Graph
Distance Matrix

You might also like