15 views

Uploaded by suraj

© All Rights Reserved

- References of Bondey Book
- Definition Graph Theory
- Mathematical Foundations of Computer Science_UNIT-5
- Graph 2
- s07-socnet
- COE128 LQ3
- 1.2 Graph Theory
- Week 06b: Graph Algorithms 1.pdf
- Dynamic Generators of Topologically Embedded Graphs
- three colrability
- v2i21
- 41UndirectedGraphs.pdf
- Ch5
- Chapter 2 _CMOS_process Supplement III
- Semantichyper: Graph Based knowledge representation architecture for complex product development
- Issn 1937 - 1055 Volume 4, 2009
- Algorithms Without Programming
- CH5_3
- Test
- Edmonds

You are on page 1of 202

By

Chandan Giri

chandangiri@gmail.com

Graph Theory - History

Seven Bridges of

Knigsberg ,

published in 1736.

Famous problems

A traveling salesman is to visit a

number of cities; how to plan the trip

so every city is visited once and just

once and the whole trip is as short as

possible ?

Famous problems

which asks if it is possible to color, using only four

colors, any map of countries in such a way as to

prevent two bordering countries from having the

same color.

1976 by Kenneth Appel and Wolfgang Haken, can

be considered the birth of graph theory.

Examples

Shortest route between two cities.

Shortest distance between all pairs of cities in

a road atlas.

Matching / Resource Allocation

Task scheduling

Visibility / Coverage

Examples

Flow of material

liquid flowing through pipes

current through electrical networks

information through communication networks

parts through an assembly line

In Operating systems to model resource handling

(deadlock problems)

In compilers for parsing and optimizing the code.

Basics

Graph Definitions and Notation

1 1 2 3

2 3

4 5 6 4 5 6

Definitions

Vertex

Basic Element

Drawn as a node or a dot.

Vertex set of G is usually denoted by V(G), or V

Edge

A set of two elements

Drawn as a line connecting two vertices, called

end vertices, or endpoints.

The edge set of G is usually denoted by E(G), or E.

Graph Definitions and Notation

Let G=(V,E, g) be a graph and e be an edge of this

graph.

Then there are vertices v and w such that

g(e)={v,w}; vertices v and w are end vertices of e

When a vertex v is an end point of some edge e, we

say that e is an incident with the vertex v and v is

incident with the edge e.

Two vertices v and w of G are said to be adjacent if

there exists an edge e E such that g(e)={v,w}.

Graph Definitions and Notation

Two edges are said to be adjacent if they have

a common end vertex.

If e is an edge such that g(e) = {v,w}, where

v=w, then e is an edge from the vertex v to

itself. Such an edge is called a loop on the

vertex v or at the vertex v.

If there is a loop on v, then v is adjacent to

itself.

Graph Definitions and Notation

e1

v3

v1 v2

v7

e2

e5 e3 e4 e6 e7

v4 v5

v6

Graph Definitions and Notation

Let G=(V, E, g) be a graph.

The incidence function g need not be one one.

Therefore, there may exist edges e1, e2, ., en-1, en,

n 2 such that g(e1)= g(e2) = = g(en) = {v, w}.

Such edges are called parallel edges.

Example:

g(e1)=g(e2)={v1, v2}. So edges e1 and e2 are parallel. Similarly

edges e4, e6 and e7 are parallel.

e1

v1 v2

v7

e2

e5 e3 e4 e6 e7

v4 v5

v6

Graph Definitions and Notation

DEFINITION :: Isolated vertex

Let G be a graph and v be a vertex in G. We say that v is an

isolated vertex if it is not incident with any edge.

Let G be a graph and v be a vertex of G. The degree of v,

written as deg(v) or d(v) is the number of edges incident

with v.

We make the convention that each loop on a vertex v

contributes 2 to the degree of v.

Example:

deg(v1)=2

v1 e1 deg (v2)= 1

v2

deg (v3)=3

e2 v5 deg(v4)=2

e3

v4 v3

deg(v5)=0

Graph Definitions and Notation

DEFINITION:: k-regular graph

Let G be graph and k be a nonnegative integer.

G is called a k-regular graph if the degree of each

vertex of G is k

Example:

An interesting k-regular graph is the Petersen 3-

regular graphs follows: v1

v6

v10 v7

v2 v3

v9 v8

v4 v5

Graph Definitions and Notation

DEFINITION :: Even (odd ) degree vertex

v is called an even (odd) vertex if the degree of

v is even (odd)

A vertex with degree one is called the pendant

vertex (or leaf vertex).

Example::

v1 e1 deg(v1)=2 Even

v2

deg (v2)= 1 Odd

e2 deg (v3)=3 Odd

e3

v4 v3 deg(v4)=2 Even

Graph Definitions and Notation

DEFINITION :: Degree Sequence

that n1 n2 n3 nk.

Then the finite sequence n1, n2, n3, , nk is called the degree

sequence of the graph

Every graph has a unique degree sequence.

However, we can construct completely different graphs having

same degree sequence.

Example::

The degree sequence of both of these graphs is 2, 3, 3, 4. But

the graphs are different.

v1 v2 v1 v2

v4 v3 v4 v3

Graph Definitions and Notation

Theorem: The sum of the degrees of all vertices of a graph G is twice the number

of edges.

i.e= = . , where e is the number of edges of the graph and n is the

number of vertices of the graph G.

Proof:

Every edge contributes two to the sum of the degrees, one for each of its end points.

Proof:It is known that =1 = 2. , where m is the number of edges of the graph.

Hence =1 =

=> + = n

Now is even. As has to be even but are odd degree vertices. So

the number of odd degree vertices should be in even numbers. This proves the

statement.

Corollary: The sum of degrees of all of the vertices of a graph G is an even integer.

--- Follows directly from above theorem

Graph Definitions and Notation

DEFINITION :: Simple Graph

edges and any loop

Theorem:: Let G be a simple graph with at least two vertices. Then G has at least

two vertices of same degree

Graph Definitions and Notation

DEFINITION :: Complete Graph

A simple graph with n vertices in which there is an edge

between every pair of distinct vertices is called a complete

graph on n vertices. This is denoted as Kn.

a

Example: e

b

K5

d

c

Graph Definitions and Notation

Theorem: The number of edges in a complete graph with n

vertices is n(n-1)/2

Proof:

Every node in the complete graph with n vertices is connected to

