Graphs Lecture Notes

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

GRAPHS

 Graphs make it possible to reason about the relations between objects and how individual
connections between objects can give rise to larger structures.
 A graph is a collection of objects (usually referred to as nodes or vertices) that can be
connected to one another. Specifically, any pair of nodes may be connected by an edge
(sometimes called an arc).
 A computer network is an example of a graph. Vertices or nodes represent the computers and
edges represent the communication links between the computers.

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.

 Typically, anything can act as nodes in a graph: people, places, words, numbers, etc.
 Since edges run between two nodes, we often represent edges as which pair of nodes they
connect.
GRAPHS
 For example, consider the following graph, which represents friendships in a group of
people.
Amy Bob

Cathy Dean

Frank
Ethan

 In this case, we could represent the graph as follows:

 E = {}, {}
{}}

 Notice that in the this case, our edges were represented as a set of unordered pairs,
because friendship is bidirectional – if person A is a friend of person B, then person B is
GRAPHS
An unordered pair is a set {a, b} of two elements a ≠ b.

 An unordered pair represents two objects without specifying that one of these
objects is the “first” object and that one of these is the “second” object. For
example, the friendship between Amy and Bob might be represented as the
unordered pair { Amy, Bob }. Since sets are unordered collections of distinct
elements, this means that { Amy, Bob } = { Bob, Amy }.

An undirected graph is a graph where V is a set of nodes, which can be anything, and
E is a set of unordered pairs.
GRAPHS
 Now consider Ethihad airline network where each airport is represented by a
vertex. We can model all the flights by the airline each day using a directed edge to
represent each flight, going from the vertex representing the departure airport to
the vertex representing the destination airport..

Harare JHB

Nairobi
Dubai Paris

 We would represent the graph as follows:


V = { Harare, Johannesburg, Nairobi, Paris}
E = { (Harare, JHB), (Harare, Dubai), (Dubai, Paris), (JHB, Paris),(Nairobi, Harare),
(Nairobi, JHB) }
G = (V, E)
GRAPHS
 In this case, our edges were represented as a set of ordered pairs, because flights have a
definite ordering to them. In these graphs, the edges are directed, meaning that they flow
from one node to another.

An ordered pair is a collection of two objects a and b in order. We denote the


ordered pair consisting first of a, then of b as (a, b). Two ordered pairs ( ) and
( ) are equal if = and =.

A directed graph is an ordered pair where is a set of nodes, which can be anything,
and E is a set of edges, which are ordered pairs of nodes drawn from V.

 To summarize, a undirected graph is a graph G = (V, E), where E is a set of


unordered pairs. A directed graph(or digraph) is a graph G = (V, E), where E is a set
of ordered pairs.
 An edge from a node to itself is called a self-loop. In undirected graphs, self-loops
are generally not allowed. In directed graphs, self-loops are generally allowed
unless specified otherwise.
GRAPHS
Graph Properties
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.

 Note that in a simple graph, each edge is associated to an unordered pair of


vertices, and no other edge is associated to this same edge.
Graphs that may have multiple edges connecting the same vertices or loops are called
multigraphs.
 When there are m different edges associated to the same unordered pair of vertices
we also say that is an edge of multiplicity m.

Simple graph Multi graph


GRAPHS
Graph Properties

Vertices and are said to be adjacent or neighbors if there is an edge In such a case,
and are called the endpoints of , and is said to connect and . Also, the edge is said to
be incident on each of its endpoints and .

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 .

Handshaking Theorem : The sum of the degrees of the vertices of a graph G is equal
to twice the number of edges in G.
 A vertex of degree zero is called an isolated vertex.
GRAPHS
Graph Properties
A path in a graph is a series of nodes where for any with , there is an edge from to

 In other words, a path is a series of nodes such that any two consecutive nodes in the
sequence are adjacent.
 The number of edges is called the length of the path. The length of the path is n-1.

A simple path is a path with no repeated nodes.

 Notice that this definition just says that a simple path cannot repeat any nodes. This
