3. A graph G consists of a finite set of ordered pairs, called edges
E, of certain entities called vertices V. Edges are also called as
arcs or links. Vertices are also called as nodes or points.
G=(V,E)
A graph is a set of vertices and edges. A vertex may represent
a state or a condition while the edge may represent a relation
between two vertices.
03/09/2012 3
4. Directed Graph
Directed Graphs or DIGRAPHS make reference to edges which are
directed (i.e.) edges which are ordered pairs of vertices.
Undirected Graph
A graph whose definition makes reference to unordered pairs of
vertices as edges is known as an undirected graph
Path
A simple path is a path in which all the vertices except possibly the
first and last vertices are distinct
03/09/2012 4
5. Cycle
A cycle is a simple path in which the first and last vertices are the same
. A cycle is also known as a circuit, elementary cycle, circular path or
polygon.
Eulerian Graph
A walk starting at any vertex going through each edge exactly once
and terminating at the start vertex is called an Eulerian walk or line.
A Hamiltonian path in a graph is a path that visits each vertex
in the graph exactly once.
A Hamiltonian cycle is a cycle that visits each vertex in the
graph exactly once and returns to the starting vertex.
03/09/2012 5
6. Let G = (V, E) be an undirected connected graph. A subgraph
T = (V, E’) of G is a spanning tree of G iff T is a tree
Given G = (V, E) to be a connected, weighted undirected graph
where each edge involves a cost, the extraction of a spanning
tree extends itself to the extraction of a minimum cost
spanning tree.
A minimum cost spanning tree is a spanning tree which has a
minimum total cost.
03/09/2012 6
8. Select an arbitrary node as the initial tree (T)
Augment T in an iterative fashion by adding the outgoing edge
(u,v), (i.e., u T and v G-T ) with minimum cost (i.e.,
weight)
The algorithm stops after |V | - 1 iterations
Computational complexity = O (|V|2)
03/09/2012 8
9. The algorithm then finds, at each stage, a new vertex to add
to the tree by choosing the edge (u, v) such that the cost of (u,
v) is the smallest among all edges where u is in the tree and v
is not.
Algorithm would build the minimum spanning tree, starting
from v1. Initially, v1 is in the tree as a root with no edges.
Each step adds one edge and one vertex to the tree.
03/09/2012 9
10. procedure PRIM(G)
E’ = ; /* Initialize E’ to a null set */
Select a minimum cost edge (u,v) from E;
V’ = {u} Include u in V’
while V’ not equal to V do
Let (u, v) be the lowest cost edge such that u is in V’ and v is in V
– V’;
Add edge (u,v) to set E’;
Add v to set V’;
endwhile
end PRIM
03/09/2012 10
12. V2
1
V1
V1
Algorithm starts
After the 1st
iteration
03/09/2012 12
13. V3
V2 3
V2 V3
3 1
3
1 1
3 V
V1
1
After the 2nd V5
iteration
After the 3rd
iteration
03/09/2012
13
14. V3
V2 3 V2 3 V3
1 1
2
1 1
V1 V1
1 V6
1
V4 V5 V4 V5
After the 4th After the 5th
iteration iteration
03/09/2012
14
15. The Travelling Salesman Problem (TSP) is an NP-hard problem
studied in OR(Operational Research) and theoretical
computer science.
You are given a set of n cities
You are given the distances between the cities.
You start and terminate your tour at your home city.
You must visit each other city exactly once.
Your mission is to determine the shortest tour.
03/09/2012 15
16. The TSP is easy to state, takes no math background to
understand, and no great talent to find feasible solutions. It’s
fun, and invites recreational problem solvers.
It inturn has many practical applications.
Many hard problems, such as job shop scheduling, can be
converted algebraically to and from the TSP.
A good TSP algorithm will be good for other hard problems.
03/09/2012 16
18. It works only on undirected graphs.
Step 1, minimum spanning tree: we construct a minimum cost
spanning tree T for graph G
Step 2, Creating a Cycle:Now that we have our MST M , we
can create a cycle W from it. In order to do this, we walk
along the nodes in a depth first search, revisiting vertices as
ascend. Graphically, this means outlining the tree.
03/09/2012 18
19. Step 3, Removing Redundant Visits: In order to create a
plausible solution for the TSP, we must visit vertices exactly
once.
Since we used an MST, we know that each vertex is visited at
least once, so we need only remove duplicates in such a way
that does not increase the weight.
Algorithm complexity is O(n3).
03/09/2012 19
30. Applying graph theory to a system means using a graph-
theoretic representation
Representing a problem as a graph can provide a different
point of view.
Representing a problem as a graph can make a problem much
simpler.
More accurately, it can provide the appropriate tools for solving the
problem.
03/09/2012 30