all of the other n1 nodes.

Hence, Since each edge has two endpoints, this implies that the

graph has n(n1)/2 edges.

i=0 = n(n 1)/2

Graph Definitions and Notation

DEFINITION :: Bipartite Graph

A simple graph G is called a bipartite graph if the vertex set V of G

can be partitioned into Nonempty subsets V1 and V2 such that each

edge of G is incident with one vertex in V1 and one vertex in V2.

V1 V2 is called a bipartition of G.

A

X

B

Y

C

Z

D

Bipartite Graphs

Example I: Is C3 bipartite?

the vertices into two sets so that there are

v2 v3 no edges with both endpoints in the same

set.

Example II: Is C6 bipartite?

v1 v6 v1 v6

Yes, because we

v2 v5 can display C6 v5 v2

like this: v4

v3 v4 v3

23

Graph Definitions and Notation

DEFINITION :: Complete Bipartite Graph

A bipartite graph G with bipartition V1V2 is called a complete

bipartite graph on m and n vertices if the subsets V1 and V2 contain

m and n vertices, respectively, such that there is an edge between

each pair of vertices v1 and v2, where v1V1and v2V2.

v1 v6

v5 v2

v3 v4

Graph Definitions and Notation

v3 v3

e3 v2 v2 e3

v2 v3

v2 e1

e2 e1

e1 e4

e1 e4 v1 v4 e2

e2 v1 v4

v1 v4 e2

v1 v4 e6 e5

e6

e5

e7 v5

v5 v6

v5

v6

G G1 G2 G3

DEFINITION :: Sub-graph

Let G= (V, E, g) be a graph. The graph G1=(V1, E1, g1) is a sub-graph of G if

a) V1 V and

b) Every edge of G1 is also an edge of G.

Subgraph::Graph Definitions

Spanning Sub-graph:

If V1 = V then G1 is called the spanning sub-graph of

G i.e if every vertex V1 of G1 is in G.

Edge disjoint sub-graph:

If G1 and G2 are two sub-graphs of G and they have no

edges are in common then G1 and G2 are edge disjoint.

Vertex disjoint sub-graph

If G1 and G2 are two sub-graphs of G and they have no

vertices are in common then G1 and G2 are edge disjoint.

Are vertex disjoint sub-graphs also edge disjoint sub-graphs?

Not all time.

Sub-graph

Few observations:

Every graph is its own sub-graph

A sub-graph of a sub-graph of G is a sub-graph of

G

A single vertex in a graph G is a sub-graph of G

A single edge in G, together with its vertices, is

also a sub-graph of G

Isomorphism of Graphs

Let G=(V,E) and G={V, E} be graphs.

G and G are sais to be isomorphic if there

exist a pair of functions f:V V and g: E

E that associates each element in V with

exactly one element in V and vice versa;

g associates each element in E with exactly one

element in E and vice versa, and

for each v V, and each e E, if v is an end point

of the edge e, then f(v) is an endpoint of the edge

g(e).

Isomorphism of Graphs

If two graphs are isomorphic then they must

have

The same number of vertices

The same number of edges

The same degrees for corresponding vertices

The same number od connected components

The same number of loops

The same number of parallel edges.

Isomorphism of Graphs

Example: v5

e1

a v4 v3

e e3

5 4 2

e2 e4 e6

1

c

6 3

b d v1 e5 v2

A B

The vertices a, b, c, d, e in the graph (A) corresponds to v1, v2,

v3, v4 and v5 of the graph (B) respectively.

The edges 1, 2, 3, 4, 5 and 6 correspond to e1, e2, e3, e4, e5 and

e6 respectively.

Except for the labels (i.e. names ) of their vertices and

edges, isomorphic graphs are the same graph.

Walks, Paths, and Cycles

DEFINITION :: Walk

Let u and v be two vertices in a graph G.

A walk from u to v, in G, is an alternating sequence of n+1 vertices and

n edges of G

(u= v1, e1, v2, e2, v3, e3, .., vn-1, en-1, vn, en, vn+1=v)

beginning with vertex u, called the initial vertex, and ending with vertex

v, called the terminal vertex, in which vi and vi+1 are endpoints of edge ei for

i=1, 2, ., n.

Example:

v1 v2 v5

b

f

Walks:

a c e g v1, b, v2, e, v3, h, v3, d, v4

v6 v4, c, v2, f, v5 , g, v6

v4 d v1, b, v2, c, v4, a, v1

v3

h

Walks, Paths, and Cycles

DEFINITION :: Directed walk

Let u and v be two vertices in a directed graph G.

A directed walk from u to v in G is an alternating sequence

of n+1 vertices and n arcs of G

(u= v1, e1, v2, e2, v3, e3, .., vn-1, en-1, vn, en, vn+1=v)

beginning with vertex u and ending with vertex v in which

each edge ei, for i=1, 2, , n, is an arc from vi to vi+1

Walks, Paths, and Cycles

DEFINITION :: Length of a walk (directed walk)

Open walk

Closed

walk

Walks, Paths, and Cycles

DEFINITION :: Trail and Path

v1 v2 v5

b

f

Walks:

e g v1, b, v2, e, v3, h, v3, d, v4 ---- Not a path, trail

a c

v6 v4, c, v2, f, v5 , g, v6 ------ Path, trail

d v1, b, v2, c, v4, a, v1 ----- Path (also closed path,

v4 v3

cycle), trail (circuit)

h

DEFINITION :: Cycle

DEFINITION :: Circuit

Walks, Paths, and Cycles

DEFINITION :: Trivial walk, path or trail

DEFINITION :: k-cycle

Some properties of Walks, Paths, and

Cycles

Vertices Edges Comments

edges

Paths No repetitions of No Repetition of

vertices except possibly edges

starting and terminal

vertices

Circuits Repetition Allowed No Repetition of A nontrivial closed trail

edges

Cycles No repetitions of Without repetition of

vertices except starting vertices except starting

and terminal vertices and terminal vertices

Walks, Paths, and Cycles

Theorem: Let G be a graph and u and v be two

vertices of G. If there is a walk from u to v, then there is

a path form u to v.

Operations on Graph

DEFINITION :: Complement of a simple graph

Operations on Graph

DEFINITION :: Difference operation

If the graphs G=(V, E) and G=(V, E) are simple and V V,

then the difference graph is G- G = (V, E) where E contains

those edges from G that are not in G (simple graph).

