0% found this document useful (0 votes)
13 views61 pages

2215Ch9 2022

Uploaded by

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

2215Ch9 2022

Uploaded by

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

MTH 2215

Applied Discrete Mathematics

Chapter 9, Section 9.1


Introduction to Graphs

These class notes are based on material from our


textbook, Discrete Mathematics and Its
Applications, 6th ed., by Kenneth H. Rosen,
published by McGraw Hill, Boston, MA, 2006. They
are intended for classroom use only and are not a
substitute for reading the textbook.
Problem
• The Seven bridges of Königsberg

C c

D
A
a d

B b
Simple Graph

• A graph consists of
– a nonempty set of vertices called V
– a set of edges (unordered pairs of
distinct elements of V) called E
• Notation: G = (V,E)
• A graph is simple if there is at most one
edge linking two vertices.
Simple Graph Example

Detroit
New York
San Francisco
Chicago
Denver Washington
Los Angeles

• This simple graph represents a network.


• The network is made up of computers and
telephone links between computers
Multigraph
• A multigraph can have multiple edges (two or
more edges connecting the same pair of
vertices).
Detroit
New York
San Francisco
Chicago
Denver Washington
Los Angeles

There can be multiple telephone lines between two


computers in the network.
Pseudograph
• A Pseudograph can have multiple edges and
loops (an edge connecting a vertex to itself).
Detroit

San Francisco Chicago New York


Denver

Washington

Los Angeles There can be telephone lines in the network from


a computer to itself.
Types of Undirected Graphs

Pseudographs
Multigraphs
Simple Graphs
Directed Graph
The edges are ordered pairs of (not necessarily
distinct) vertices.
Detroit
Chicago New York
San Francisco

Denver Washington

Los Angeles

Some telephone lines in the network may operate in only


one direction. Those that operate in two directions are
represented by pairs of edges in opposite directions.
Directed Multigraph
A directed multigraph is a directed graph with multiple
edges between the same two distinct vertices.

Detroit
New York
Chicago
San Francisco

Denver Washington

Los Angeles

There may be several one-way lines in the same direction


from one computer to another in the network.
Types of Directed Graphs

Directed
Multigraphs
Directed Graphs
Graph Models

• Graphs can be used to model structures,


sequences, and other relationships.
• Example: ecological niche overlay graph
– Species are represented by vertices
– If two species compete for food, they are
connected by a vertex
Niche Overlay Graph
Acquaintanceship Graph
Influence Graph
Round-Robin Tournament Graph
Call Graphs

Directed graph (a) represents calls from a telephone number


to another.
Undirected graph (b) represents called between two
numbers.
Hollywood Graph

• In the Hollywood graph:


– Vertices represent actors
– Edges represent the fact that the two
actors have worked together on some
movie
• As of October 2007, this graph had 893,283
vertices, and over 20 million edges.
Shortest-path Algorithms
• A decade or so ago a game called "Six Degrees
of Kevin Bacon" was popular on college
campuses.
• The idea, based on the idea that “it’s a small
world”, was to try to find the fewest number of
connections to link any other actor with Kevin
Bacon.
• It was discovered that you could connect Kevin
Bacon with just about any other actor in 6 links
or so.
Bacon Numbers

• In the Hollywood Graph, the Bacon


Number of an actor x is defined as the
length of the shortest path connecting x and
the actor Kevin Bacon.
• The average Kevin Bacon number is 2.957
• For more information, see the Oracle of
Bacon website at the University of Virginia
Computer Science Department.
Bacon Numbers
Kevin Bacon Number Number of People
0 1 (Kevin Bacon himself)
1 2030
2 190213
3 557245
4 133450
5 9232
6 958
7 137
8 17
Shortest-path Algorithms

• Writing an efficient program for finding the


shortest path in a graph is an important
optimizing task in Computer Science.
• For futher information about shortest-path
algorithms, take CSE 4833, or read the course
textbook, Introduction to Algorithms by Cormen,
Leiserson, Rivest, and Stein.
Summary