implicitly also means that the simple path cannot repeat any edges, since if that were
the case the path would have to repeat that edge's endpoints.
A cycle/circuit is a closed path of length 3 or more in which all vertices are distinct
except = . A cycle of length k is called a k-cycle.

 A simple cycle is a cycle that does not contain any duplicate nodes (except for the very
GRAPHS
Example: Consider the graph G

 Describe G formally, that is, find the set V (G) of vertices of G and the set E(G) of
edges of G.
V (G)={A,B,C,D,E}
E(G) = {{A,B}, {A,C}, {A,D}, {B,C}, {B,E}, {C,D}, {C,E}} – there are the 7 pair of vertices
 Find the degree of each vertex.
The degree of a vertex is equal to the number of edges to which it belongs; e.g., deg(A) = 3
since A belongs to the three edges {A,B}, {A,C}, {A,D}. Similarly, deg(B) = 3, deg(C) = 4,
deg(D) = 2, deg(E) = 2
This proves the theorem which states that the sum of degrees is equal to 2 times the
number of edges. 3+3+4+2+2= 2*7 =14
GRAPHS
 Find all simple paths from A to E;
A simple path from A to F is a path such that no vertex, and hence no edge, is
repeated.

 Find all cycles which include vertex A;


A cycle is a closed path in which no vertex is repeated (except the first and last). There are
three cycles which include vertex A:
GRAPHS
Connectivity and Connected Component
Let G be an undirected graph. Two nodes u and v are called connected if there is a
path from u to v in G. if u and v are connected, we denote this by writing . if u and v
are not connected, we denote this by writing
A graph G as a whole is called connected if all pairs of nodes in G are connected.

Let be an undirected graph. A connected component of is a nonempty set of nodes


(that is, C ⊆ V), such that
For any u, v ∈ C, we have .
For any and , we have
GRAPHS
Connectivity and Connected Component
 Intuitively, a connected component is a “piece” of a graph in the sense.
 By definition, a connected component is a set of nodes where all the nodes within
that set are connected. To ensure that this set is as large as possible, rule 2 says that
if you pick any node in C (call it u) and any node not in C (call it v), then u and v are
not connected. The notation v ∈ V – C just means that v is a node in the graph (it's
in V) but not contained within C.

Theorem: Let be an undirected graph. Then the connectivity relation


over V is an equivalence relation.
GRAPHS
Connectivity and Connected Component

An undirected graph G is called k-edge-connected if G is connected, and there is no


set of k – 1 edges that can be removed from G that disconnects it..

A bridge in a connected, undirected graph G is an edge in G that, if removed,


disconnects G.

Theorem: An undirected graph G is 2-edge-connected iff it is connected and has no


bridges.
GRAPHS
Example
Consider the multigraphs below.

Which of them are connected? If a graph is not connected, find its connected
components.
 Only (1) and (3) are connected, (2) is disconnected; its connected components are
{A,D,E} and {B,C}. (4) is disconnected; its connected components are {A,B,E} and
{C,D}.
GRAPHS
Euler paths and circuits

Let G = (V,E) be a graph with no isolated vertices. An Euler path in G is a simple path
that transverses every edge of the graph exactly once. Analogously, an Euler circuit in
G is a simple circuit that transverses every edge of the graph exactly once.

Let G be a connected multigraph. Then G contains an Euler circuit if and only if G its
vertices have even degree.
Also, G contains an Euler path/trail from vertex a to vertex b () if and only if a and b
have odd degree, and all its other vertices have even degree.
GRAPHS
Hamilton circuits

A Hamilton circuit in a graph G is a circuit that contains each vertex of G once (except
for the starting and ending vertex, which occurs twice). A Hamilton path in G is a path
(not a circuit) that contains each vertex of G once.

Note that by deleting an edge in a Hamilton circuit we get a Hamilton path, so if a


graph has a Hamilton circuit, then it also has a Hamilton path. The converse is not true,
i.e., a graph may have a Hamilton path but not a Hamilton circuit.
GRAPHS
Example:
Consider each graph in the Figure below. Which of them are traversable, that is, have
Euler paths?
Which are Eulerian, that is, have an Euler circuit? For those that do not, explain why.

Example:
Which of the graphs have a Hamiltonian circuit? If not, why not?
GRAPHS
Planar graphs

A graph is called a planar graph if there is some way to draw it in a 2D plane without
any of the edges crossing.

 A graph is called the utility graph if there is no way to draw it in the plane without
edges crossing. For further explanation, you can view this video
https://youtu.be/VvCytJvd4H0
GRAPHS
Example
Draw a planar representation of the graph below.

Solution
A planar graph does not edges that cross.
GRAPHS
Graph Coloring

Consider a graph G. A vertex coloring, or simply a coloring of G is an assignment of


colors to the vertices of G such that adjacent vertices have different colors. We say
that G is n-colorable if there exists a coloring of G which uses n colors.

 A coloring of a simple graph is the assignment of a color to each vertex of the graph
so that no two adjacent vertices are assigned the same color
 The chromatic number of a graph is the least number of colors needed for a
coloring of this graph. The chromatic number of a graph G is denoted by χ(G).
GRAPHS
Welch and Powell Algorithm for Graph Coloring
 Order the vertices of graph G according to decreasing degrees
 Assign the first colour to the first vertex and then in sequential order, assign to
each vertex adjacent which is not adjacent to the previous vertex which was
assigned .
 Repeat step 2 with a second colour and the subsequence of non-coloured vertices.
 Repeat step 3 with a third colour and so on until all the vertices are coloured.

Theorem (Four-Color Theorem): Every planar graph is 4-colorable

.
GRAPHS
Example
Find the chromatic number of the graph given below

The chromatic number of a graph is the least number of colours needed for graph
colouring.

Vertices according to a c b d e
decreasing degrees deg(a)=3 deg(c)=3 deg(b)=2 deg(d)=2 deg(e)=2

Colour c1 c1 c2 c2 c2

 The χ(G)=2

You might also like