Operations on Graph

Operations on Graph

Operations on Graph

DEFINITION ::Removal of a vertex

i.e. deletion of a vertex v means the deletion of the vertex v and deletion of

all the edges incident on v.

removing e form E.

Connected graph

DEFINITION :: Connectedness

only if the graph of this network is connected.

Note: A graph consisting of only one vertex is always connected, because it does

not contain any pair of distinct vertices.

Connected graph

Example: Are the following graphs connected?

a b a

b

e e

d

d c

c

Yes. No.

a b a

b

e d e

c

d f

c No.

Yes.

44

Some Theorem

Theorem:

A graph is disconnected if and only if its vertex set V can be partitioned into two

nonempty, disjoint subsets V1 and V2 such that there exists no edge in G whose one end

vertex is in subset V1 and the other in subset V2.

Proof:

Suppose that such a partition exists.

Consider two arbitrary vertices a and b of G, such that a V1 and b V2. No path can

exist between vertices a and b; otherwise there would be at least one edge whose one end

vertex would be in V1 and the other in V2. hence, if a partition exists, G is not connected.

Consider a vertex a in G. Let V1 be the set of all vertices that are joined by paths to a.

Since G is disconnected V1 does not include all vertices of G. The remaining vertices will

form a (nonempty) set V2. So no vertex in V1 is joined to any in V2 by an edge. Hence the

partition.

Component

DEFINITION :: Component

Connected graph

Theorem: If a graph (connected or disconnected) has only two

odd vertices v1 and v2, then there is a path between v1 and v2.

Proof:

Case 1: G is connected. It is obvious that there is a path

between v1 and v2.

of these connected components the theorem which states that

number of odd vertices in a graph is always even is applicable.

As there are only two odd vertices so, v1 and v2 must belong

to the same component. Otherwise the above stated theorem

would be violated. (Proved)

Connected graph

Theorem: If a graph has n vertices & k components then it can

have a maximum of (n-k)(n-k+1)/2 edges.

Proof:

If ni (>= 1) is the number of vertices for the i-th component of the

graph,

Then we have n1+n2+.+nk = n for the k component of the graph.

Now maximum number of edges of a component I = ni(ni-1)/2.

Again maximum number of edges n of G = ( ni2 ni) =

ni2 ni

Now =1( 1) =

2

Taking square at both sides we have ( =1( 1)) = ( )2

Equating both sides we can obtain (n-k)(n-k+1)/2 edges.

Walks, Paths, and Cycles

DEFINITION :: Distance

Euler graph

Euler line and Euler graph

If some closed walk in a graph contains all the

edges of the graph, then the walk is called an Euler

line and the graph an Euler graph.

Walks, Paths, and Cycles

Theorem: A graph is bipartite if and only if it does not contain any cycle of odd

length.

Proof:

() If G is bipartite with bipartition X,Y of the vertices, then

any cycle C has vertices that must alternatively be in X and Y.

Thus, since a cycle is closed, C must have an even number of

vertices and hence is an even cycle.

Assume G has no odd cycle. Let u V(G) be an arbitrary vertex.

Partition all other vertices based on the parity of distance (even or

odd) from u. That is, let

X={v V(G): d(u,v) is even}

Y={v V(G): d(u,v) is odd}

Clearly X Y = null and X UY=V(G) since G is connected.

Proof continued.

We claim that X,Y is a bipartition of G.

Suppose not

then there exists an edge incident to two vertices of X or an edge

incident to two vertices of Y. Without loss of generality, assume the

former.

Let x1,x2 X and edge x1x2 exists. It follows that

x1 X there exists u, x1-path P1 of even length

x2 X there exists u, x2-path P2 of even length

Concatenate u, x1-path P1, the edge x1x2 and the x2, u-path P2 to

obtain a closed odd walk.

Hence it will contains a odd cycle. This is contradicting with the

assumption.

Hence, it must be the case the X,Y is a valid bipartition, so G is

bipartite.

Matrix Representation of a Graph

Adjacency Matrix:

Let G be a graph with n vertices, where n>0.

Let V(G) = {v1, v2, v3, , vn}.

The adjacency matrix AG of G is an nxn matrix [aij] such that the (i, j) ths

entry of AG is the number of edges from vi to vj.

i.e. =

0

Because aij is the number of edges from vi to vj, the adjacency matrix AG is a square

matrix over the set of non-negative integers.

0 1 0 1

Example: v2 1 0 1 0

e6 1 = 0 1 1 1

v2

e1 1 0 1 0

e2

e1

e2

v1 v3

v1 v3 e7 e5

0 1 0 2

e5 e4 e3 1 0 2 0

e4 e3 2 = 0 2 1 1

v4 2 0 1 0

v4 G1 G2

Properties of Adjacency matrix

The Adjacency matrix AG of a graph has the

following property

1. AG is a symmetric matrix

2. If G does not contain any loops and parallel

edges then each element of AG is either 0 or 1

3. If G does not contain any loops, then all of the

diagonal elements of AG are 0.

Matrix Representation of a Graph

Incidence matrix

The all-vertex incidence matrix of a non-empty and loopless graph

G=(V, E) is an nxm matrix [aij], where n is the number of vertices

in G and m is the number of edges of G and

=

Properties of Adjacency matrix

The incidence matrix AG of a graph has the

following property

Since an edge is incident on two vertices, each column of A

will have exactly two 1s and rest are 0s.

If any row has all entries as 0, then no edge is incident on

that vertex, hence it is an isolated vertex.

The number of 1s is a row indicates the degree od the

corresponding vertex.

Cut-edge, Cut Vertex

A cut-edge or cut-vertex of a graph is an edge

or vertex whose deletion increases the number

of components

Cut-edge

Cut-vertex

Cut-edge, Cut Vertex

G-e or G-M : The subgraph obtained by

deleting an edge e or set of edges M

G-v or G-S : The subgraph obtained by deleting

a vertex v or set of vertices S

G G-e

e

Cut-edge, Cut Vertex

Theorem: An edge e is a cut-edge if and only if e

belongs to no cycles.

Proof :

Let e= (x, y) be an edge in a graph G and H be the

component containing e.

Since deletion of e effects no other component, it

suffices to prove that H-e is connected if and only if e

belongs to a cycle.

First suppose that H-e is connected.

This implies that H-e contains an x, y-path,

This path completes a cycle with e.

Cut-edge, Cut Vertex