Type Edges Loops Multiple


Edges
Simple Graph Undirected NO NO

Multigraph Undirected NO YES

Pseudograph Undirected YES YES

Directed Directed YES NO


Graph
MTH 2215
Applied discrete mathematics

Chapter 9.2
Graph Terminology

These class notes are based on material from our


textbook, Discrete Mathematics and Its
Applications, 6th ed., by Kenneth H. Rosen,
published by McGraw Hill, Boston, MA, 2006. They
are intended for classroom use only and are not a
substitute for reading the textbook.
Adjacent Vertices in Undirected
Graphs
• Two vertices, u and v in an undirected graph
G are called adjacent (or neighbors) in G, if
{u,v} is an edge of G.
• An edge e connecting u and v is called
incident with vertices u and v, or is said to
connect u and v.
• The vertices u and v are called endpoints of
edge {u,v}.
Degree of a Vertex

• 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 a vertex v is denoted by
deg(v).
Example
c d
b

a g f e

• Find the degrees of all the vertices:


deg(a) = 2, deg(b) = 6, deg(c) = 4, deg(d) = 1,
deg(e) = 0, deg(f) = 3, deg(g) = 4
Complete Graph

• The complete graph on n vertices (Kn) is the


simple graph that contains exactly one edge
between each pair of distinct vertices.
• The figures above represent the complete graphs,
Kn, for n = 1, 2, 3, 4, 5, and 6.
Cycle
• The cycle Cn (n  3), consists of n vertices
v1, v2, …, vn and edges {v1,v2}, {v2,v3}, …,
{vn-1,vn}, and {vn,v1}.

Cycles: C3 C4 C5 C6
Wheel
When a new vertex is added to a cycle Cn and
this new vertex is connected to each of the n
vertices in Cn, we obtain a wheel Wn.

Wheels: W3 W4 W5 W6
Subgraph
• A subgraph of a graph G = (V,E) is a graph
H = (W,F) where W  V and F  E.

K5 C5
Is C5 a subgraph of K5?
Union
• The union of 2 simple graphs G1 = (V1, E1) and
G2 = (V2, E2) is the simple graph with vertex set V
= V1V2 and edge set E = E1E2. The union is
denoted by G1G2.
c c c

b d b f
f b d d

a e a e a e
S5 C5 W5
S5  C5 = W5
MTH 2215
Applied discrete mathematics

Chapter 9.4
Connectivity

These class notes are based on material from our


textbook, Discrete Mathematics and Its
Applications, 6th ed., by Kenneth H. Rosen,
published by McGraw Hill, Boston, MA, 2006. They
are intended for classroom use only and are not a
substitute for reading the textbook.
Paths in Undirected Graphs
• There is a path from vertex v0 to vertex vn if
there is a sequence of edges from v0 to vn
– This path is labeled as v0,v1,v2,…,vn and
has a length of n.
• The path is a circuit if the path begins and
ends with the same vertex.
• A path is simple if it does not contain the
same edge more than once.
Paths in Undirected Graphs
• A path or circuit is said to pass through the
vertices v0, v1, v2, …, vn or traverse the
edges e1, e2, …, en.
Example
• u1, u4, u2, u3
u1 u2
– Is it simple?
– yes

– What is the length?


u5 u4 u3 –3

– Does it have any circuits?


– no
Example
• u1, u5, u4, u1, u2, u3

– Is it simple?
u1 u2 – yes

u5 u3
– What is the length?
u4 –5

– Does it have any circuits?


– Yes; u1, u5, u4, u1
Example
• u1 , u2 , u5 , u4 , u3

– Is it simple?
– yes
u1 u2

– What is the length?


u5 u3 –4
u4
– Does it have any circuits?
– no
Connectedness
• An undirected graph is called connected if there
is a path between every pair of distinct vertices
of the graph.
• There is a simple path between every pair of
distinct vertices of a connected undirected graph.
Example
Are the following graphs connected?

a b a b

c e

