0% found this document useful (0 votes)
3 views45 pages

DS-Lecture 14

The lecture covers various concepts related to graphs, including definitions of graphs, directed graphs, simple graphs, and complete graphs. It explains the structure of graphs, including vertices and edges, and introduces important concepts such as walks, trails, paths, circuits, and connectedness. Additionally, it discusses practical applications of graphs in problem-solving, such as the 'Vegetarians and Cannibals' puzzle.

Uploaded by

ashiak7786
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)
3 views45 pages

DS-Lecture 14

The lecture covers various concepts related to graphs, including definitions of graphs, directed graphs, simple graphs, and complete graphs. It explains the structure of graphs, including vertices and edges, and introduces important concepts such as walks, trails, paths, circuits, and connectedness. Additionally, it discusses practical applications of graphs in problem-solving, such as the 'Vegetarians and Cannibals' puzzle.

Uploaded by

ashiak7786
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/ 45

Discrete Structures

(CS-104)
Lecture 14
Graphs
Today’s Lecture
 Graphs
 Directed Graphs
 Simple Graphs
 Complete Graphs
 Complete Bipartite Graphs
 Subgraphs
 The Concept of Degree
Today’s Lecture
 Subgraphs
 The Concept of Degree
 Walks, Trails, Paths and Circuits
 Connectedness
 Connected Components
 Euler Circuits
 Constructing an Euler Circuits
Graphs
Imagine an organization that wants to set up teams of three to
work on some projects. In order to maximize the number of people
on each team who had previous experience working together
successfully, the director asked the members to provide names of
their past partners. This information is displayed below both in a
table and in a diagram.
Cont…
Cont…

Drawings such as those shown previously are


illustrations of a structure known as a graph. The dots
are called vertices (plural of vertex) and the line
segments joining vertices are called edges. As you can
see from the drawing, it is possible for two edges to
cross at a point that is not a vertex.
Cont…
In general, a graph consists of a set of vertices and a set of edges
connecting various pairs of vertices. The edges may be straight or
curved and should either connect one vertex to another or a vertex
to itself, as shown below.
Cont…
In this drawing, the vertices have been labeled with v’s
and the edges with e’s. When an edge connects a
vertex to itself (as e5 does), it is called a loop. When two
edges connect the same pair of vertices (as e2 and e3
do), they are said to be parallel. It is quite possible for a
vertex to be unconnected by an edge to any other
vertex in the graph (as v5 is), and in that case the vertex
is said to be isolated.
Definition: Graphs
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: Examples
Example: Consider the following graph:

a. Write the vertex set and the edge set, and give a table showing the
edge-endpoint function.
b. 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.
Graphs: Examples (Contd….)
a. vertex set = {v1, v2, v3, v4, v5, v6} Edge-endpoint function
edge set = {e1, e2, e3, e4, e5, e6, e7}

b. 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.
Drawing More Than One Picture for a Graph
Consider the graph specified as follows:

vertex set = {v1, v2, v3, v4}


edge set = {e1, e2, e3, e4}

Edge-endpoint function
Labeling Drawings to Show They Represent the Same Graph

Consider the two drawings shown in Figure. Label


vertices and edges in such a way that both drawings
represent the same graph.
Labeling Drawings to Show They Represent the Same Graph

Both drawings are representations of the graph with vertex set {v1, v2, v3,
v4, v5}, edge set {e1, e2, e3, e4, e5}, and edge-endpoint function as follows:
Directed Graphs
Directed Graphs: Examples of Graphs
Using a Graph to Represent Knowledge
What paper finish does the New York Times use?
Using a Graph to Solve a Problem: Vegetarians and Cannibals

Using a Graph to Represent Knowledge


The following is a variation of a famous puzzle often used as an
example in the study of artificial intelligence. It concerns an island
on which all the people are of one of two types, either vegetarians
or cannibals. Initially, two vegetarians and two cannibals are on the
left bank of a river. With them is a boat that can hold a maximum of
two people.

The aim of the puzzle is to find a way to transport all the


vegetarians and cannibals to the right bank of the river. What
makes this difficult is that at no time can the number of cannibals
on either bank outnumber the number of vegetarians. Otherwise,
disaster befalls the vegetarians!
Using a Graph to Solve a Problem: Vegetarians and Cannibals
Simple Graphs

Example
Draw all simple graphs with the four vertices {u, v, w, x} and two
edges, one of which is {u, v}.
Each possible edge of a simple graph corresponds to a subset of
two vertices. Given four vertices, there are 4C2 = 6 such subsets in
all: {u, v}, {u,w}, {u, x}, {v,w}, {v, x}, and {w, x}. Now 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.
Simple Graphs
Complete Graphs

Example
Complete Graphs on n Vertices: K1, K2, K3, K4, K5
The complete graphs K1, K2, K3, K4, and K5 can be drawn as follows:
Complete Graphs
Example
Complete Graphs on n Vertices: K1, K2, K3, K4, K5
The complete graphs K1, K2, K3, K4, and K5 can be drawn as follows:
Complete Bipartite Graphs
Complete Bipartite Graphs
Complete Bipartite Graphs: K3,2 and K3,3
SubGraphs

Example
SubGraphs
The Concept of Degree
The Concept of Degree
Degree of a Vertex and Total Degree of a Graph
Find the degree of each vertex of the graph G shown below. Then
find the total degree of G.
The Concept of Degree
SubGraphs

Example
SubGraphs
The Concept of Degree
The Concept of Degree
Degree of a Vertex and Total Degree of a Graph
Find the degree of each vertex of the graph G shown below. Then
find the total degree of G.
The Concept of Degree
Walks
Let G be a graph, and let v and w be vertices in G.
A walk from v to w is a finite alternating sequence of
adjacent vertices and edges of G. Thus a walk has the
form
v0e1v1e2 · · · vn−1envn,

where the v’s represent vertices, the e’s represent


edges, v0 = v, vn = w, and for all i = 1, 2, . . . n, vi−1 and
vi are the endpoints of ei. The trivial walk from v to v
consists of the single vertex v.
Definitions
A trail from v to w is a walk from v to w that does not
contain a repeated edge.
A path from v to w is a trail that does not contain a
repeated vertex.
A closed walk is a walk that starts and ends at the
same vertex.
A circuit is a closed walk that contains at least one
edge and does not contain a repeated edge.
A simple circuit is a circuit that does not have any
other repeated vertex except the first and last.
Cont…
For ease of reference, these definitions are summarized
in the following table:
Notations for Walk
Often a walk can be specified unambiguously by giving either a
sequence of edges or a sequence of vertices.
Cont…
Example: Trails, Paths, Circuits
Cont…
Solution
Connectedness

Example
Contd…

Theorem
Let G be a graph.
a. If G is connected, then any two distinct vertices of G can be connected
by a path.
b. If vertices v and w are part of a circuit in G and one edge is removed
from the circuit, then there still exists a trail from v to w in G.
c. If G is connected and G contains a circuit, then an edge of the circuit
can be removed without disconnecting G.
Connected Component of a Graph
Contd…
Find all connected components of the following graph G.

G has three connected components: H1, H2, and H3 with vertex sets V1, V2,
and V3 and edge sets E1, E2, and E3, where

You might also like