Proof :2/2

Now suppose that e lies in a cycle C.

Choose u, vV(H)

Since H is connected, H has a u, v-path P

If P does not contain e

Then P exists in H-e

Otherwise (P contains e)

Suppose by symmetry that x is between u and y on P

Since H-e contains a u, x-path along P, the

transitivity of the connection relation implies that H-e has a

u, v-path

We did this for all u, v V(H), so H-e is connected.

Cut-edge, Cut Vertex

An Example:

x e y

u v

P

Eulerian Circuits

A graph is Eulerian if it has a closed trail

containing all edges.

We call a closed trail a circuit when we do not

specify the first vertex but keep the list in

cyclic order.

An Eulerian circuit or Eulerian trail in a

graph is a circuit or trail containing all the

edges.

Even Graph, Even Vertex

all even.

A vertex is odd [even] when its degree is odd

[even].

Maximal Path

that is not contained in a longer path.

When a graph is finite, no path can extend forever ,

so maximal (non-extendible) paths exist.

Lemma: If every vertex of graph G has degree at

least 2, then G contains a cycle.

Proof:

Let P be a maximal path in G, and let u be an endpoint of P

Since P cannot be extended, every neighbor of u must already be a

vertex of P

Since u has degree at least 2, it has a neighbor v in V (P ) via an

edge not in P

The edge uv completes a cycle with the portion of P from v to u

Must

P u

v

u

P

Impossible

Theorem: A graph G is Eulerian if and only if it has at most one

nontrivial component and its vertices all have even degree.

Proof: (Necessity)

Suppose that G has an Eulerian circuit C

Each passage of C through a vertex uses two incident

edges

And the first edge is paired with the last at the first vertex

Hence every vertex has even degree

In

Out

End (The last)

Theorem: A graph G is Eulerian if and only if it has at most one

nontrivial component and its vertices all have even degree.

Proof: (Necessity)

Assume that all vertices of G are of even degree.

Now we can construct a walk starting at an arbitrary vertex v and going

through the edges of G such that no edge is traced more than once.

We continue tracing as far as possible. Since every vertex is of even degree,

we can exit from every vertex we enter; the tracing can cannot stop at any

vertex but v.

Since v is also of even degree, we shall eventually reach v when the tracing

comes to an end.

If this closed walk h we just traced includes all the edges of G, G is an

Euler graph.

If not, we remove from G all the edges in h and obtain a sub-graph h of G

formed by the remaining edges.

Theorem: A graph G is Eulerian if and only if it has at most one

nontrivial component and its vertices all have even degree

Proof:

Since both G and h have all their vertices of even degree,

degree of vertices of h is also even. Moreover, h must touch

h at least at one vertex a, because G is connected.

Starting from a, we can construct a new walk in h. Since.

All the vertices of h are of even degree, this walk in h must

terminate at vertex a. but this walk in h can not be combined

with h to form a new walk, which starts and ends at vertex v

and has more edges than h.

This process can not be repeated until we obtain a closed

walk that traverses all the edges of G.

Thus G is an Euler graph.

Hamiltonian Circuit

A Hamilton circuit in a graph is a circuit that

visits each vertex exactly once (returning to

the starting vertex to complete the circuit).

Example: Identifying Hamilton Circuits

Refer to the graph below. Which of the following are Hamilton circuits?

a) A B E D C F A

b) A B C D E F C

EBFA

c) B C D E F B

B C D

A

F E

Example: Identifying Hamilton Circuits

Solution

a) It is a Hamilton circuit for the graph.

b) It is not a Hamilton circuit since it visits B

more than once.

c) It is not a Hamilton circuit since it does not

visit all the vertices.

Hamiltonian Path

If we remove any one edge from a

Hamiltonian circuit, we are left with a path.

This path is called a Hamiltonian path. .

Clearly, a Hamiltonian path in a graph G

traverses every vertex of G.

Since a Hamiltonian path is a sub-graph of a

Hamiltonian circuit, every graph that has a

Hamiltonian circuit also has a Hamiltonian

path.

Hamiltonian Circuits

There are, however, many graphs with

Hamiltonian paths that have no Hamiltonian

circuits.

The length of a Hamiltonian path (if there

exists) in a connected graph of n vertices is (n-

1).

Circuits

Hamiltonian Circuits

A given graph may contain more than one

Hamiltonian circuit.

The determination of the exact number of

edge-disjoint Hamiltonian circuits in a graph in

general is a unsolved problem.

However, Hamiltonian circuits in a complete

graph with odd number of vertices (n>=3)

are (n-1)/2.

Planar Graphs

The plane representations of graphs are by no

means unique

75

Planar Graphs

Properties of a graph are not necessarily

immediate from one representation, but may be

apparent from another.

surface graphs, that rely on the (topological or

geometrical) properties of the drawings of the

graph.

graphs.

76

Planar Graphs

A planar graph will be a graph that

can be drawn in the plane so that no two edges

intersect with each other.

a

a

e

c b

b

d

d e c

77

Applications of planar graphs

Planar graphs are extensively used in Electrical, Mechanical

and Civil Engineering.

culprit for reducing comprehensibility.

VLSI design, circuit needs to be on surface; lesser the

crossings, better is the design.

High speed highways/railways design, crossings are

always problematic.

Irrigation canals, crossing simply not admissible.

Most of facility location problems on maps are actually

problems of planar graphs.

78

What are planar graph- drawings?

Definition :

Given a graph G= (V,E), a drawing maps

each vertex v V to a distinct point (v) in

plane, and each edge e E, e= (u,v) to a simple

open Jordan curve (u,v) with end points (u),

(v).

79

Problem definition: Planar Embedding

Given a graph G=(V,E), if G is planar, how

can G be drawn in the plane such that there are no

edge crossings.

- i.e. compute a planar representation of

the graph G.

- But for this, it is required to know

whether a graph is planar or not, which is called

planarity testing.

80

Problem (Decision problem)

Given a graph G= (V,E), is G planar?

- i.e. can G be drawn in the plane

without edge crossing?

- planarity of K4

yes, K4 is planar 1

1

2 3

2 4

4 3

Graph K4 81

K5 and K3,3

Question: Are the following graphs planar?

No, they are not. There always will be at least one

crossing.

- can be proved by Eulers celebraed

theorem

1 2

1 3

5

2

1 2 3

3

4

82

K5 and K3,3