f d c

g e d f

Yes No
Connectedness (Cont.)

• A graph that is not connected is the union


of two or more disjoint connected
subgraphs (called the connected
components of the graph).
Example
• What are the connected components of
the following graph?

b d e f

a c h g
Example
• What are the connected components of
the following graph?

b d e f

a c h g

{a, b, c}, {d, e}, {f, g, h}


Cut edges and vertices

• If one can remove a vertex (and all


incident edges) and produce a graph with
more connected components, the vertex is
called a cut vertex.
• If removal of an edge creates more
connected components the edge is called a
cut edge or bridge.
Example
• Find the cut vertices and cut edges in the
following graph.

a d f g

b c e h
Example
• Find the cut vertices and cut edges in the
following graph.

a d f g

b c e h

Cut vertices: c, e and b


Cut edge: (c, e)
MTH 2215
Applied discrete mathematics

Chapter 9.5
Euler and Hamilton Paths

These class notes are based on material from our


textbook, Discrete Mathematics and Its
Applications, 6th ed., by Kenneth H. Rosen,
published by McGraw Hill, Boston, MA, 2006. They
are intended for classroom use only and are not a
substitute for reading the textbook.
Euler Paths and Circuits
• The Seven bridges of Königsberg

C
c

D
A
a d

B
b
Euler Paths and Circuits

• An Euler path is a path using every edge


of the graph G exactly once.
• An Euler circuit is an Euler path that
returns to its start.
C

Does this graph have an


A D
Euler circuit?
No.
B
Necessary and Sufficient Conditions
• How about multigraphs?

• A connected multigraph has a Euler circuit


iff each of its vertices has an even degree.
• A connected multigraph has a Euler path
but not an Euler circuit iff it has exactly
two vertices of odd degree.
Example
• Which of the following graphs has an
Euler circuit?
a b a b a b

e e

d c d c c d e

yes no no
(a, e, c, d, e, b, a)
Example
• Which of the following graphs has an
Euler path?
a b a b a b

e e

d c d c c d e

yes no yes
(a, e, c, d, e, b, a ) (a, c, d, e, b, d, a, b)
Hamilton Paths and Circuits

• A Hamilton path in a graph G is a path


which visits every vertex in G exactly once.

• A Hamilton circuit is a Hamilton path that


returns to its start.
Hamilton Circuits

Is there a circuit in this graph that passes through each


vertex exactly once?
Hamilton Circuits

Yes; this is a circuit that passes through each vertex


exactly once.
Finding Hamilton Circuits

Which of these three figures has a Hamilton circuit?


Of, if no Hamilton circuit, a Hamilton path?
Finding Hamilton Circuits

• G1 has a Hamilton circuit: a, b, c, d, e, a


• G2 does not have a Hamilton circuit, but does have a
Hamilton path: a, b, c, d
• G3 has neither.
Finding Hamilton Circuits

• Unlike the Euler circuit problem, finding


Hamilton circuits is hard.
• There is no simple set of necessary and
sufficient conditions, and no simple
algorithm.
Properties to look for ...

• No vertex of degree 1
• If a node has degree 2, then both edges
incident to it must be in any Hamilton
circuit.
• No smaller circuits contained in any
Hamilton circuit (the start/endpoint of any
smaller circuit would have to be visited
twice).
A Sufficient Condition
Let G be a connected simple graph with n
vertices with n  3.
G has a Hamilton circuit if the degree of
each vertex is  n/2.
Travelling Salesman Problem
A Hamilton circuit or path may be used to
solve practical problems that require visiting
“vertices”, such as:
road intersections
pipeline crossings
communication network nodes
A classic example is the Travelling Salesman
Problem – finding a Hamilton circuit in a
complete graph such that the total weight of
its edges is minimal.
Summary
Property Euler Hamilton
Repeated visits to a given Yes No
node allowed?
Repeated traversals of a No No
given edge allowed?
Omitted nodes allowed? No No

Omitted edges allowed? No Yes

You might also like