Question: Are the following graphs

planar?

1 2

1 3

5

2

1 2 3

3

4

83

Is the following graph planar?

84

Is the following graph planar?

- Yes it is

- But how to arrive at the answer?? 85

Basic assumptions

We assume that our graphs are connected and

there are no self loops and no-multi edges.

edges can be easily dealt with.

86

More definitions

Definition: Subdivision of a graph

An edge e = (u,v) G is subdivided, when it is replaced by a

path u x v of length two by introducing a new vertex x.

of subdivisions.

subdivisions are planar.

87

Geometric properties

Let F be an open set of this plane R R, that is, every

point x F has a disk centered at x and contained in F.

Region:

F is a region, if any two points x, y F can be

joined by a continuous curve the points of which are

all in F.

Boundary:

The boundary of a region is consists of

those points for which every neighborhood contains

points from F and its complement.

88

Faces

Let G be a planar graph, and P(G) one of its

plane embeddings.

Regard now each edge e = (u,v) G as a line

from u to v.

The set (R R)\EG is open and it is divided into

a finite no. of disjoint regions, called faces of

P(G).

89

Interior faces:

A face of P(G) is an interior face, if it is

bounded.

Exterior faces:

The (unique) face that is unbounded is called the

exterior face of P(G).

The edges that surrounded a face F, constitute this

boundary of F.

Exterior boundary: Boundary of exterior face

- vertices on exterior boundary are called

exterior vertices of exterior edge.

- vertices that not on the exterior boundary are

interior vertices.

90

Properties

Embedding P(G) satisfy following properties:

Two different faces F1 and F2 are disjoint and their

boundaries can intersect only on edges.

P(G) has a unique exterior faces.

Each edge e belongs to this boundary of at most two

faces.

Each cycle of G surrounds at least one internal face of

P(G).

A bridge of G belongs to this boundary of only one face.

An edge that is not a bridge belongs to the boundary of

exactly two faces.

91

Eulers Formula

Lemma 1: A plane embedding P(G) of a planar graph

G has no interior faces if and only if G is acyclic,

that is, if and only if the connected components of G

are trees.

- follows from the geometric properties

Lemma 2: (Eulers formula) proved by Legendre

(1974)

Let G be a connected planar graph and let be any of

its plane embeddings. Then,

v e + f = 2, where f is the no. of faces of P(G)

92

Proof

It can be proved by the method of induction on no.

of faces f of a plane embedding P(G).

Note that f 1, since each P(G) has an exterior

face.

If f = 1, then here are no cycles in G, and since G is

connected, it is a face.

Hence, e = v 1.

with less than f faces for f 2.

93

Proof Continued...

The sub graph G - e is planar with a plane embedding

P(G - e) = P(G) - e obtained by simply erasing the edge e.

Now P(G - e) has (f 1) faces, since the two faces of

P(G) that are separated by e are merged into one face of

P(G - e).

By the induction hypothesis,

vG-e - eG-e + (fG - 1) = 2 and the claim follows:

embedding of G has the same no. of faces.

fG = e G - v G + 2

94

Maximum planar graphs

Lemma:

If G is a planar graph of order vG 3, then

eG 3vG 6

Moreover, if G has no triangles C3, then eG 2vG 4.

Proof:

Let v be the no. of regions of G.

Now if the

For graph G with f faces, it follows from the fact

that, 2eG 3fG ........ (A)

95

Maximum planar graphs

Each face for embedding P(G) contains at least three edges on its

boundary .

Hence, 3fG 2eG, since each edge lies on at most two faces.

So from (A),

3fG 2eG

=> fG 2/3 eG

Now combining this with Eulers formula,

vG eG + fG = 2

=> fG = 2 + eG vG

=> eG vG + 2 = fG 2/3 eG

=> 3eG 3vG + 6 2eG

=> eG 3vG 6

Example: k5, vG = 5, eG = 10

Now 10 3x5 6 is contradicting. So it is non- planar.

96

Corollary: Let G be a connected planar graph with

vG vertices and eG edges, and no triangles. Then

eG 2vG 4.

Proof: For graph G with fG faces, it follows that a

face with triangle requires at least 4 edges.

Hence, 4fG 2eG

=> fG eG

combining this with Eulers formula

we have, vG eG + fG = 2

=> eG vG + 2 = fG eG

=> eG 2vG - 4

97

Example: K3,3

6 vertices and 9 edges and no triangles.

Now 9 12 4 8 contradicting.

So it is non- planar.

polyhedron.

98

Graph Traversal

Graph Searching Algorithms

Searching a graph

Symmetrically following the edges of the graph so

as to visit all the vertices.

Breadth-first search

Depth-first search

Topological sort (of a directed acyclic

graph):

It is a linear ordering of all the vertices such that if

(u,v) is a directed edge, then u appears before v in

the ordering.

Breadth-first search : Idea

Graph G=(V, E), directed or undirected with adjacency list

representation.

GOAL: Systematically explores edges of G to

Discover every vertex reachable from the source vertex s

Compute the shortest path distance of every vertex from the

source vertex s

Produce a breadth-first tree (BFT) GH with root s

BFT contains all vertices reachable from s

The unique path from any vertex v to s in GH constitutes a shortest

path from s to v in G

IDEA: Expanding frontier across the breadth greedy

Propagate a wave 1 edge-distance at a time

Using a FIFO queue : O(1) time to update pointers to both ends.

Breadth-first search: Key

components

Maintains the following fields for each u V

Color[u]: color of u

WHITE: not discovered yet

GRAY: discovered and not to be or being processed

BLACK: discovered and processed

H[u]: parent of u (NIL if u=s or u is not

discovered yet)

d[u]: distance of u from s

Breadth-first search: Algorithm

BFS (G, s)

for each u V do

color[u] WHITE

H[u] NIL; d[u]

color[s] GRAY

H[s] NIL; d[s]0;

Q{s}

while (Q != NULL) do

uhead[Q]

for each v in Adj[u] do

if color[v]= WHITE then

color[v] GRAY

H[v]u

d[v]d[u] +1

ENQUEUE(Q, v)

DEQUEUE(Q)

color[u]BLACK

Breadth-first search : Example

Sample graph: FIFO Just after

Queue Q Processing vertex

s

{a} --

0

a d

b e

i

f

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

a 0 d {a, b, c} a

1

c

1

b e

i

f

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

a 0 d {a, b, c} a

{a, b, c, f} b

1

c

1

b e

2

i

f

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

0 d {a, b, c} a

a

1 {a, b, c, f} b

{a, b, c, f, e} c

c

1 2

b e

2

i

f

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

0 d {a, b, c} a

a {a, b, c, f} b

1

{a, b, c, f, e} c

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

1 2

b e

2

3 i

f 3

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

3 d {a, b, c} a

a 0

1 {a, b, c, f} b

{a, b, c, f, e} c

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

1 2 {a, b, c, f, e, g, h, d, i} e

b e

2 All distances

i are filled in

3 f 3 after

3 processing e

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

3 d {a, b, c} a

a 0

1 {a, b, c, f} b

{a, b, c, f, e} c

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

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

1

b e

2

3 i

3 f

3

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

0 3 d {a, b, c} a

a {a, b, c, f} b

1

{a, b, c, f, e} c

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

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

2

b e

2

3 i

3 f

3

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

3 {a} --

a 0 d {a, b, c} a

{a, b, c, f} b

1

{a, b, c, f, e} c

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

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

1 2

b e

2

f 3 i

3 3

g h

Breadth-first search : Example

FIFO Just after

Queue Q Processing vertex

s

{a} --

0 3 d {a, b, c} a

a {a, b, c, f} b

1

{a, b, c, f, e} c

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

1 2 {a, b, c, f, e, g, h, d, i} i

b e

2 Algorithm terminates :

All vertices are processed.

3 i

3 f

3

g h

Breadth-first Search: Analysis

Running time: O(V+E) = considered linear

time in graphs

Initialization: O(V)

Queue operations: O(V)

Each vertex enqueued and dequeued at most once

Both enqueue and dequeue operations take O(1) time

Processing gray vertices: O(E)

Each vertex is processed at most once and

= ()

Breadth-first search: The paths to the

root

BFT(G,s), where VH={vV:H(v) NIL} {s}

and EH={(H[v], v) E: v VH {s}}

is a breadth first tree such that

VH consists of all vertices in V that are reachable

from s

For all v VH, unique path p(v,s) in GH constitutes

a sp(s,v) in G

Breadth-first Tree: The BFS tree

s

a 0 3d

s 1

3 d c

0 1

a 2

1 b e

c 2

i

1 2 f 3

3 3

b e g h

2

3 i

3 f

3

g h

Depth-first search: Idea

Graph G=(V,E) directed or undirected

Adjacency list representation

Goal: Systematically explore every vertex and

every edge

Idea: Search deeper whenever possible

Using a LIFO queue (Stack; FIFO queue used in

BFS)

Depth-first search: Key components

Maintains several field for each v V

Like BFS, colors the vertices to indicate their

states. Each vertex is

Initially white

Grayed when discovered

Blacked when finished

Like BFS, records discovery of a white v

during scanning Adj[u] by H[v] u

Depth-first search: Key components

Unlike BFS, predecessor graph GH produced

by DFS forms spanning forest

GH= (V,EH) where

EH={(H[v],v): v V and H[v] != NIL}

GH = depth-first forest(DFF) is composed of

disjoint depth-first trees (DFTs)

Depth-first search: Key components

DFS also timestamps each vertex with two

timestamps

d[v] : records when v is first discovered and

grayed

f[v]: records when v is finished and blackened

Since there is only one discovery event and

finishing event for each vertex we have

1<=d[v] <f[v]<=2|V|

Depth-first search: Algorithm

DFS-VISIT(G, u)

DFS(G) color[u] gray

for each u V do

d[u] time time+1

color[u] white for each v Adj[u] do

H[u] NIL if color[v]= white then

time 0 H[v] u

for each u V do DFS-VISIT(G,v)

if color[u]= white

then color[u] black

DFS-VISIT(G,u) f[u] time time +1

Depth-first search: Analysis

Running time: O(V+E)

Initialization loop in DFS: O(V)

Main loop in DFS: O(V) exclusive of time to execute

calls to DFS-VISIT

DFS-VISIT is called exactly once for each v V since

DFS-VISIT is invoked only on white vertices and

DFS-VISIT(G,u) immediately colors u as gray

For loop of DFS-VISIT(G, u) is executed |Adj[u]|

time

Since sum |Adj[u]| = E, total cost of executing loop of

DFS-VISIT is O(E).

Depth-first search: Example

x y z

s t

w v u

Depth-first search: Example

x y z

1

s t

w v u

Depth-first search: Example

x y z

1

s t

w v u

Depth-first search: Example

x y z

1

s t

w v u

Depth-first search: Example

x y z

1

s t

w v u

Depth-first search: Example

x y z

1

s t

3 4

w v u

Depth-first search: Example

x y z

1

s t

3 4 5

w v u

Depth-first search: Example

x y z

1

s t

3 4 5 6

w v u

Depth-first search: Example

x y z

1

s t

2 7

3 4 5 6

w v u

Depth-first search: Example

x y z

1 8

s t

2 7

3 4 5 6

w v u

Depth-first search: Example

x y z

1 8

s t

2 7

3 4 5 6

w v u

Depth-first search: Example

x y z

1 8

s t

2 7 9

3 4 5 6

w v u

Depth-first search: Example

x y z

1 8

s t

2 7 9

3 4 5 6

w v u

Depth-first search: Example

x y z

1 8

s t

2 7 9 10

3 4 5 6

w v u

Depth-first search: Example

x y z

1 8 11

s t

2 7 9 10

3 4 5 6

w v u

Depth-first search: Example

x y z

1 12 8 11

s t

2 7 9 10

3 4 5 6

w v u

Depth-first search: Example

x y z

1 12 8 11 13

s t

2 7 9 10

3 4 5 6

w v u

Depth-first search: Example

x y z

1 12 8 11 13

s t

2 7 9 10

3 4 5 6

w v u

Depth-first search: Example

x y z

1 12 8 11 13

s t

2 7 9 10

3 4 5 6

w v u

Depth-first search: Example

x y z

1 12 8 11 13

s t

2 7 9 10

3 4 5 6 14

w v u

Depth-first search: Example

x y z

1 12 8 11 13

s t

2 7 9 10

3 4 5 6 14

w v u

Depth-first search: Example

x y z

1 12 8 11 13

s t

2 7 9 10

3 4 5 6 14 15

w v u

Depth-first search: Example

x y z

1 12 8 11 13 16

s t

2 7 9 10

3 4 5 6 14 15

w v u

Depth-first search: DFT and DFF

x y z

1 12 8 11 13 16

s t

2 7 9 10

3 4 5 6 14 15

w v u

y z

1 12 8 11 13 16

x t

s

2 7 9 10

3 4 5 6 14 15

w v u

Graph Coloring

Basics

Assignment of "colors" to certain objects in

a graph subject to certain constraints

Vertex coloring (the default)

Edge coloring

Face coloring (planar)

Not Graph Labeling

Graph coloring

Just markers to keep track of adjacency or

incidence

Graph labeling

Calculable problems that satisfy a numerical

condition

Vertex coloring

In its simplest form, it is a way of coloring

the vertices of a graph such that no two

adjacent vertices share the same color

Edge and Face coloring can be transformed

into Vertex version

Vertex Color example

Anything less results in adjacent vertices

with the same color

Known as proper

3-color example

Vertex coloring

A k-coloring of a graph G is a labeling f:

V(G) S, where |S| = k (often we use S =

[k]). The labels are colors; the vertices of

one color form a color class.

A k-coloring is proper if adjacent vertices

have different labels.

A graph is k-colorable if it has a proper k-

coloring. The chromatic number (G) is

the least k such that G is k-colorable.

k-chromatic

A graph G is k-chromatic if (G) =k.

A proper k-coloring of a k-chromatic graph

is an optimal coloring.

If (H) < (G) = k for every proper

subgraph H of G, then G is color-critical or

k-critical.

Chromatic number of a complete graph:

(G) = n

Spanning Trees

Definition:

A tree T is said to be a spanning tree of a

connected graph G if T is a subgraph of G and T

contains all the vertices of G.

6 4

5 9

14 2

10

15

3 8

Spanning Tree

Since the vertices of G are barely hanging

together is a panning tree, it is a sort of skeleton

of the original graph G.

This is why a spanning tree is sometimes refereed

to as a skeleton or scaffolding of G.

Since spanning trees are the largest (with

maximum number of edges) trees among all trees

in G. it is also quite appropriate to call a spanning

tree a maximal tree subgraph or maximal tree of

G.

Spanning Tree

Theorem:

Every connected graph has at least one spanning

tree.

Theorem:

With respect to any of its spanning trees, a connected

graph of n vertices and e edges has (n-1) tree

branches and (e-n+1) chords.

Finding a spanning tree

To find a spanning tree of a graph,

pick an initial node and call it part of the spanning tree

do a search from the initial node:

each time you find a node that is not in the spanning tree, add to the spanning tree both

the new node and the edge you followed to get to it

result of a BFS result of a DFS

starting from top starting from top 157

Minimizing costs

Suppose you want to supply a set of houses (say, in a

new subdivision) with:

electric power

water

sewage lines

telephone lines

To keep costs down, you could connect these houses

with a spanning tree (of, for example, power lines)

However, the houses are not all equal distances apart

To reduce costs even further, you could connect the

houses with a minimum-cost spanning tree

158

Minimum-cost spanning trees

Suppose you have a connected undirected graph with a weight (or

cost) associated with each edge

The cost of a spanning tree would be the sum of the costs of its

edges

A minimum-cost spanning tree is a spanning tree that has the

lowest cost

16 16

A B A B

21 11 6 11 6

19 5 5

F C F C

33 14

10

E 18 D E 18 D

A connected, undirected graph A minimum-cost spanning tree

159

Finding spanning trees

There are two basic algorithms for finding minimum-cost

spanning trees, and both are greedy algorithms

spanning tree, and repeatedly add the cheapest edge that does

not create a cycle

Here, we consider the spanning tree to consist of edges only

Prims algorithm: Start with any one node in the spanning tree,

and repeatedly add the cheapest edge, and the node it leads to,

for which the node is not already in the spanning tree.

Here, we consider the spanning tree to consist of both nodes and edges

160

Kruskals Algorithm

Kruskal()

{

T = ;

for each v V

MakeSet(v);

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1?

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2? 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5?

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8? 25

for each v V 5

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9?

T = ; 14 17

8 25

for each v V 5

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13? 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14? 17

8 25

for each v V 5

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17?

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19?

{ 9

T = ; 14 17

8 25

for each v V 5

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21? 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25?

for each v V 5

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T U {{u,v}};

Union(FindSet(u), FindSet(v));

}

Kruskals Algorithm

Run the algorithm:

Kruskal() 2 19

{ 9

T = ; 14 17

8 25

for each v V 5

MakeSet(v); 21 13 1

sort E by increasing edge weight w

for each (u,v) E (in sorted order)

if FindSet(u) FindSet(v)

T = T {{u,v}};

Union(FindSet(u), FindSet(v));

}

Prims algorithm

T = a spanning tree containing a single node s;

E = set of edges adjacent to s;

while T does not contain all the nodes {

remove an edge (v, w) of lowest cost from E

if w is already in T then discard edge (v, w)

else {

add edge (v, w) and node w to T

add to E the edges adjacent to w

}

}

An edge of lowest cost can be found with a priority queue

Testing for a cycle is automatic

Hence, Prims algorithm is far simpler to implement than Kruskals

algorithm

185

Walk-Through

2

Initialize array

3

10

F C K dv pv

A 7

4

3 A F

8 B F

18

4

9

B D C F

10

H 25 D F

2

3 E F

G 7

E F F

G F

H F

2

Start with any node, say D

3

10

F C K dv pv

A 7

4

3 A

8

18 B

4

9

B D C

10

H 25 D T 0

2

3 E

G 7

E F

G

H

2 Update distances of

adjacent, unselected nodes

3

10

F C K dv pv

A 7

4

3 A

8

18 B

4

9

B D C 3 D

10

H 25 D T 0

2

3 E 25 D

G 7

E F 18 D

G 2 D

H

2 Select node with minimum

distance

3

10

F C K dv pv

A 7

4

3 A

8

18 B

4

9

B D C 3 D

10

H 25 D T 0

2

3 E 25 D

G 7

E F 18 D

G T 2 D

H

2 Update distances of

adjacent, unselected nodes

3

10

F C K dv pv

A 7

4

3 A

8

18 B

4

9

B D C 3 D

10

H 25 D T 0

2

3 E 7 G

G 7

E F 18 D

G T 2 D

H 3 G

2 Select node with minimum

distance

3

10

F C K dv pv

A 7

4

3 A

8

18 B

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E 7 G

G 7

E F 18 D

G T 2 D

H 3 G

2 Update distances of

adjacent, unselected nodes

3

10

F C K dv pv

A 7

4

3 A

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E 7 G

G 7

E F 3 C

G T 2 D

H 3 G

2 Select node with minimum

distance

3

10

F C K dv pv

A 7

4

3 A

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E 7 G

G 7

E F T 3 C

G T 2 D

H 3 G

2 Update distances of

adjacent, unselected nodes

3

10

F C K dv pv

A 7

4

3 A 10 F

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E 2 F

G 7

E F T 3 C

G T 2 D

H 3 G

2 Select node with minimum

distance

3

10

F C K dv pv

A 7

4

3 A 10 F

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E T 2 F

G 7

E F T 3 C

G T 2 D

H 3 G

2 Update distances of

adjacent, unselected nodes

3

10

F C K dv pv

A 7

4

3 A 10 F

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E T 2 F

G 7

E F T 3 C

G T 2 D

H 3 G

Table entries unchanged

2 Select node with minimum

distance

3

10

F C K dv pv

A 7

4

3 A 10 F

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E T 2 F

G 7

E F T 3 C

G T 2 D

H T 3 G

2 Update distances of

adjacent, unselected nodes

3

10

F C K dv pv

A 7

4

3 A 4 H

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E T 2 F

G 7

E F T 3 C

G T 2 D

H T 3 G

2 Select node with minimum

distance

3

10

F C K dv pv

A 7

4

3 A T 4 H

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E T 2 F

G 7

E F T 3 C

G T 2 D

H T 3 G

2 Update distances of

adjacent, unselected nodes

3

10

F C K dv pv

A 7

4

3 A T 4 H

8

18 B 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E T 2 F

G 7

E F T 3 C

G T 2 D

H T 3 G

Table entries unchanged

2 Select node with minimum

distance

3

10

F C K dv pv

A 7

4

3 A T 4 H

8

18 B T 4 C

4

9

B D C T 3 D

10

H 25 D T 0

2

3 E T 2 F

G 7

E F T 3 C

G T 2 D

H T 3 G

2 Cost of Minimum Spanning

Tree = dv = 21

3

F C K dv pv

A 4

3 A T 4 H

B T 4 C

4

B D C T 3 D

H D T 0

2

3 E T 2 F

G E F T 3 C

G T 2 D

H T 3 G

Done

- References of Bondey BookUploaded byKunaal Jain
- Definition Graph TheoryUploaded byvelavansu
- Mathematical Foundations of Computer Science_UNIT-5Uploaded byShantha Kumar
- Graph 2Uploaded byEimasedba
- s07-socnetUploaded byHarvinder Singh Khalsa
- COE128 LQ3Uploaded byNicko Pangilinan
- 1.2 Graph TheoryUploaded byGagan Kandra
- Week 06b: Graph Algorithms 1.pdfUploaded byAnonymous Z9IoLzP
- Dynamic Generators of Topologically Embedded GraphsUploaded byMirza Ahad Baig
- three colrabilityUploaded byZubin Arya
- v2i21Uploaded bysurvathana
- 41UndirectedGraphs.pdfUploaded byaagreco73
- Ch5Uploaded byjackaccyou
- Chapter 2 _CMOS_process Supplement IIIUploaded byBadai Timur
- Semantichyper: Graph Based knowledge representation architecture for complex product developmentUploaded byJexia
- Issn 1937 - 1055 Volume 4, 2009Uploaded byAnonymous 0U9j6BLllB
- Algorithms Without ProgrammingUploaded byMohammad Hossein Sekhavat
- CH5_3Uploaded byrocio Umbarila
- TestUploaded bygelivnia
- EdmondsUploaded byjazzy0756
- 7 DeadlocksUploaded byVerma Mulesh
- Super complete-antimagicness of Amalgamation of any GraphUploaded byIJAERS JOURNAL
- Sub-Graph Finding Information over Nebula NetworksUploaded byInternational Journal of computational Engineering research (IJCER)
- symbol table.xlsxUploaded byhelloansuman
- 13 Directed GraphsUploaded bySara Sarah
- cgraph.3Uploaded byRaphael de Vasconcelos Nascimento
- Forcing (G,D)-number of a GraphUploaded byMia Amalia
- Hw4Sol_rev2Uploaded bySoSo MaYa

- Algorithmic Graph Theory - David Joyner, Minh Van Nguyen, Nathann CohenUploaded byJohnatan Naranjo
- Bellman FordUploaded byacharya_s2005
- solution5_3Uploaded bysazedul1658
- DS2marksUploaded byPrem Kumaran
- On Signed Graphs Whose Two Path Signed Graphs are Switching Equivalent to Their Jump Signed GraphsUploaded byDon Hass
- Multi-Threaded Cycle Detection in Undirected GraphUploaded byShubham Gupta
- 09.7_2Uploaded byroro132
- Ipp Low Power Da Iict 3Uploaded byVS
- Algorithm DinizUploaded byRavi Gohel
- L25-Connectivity.pptUploaded byAnonymous BOreSF
- Smarandachely t-path step signed graphsUploaded byRyanElias
- Example for N & NPUploaded byRaghuveer Raman
- VertexCoverReductionINDSET.pdfUploaded byeats_donuts
- 199210524 Vlsi Design Lab ManualUploaded byAntonio Leon
- MC Graph TheoryUploaded byking_kaiser
- 42 Directed GraphsUploaded byRavi Sankar
- Graph Problem SolUploaded bydineshdash1979
- Deter Minis Tic Optimizational ProblemsUploaded byLuminita Botezatu
- Mathematics MagazineUploaded byAkshika Shree
- graph_theory_notes.pdfUploaded bysonarika123
- 2018SU B.sc Maths SyllabusUploaded bysachin81185
- DNA SequencingUploaded bymarkaz
- 93542greedy MethodUploaded byYogesh Tonpe
- Vertex ColoringUploaded bydeepakshiva
- Lec-31&32 GraphUploaded byTaqi Shah
- TutorialUploaded byChamara Jayalath
- Day2Uploaded bySri Chandra Duddu
- Math 3v03 DefinitionsUploaded byjimmy_wang7848
- graphs and trees.pptUploaded bycatarac19
- Ds Two MarksUploaded bysrcsundar