0% found this document useful (0 votes)
117 views

Graph Theory Notes

Uploaded by

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

Graph Theory Notes

Uploaded by

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

Module IV: Network design and graph theory:

● Graphs

● Minimum spanning three (MST)

● Kruskal’s Algorithm; Prim’s algorithm

● Trees

● Tree design

● Drawback of MST’s

● Shortage path trees and tours

● Bottleneck path problem


Introduction
In the modern world, planning efficient routes is essential for business
and industry, with applications as varied as product distribution,
laying new fiber optic lines for broadband internet, and suggesting
new friends within social network websites like Facebook.
This field of mathematics started nearly 300 years ago as a look into a
mathematical puzzle (we’ll look at it in a bit). The field has exploded
in importance in the last century, both because of the growing
complexity of business in a global economy and because of the
computational power that computers have provided us.
In mathematics and computer science, graph theory is the study of
graphs: A ”graph” in this context refers to a collection of vertices or
’nodes’ and a collection of edges that connect pairs of vertices. The
graphs studied in graph theory should not be confused with ”graphs of
functions” and other kinds of graphs.
The Seven Bridges of Ko̎ nigsberg is a notable historical problem in
mathematics.The city of KÄonigsberg was located on the Pregel
River in Prussia. The river di- vided the city into four separate
landmasses, including the island of Kneiphopf. These four regions
were linked by seven bridges as shown in the diagram. Residents of
the city wondered if it were possible to leave home, cross each of the
seven bridges exactly once, and return home. The Swiss
mathematician Leon- hard Euler (1707-1783) thought about this
problem and the method he used to solve it is considered by many to
be the birth of graph theory.

Figure 4.2
The key to Euler's solution was in a very simple abstraction of the
puzzle.Let us redraw our diagram of the city of KÄonigsberg by
representing each of the land masses as a vertex and representing each
bridge as an edge connecting the vertices corresponding to the land
masses. We now have a graph that encodes the necessary information.
The problem reduces to finding a "closed walk" in the graph which
traverses each edge exactly once, this is called an Eulerian circuit.
Graph theory may be said to have its beginning in 1736 when
LEONHARD
EULER considered the (general case of the) k¨onigsberg bridge
problem: Does
there exist a walk crossing each of the seven bridges of K¨onigsberg
exactly once? It took 200 years before the first book on graph theory
was written. This was (Theorie der endlichen und unendlichen
Graphen) (Teubner, Leipzig, 1936) by KONIG in 1936. Since then
graph theory has developed into an extensive and popular branch of
mathematics, which has been applied to many problems in
mathematics, computer science, and other scientific and not-so-
scientific areas.There are no standard notations for graph theoretical
objects. This is natural, because the names one uses for the objects
reflect the applications. Thus, for instance, if we consider a
communications network (say, for email) as a graph, then the
computers taking part in this network, are called nodes rather than
vertices or points. On the other hand, other names are used for
molecular structures in chemistry, flow charts in programming,
human relations in social sciences, and so on.
Definitions
A graph G is defined as: It is a non-empty set of elements called
Vertices with a family of non-ordered pair of the vertices called edges
E. The set of the vertices G denoted by V (G), the family of edges
denoted by E(G) and the graph is denoted by (V, E).
Graphically, we represent a graph by drawing a point for each vertex
and representing each edge by a curve joining its endpoints. For our
purposes all graphs will be finite graphs, i.e. graphs for which V (G)
and E(G) are finite sets, unless specifically stated otherwise.
Note that in our definition, we do not exclude the possibility that the
two endpoints of an edge are the same vertex. This is called a loop,
for obvious reasons. Also, we may have multiple edges, which is
when more than one edge shares the same set of endpoints, i.e. the
edges of the graph are not uniquely determined by their endpoints.
A simple graph is a graph having no loops or multiple edges. In this
case, each edge e in E(G) can be specified by its endpoints u; v in V
(G). Sometimes we write e = uv.
Vertex: A vertex is a dot in the graph where edges meet. A vertex
could represent an intersection of streets, a land mass, or a general
location, like “work” or “school”. Note that vertices only occur when
a dot is explicitly placed, not whenever two edges cross. Imagine a
freeway overpass – the freeway and side street cross, but it is not
possible to change from the side street to the freeway at that point, so
there is no intersection and no vertex would be placed.
Edges: Edges connect pairs of vertices. An edge can represent a
physical connection between locations, like a street, or simply that a
route connecting the two locations exists, like an airline flight.
Loop: A loop is a special type of edge that connects a vertex to itself.
Loops are not used much in street network graphs.

Figure 4.3
Degree of a vertex: The degree of a vertex is the number of edges
meeting at that vertex. It is possible for a vertex to have a degree of
zero or larger.

Figure 4.4

Path: A path is a sequence of vertices using the edges. Usually we


are interested in a path between two vertices. For example, a path
from vertex A to vertex M is shown below. It is one of many possible
paths in this graph.

Figure 4.5

Circuit: A circuit is a path that begins and ends at the same vertex. A
circuit starting and ending at vertex A is shown below.

Figure 4.6
Connected: A graph is connected if there is a path from any vertex to
any other vertex.
Weights: Depending upon the problem being solved, sometimes
weights are assigned to the edges. The weights could represent the
distance between two locations, the travel time, or the travel cost. It
is important to note that the distance between vertices in a graph does
not necessarily correspond to the weight of an edge.
Isolated vertex: Is a vertex which has no any edges.
Multiple edge: There is a multiple edge between two vertices u, v if
there is more
than one edge join u, v.
Multigraph:Is a graph with multiedge.
P-graph: G is p-graph if number of repeated each non-ordered pair of
two vertices
is not greater then p.

4.1.2 ExampleLet V ={v1, ..., v5} and


E={[v1, v2], [v1, v3], [v1, v2], [v1, v4], [v2, v3], [v2, v1], [v2, v3],
[v4, v4]}
This graph has 5-vertices and 8-edges. There are 3-edges between v1
and v2. 2-edges between v2 and v3. v5 is isolated. [v1, v2] and [v1,
v4] are adjacent and the graph is 3-graph.

4.1.3 Some Important Terminology


Order of graph: The number of the vertices is called the Order of
graph G.
Finite graph: G is finite if the number of edges is finite.
Size of a vertex: Is the number of the edges incident with the vertex
with evaluating
each loop twice . Denoted by ρ(v).
Theorem: In a graph the sum of degrees of all vertices is equal to
twice number of the edges.
Corollary: In each graph the number of odd degree vertices is even.
When two vertices u; v in V (G) are endpoints of an edge, we say u
and v are adjacent.
A path is a simple graph whose vertices can be ordered so that two
vertices are adjacent if and only if they are consecutive in the
ordering. A path which begins at vertex u and ends at vertex v is
called a u; v-path.
A cycle is a simple graph whose vertices can be cyclically ordered so
that two vertices are adjacent if and only if they are consecutive in the
cyclic ordering.
We usually think of paths and cycles as sub-graphs within some larger
graph.
A subgraph H of a graph G, is a graph such that V (H) V (G) and
E(H) E(G) satisfying the property that for every e ϵ E(H), where e
has endpoints u; v ϵ V (G) in the graph G, then u; v ϵ V (H) and e has
endpoints u; v in H, i.e. the edge relation in H is the same as in G.
4.1.4 Important Graphs
There are two special types of graphs which play a central role in
graph theory; they are the complete graphs and the complete
bipartite graphs. A complete graph is a simple graph whose vertices
are pairwise adjacent. The complete graph with n vertices is denoted
Kn.

Figure 4.7

An independent set in a graph is a set of vertices that are pairwise


nonadjacent. A graph G is bipartite if V (G) is the union of two
disjoint (possibly empty) independent sets, called partite sets of G.
Similarly, a graph is k-partite if V (G) is the union of k disjoint
independent sets.

3 different bipartite graphs


Figure 4.8
A 3-partite graph
Figure 4.9

A complete bipartite graph is a simple bipartite graph such that two


vertices are adjacent if and only if they are in different partite sets.
The complete bipartite graph with partite sets of size m and n is
denoted Km,n.

Figure 4.10

4.2 Spanning trees


A spanning tree of a connected graph G is an acyclic connected
subgraph of G containing all of G’s vertices. It is not difficult tosee
that every connected graph G has a spanning tree. Let T be a
spanningsubgraph of G with a minimal number of edges. Clearly,
every edge e inT is a cut edge of T, for otherwise T would not be
minimal.
More interesting than just noticing that a connected graph G has a
spanning tree, is finding a minimal spanning tree in a weighted
connected graph G.A Minimum Spanning Tree in an undirected
connected weighted graph is a spanning tree of minimum weight
(among all spanning trees).The minimum spanning tree may not be
unique. However, if the weights of all the edges are pairwise distinct,
it is indeed unique In other words, our goal is to find a spanning tree
T with minimal weight among all spanning trees of G. Recall that the
weight of a subgraph H is simply defined as the total sum of the
weights of H’s edges:

4.2.1 Example:

Minimum spanning tree


Figure 4.11

A famous algorithm that efficiently constructs such a tree was


designed by Prim and Kruskal [1956].
4.2.2 Prim's Algorithm
Prim's algorithm is an algorithm in graph theory that finds a minimum
spanning tree for a connected weighted graph. This means it finds a
subset of the edges that forms a tree that includes every vertex, where
the total weight of all the edges in the tree is minimized.This
algorithm also follows Greedy method like the Kruskal's algorithm. In
prim's algorithm, the set A always forms a single tree. It finds a subset
of the edges that forms a tree that includes every vertex, where the
total weight of all the edges in the tree is minimized.It starts with an
empty spanning tree. The idea is to maintain two sets of vertices. The
first set contains the vertices already included in the MST, the other
set contains the vertices not yet included. At every step, it considers
all the edges that connect the two sets, and picks the minimum weight
edge from these edges. After picking the edge, it moves the other
endpoint of the edge to the set containing MST (Minimum Spanning
Tree).
A group of edges that connects two set of vertices in a graph is called
cut in graph theory. So, at every step of Prim’s algorithm, we find a
cut (of two sets, one contains the vertices already included in MST
and other contains rest of the verices), pick the minimum weight edge
from the cut and include this vertex to MST Set (the set that contains
already included vertices).

4.2.3 Algorithm
1) Create a set MST Set that keeps track of vertices already included
in MST.
2) Assign a key value to all vertices in the input graph. Initialize all
key values as INFINITE. Assign key value as 0 for the first vertex so
that it is picked first.
3) While MST Set doesn’t include all vertices
a) Pick a vertex u which is not there in MST set and has minimum key
value.
b) Include u to MST Set.
c) Update key value of all adjacent vertices of u. To update the key
values, iterate
through all adjacent vertices. For every adjacent vertex v, if weight of
edge u-v
is less than the previous key value of v, update the key value as
weight of u-v.

The idea of using key values is to pick the minimum weight edge
from cut. The key values are used only for vertices which are not yet
included in MST, the key value for these vertices indicate the
minimum weight edges connecting them to the set of vertices
included in MST.
Let us understand with the following example:

Figure 4.12

The set MST SET is initially empty and keys assigned to vertices are
{0, INF, INF, INF, INF, INF, INF, INF} where INF indicates infinite.
Now pick the vertex with minimum key value. The vertex 0 is picked,
include it in MST SET. So MST SET becomes {0}. After including to
MST SET, update key values of adjacent vertices. Adjacent vertices
of 0 are 1 and 7. The key values of 1 and 7 are updated as 4 and 8.
Following subgraph shows vertices and their key values, only the
vertices with finite key values are shown. The vertices included in
MST are shown in green color

Figure 4.13

Pick the vertex with minimum key value and not already included in
MST (not in MST SET). The vertex 1 is picked and added to MST
SET. So MST SET now becomes {0, 1}. Update the key values of
adjacent vertices of 1. The key value of vertex 2 becomes 8.

Figure 4.14

Pick the vertex with minimum key value and not already included in
MST (not in MST SET). We can either pick vertex 7 or vertex 2, let
vertex 7 is picked. So MST SET now becomes {0, 1, 7}. Update the
key values of adjacent vertices of 7. The key value of vertex 6 and 8
becomes finite (7 and 1 respectively).

Figure 4.15

Pick the vertex with minimum key value and not already included in
MST (not in MST SET). Vertex 6 is picked. So MST SET now
becomes {0, 1, 7, 6}. Update the key values of adjacent vertices of 6.
The key value of vertex 5 and 8 are updated.
Figure 4.16

We repeat the above steps until MST SET doesn’t include all vertices
of given graph. Finally, we get the following graph.

Figure 4.17

4.2.4 Kruskal's algorithm:


Kruskal's algorithm is a greedy algorithm in graph theory that finds a
minimum spanning tree for a connected weighted graph. This means
it finds a subset of the edges that forms a tree that includes every
vertex, where the total weight of all the edges in the tree is minimized.
If the graph is not connected, then it finds a minimum spanning forest.
4.2.5 Description

● create a forest F (a set of trees), where each vertex in the graph

is a separate tree
● create a set S containing all the edges in the graph

● while S is nonempty and F is not yet spanning

● remove an edge with minimum weight from S

● if that edge connects two different trees, then add it to the forest,

combining two trees into a single tree

● Otherwise discard that edge.

The algorithm is a Greedy Algorithm. The Greedy Choice is to pick


the smallest weight edge that does not cause a cycle in the MST
constructed so far. Let us understand it with an example: Consider the
below input graph.

Figure 4.18

The graph contains 9 vertices and 14 edges. So, the minimum


spanning tree formed will be having (9 – 1) = 8 edges.

After sorting:
Weight Src Dest
1 7 6
2 8 2
2 6 5
4 0 1
4 2 5
6 8 6
7 2 3
7 7 8
8 0 7
8 1 2
9 3 4
10 5 4
11 1 7
14 3 5

Now pick all edges one by one from sorted list of edges
1. Pick edge 7-6: No cycle is formed, include it.

Figure 4.19

2. Pick edge 8-2: No cycle is formed, include it.


Figure 4.20

3. Pick edge 6-5: No cycle is formed, include it.

Figure 4.21

4. Pick edge 0-1: No cycle is formed, include it.

Figure 4.22

5. Pick edge 2-5: No cycle is formed, include it.


Figure 4.23

6. Pick edge 8-6: Since including this edge results in cycle, discard it.
7. Pick edge 2-3: No cycle is formed, include it.

Figure 4.24
8. Pick edge 7-8: Since including this edge results in cycle, discard it.

9. Pick edge 0-7: No cycle is formed, include it.

Figure 4.25

10. Pick edge 1-2: Since including this edge results in cycle, discard
it.

11. Pick edge 3-4: No cycle is formed, include it.


Figure 4.26

Since the number of edges included equals (V – 1), the algorithm


stops here.

BOTTLE NECK PROBLEM:


In graph algorithms, the widest path problem, also known as
the bottleneck shortest path problem or the maximum
capacity path problem, is the problem of finding
a path between two designated vertices in a weighted graph,
maximizing the weight of the minimum-weight edge in the path.
For instance, if the graph represents connections
between routers in the Internet, and the weight of an edge
represents the bandwidthof a connection between two routers,
the widest path problem is the problem of finding an end-to-end
path between two Internet nodes that has the maximum
possible bandwidth.[1] The weight of the minimum-weight edge
is known as the capacity or bandwidth of the path. As well as its
applications in network routing, the widest path problem is also
an important component of the Schulze method for deciding the
winner of a multiway election,[2] and has been applied to digital
compositing,[3] metabolic analysis,[4] and the computation
of maximum flows.[5] It is possible to adapt most shortest
path algorithms to compute widest paths, by modifying them to
use the bottleneck distance instead of path length.[6] However,
in many cases even faster algorithms are possible.
A closely related problem, the minimax path problem, asks for
the path that minimizes the maximum weight of any of its
edges. It has applications that include transportation planning.
[7]
Any algorithm for the widest path problem can be
transformed into an algorithm for the minimax path problem, or
vice versa, by reversing the sense of all the weight
comparisons performed by the algorithm, or equivalently by
replacing every edge weight by its negation.
Undirected graphs[edit]
In an undirected graph, a widest path may be found as the path
between the two vertices in the maximum spanning tree of the
graph, and a minimax path may be found as the path between
the two vertices in the minimum spanning tree.[8][9][10]
In any graph, directed or undirected, there is a straightforward
algorithm for finding a widest path once the weight of its
minimum-weight edge is known: simply delete all smaller edges
and search for any path among the remaining edges
using breadth first search or depth first search. Based on this
test, there also exists a linear time algorithm for finding a
widest s-t path in an undirected graph, that does not use the
maximum spanning tree. The main idea of the algorithm is to
apply the linear-time path-finding algorithm to themedian edge
weight in the graph, and then either to delete all smaller edges
or contract all larger edges according to whether a path does or
does not exist, and recurse in the resulting smaller graph.[9][11][12]
Fernandez, Garfinkel & Arbiol (1998) use undirected bottleneck
shortest paths in order to form composite aerial
photographs that combine multiple images of overlapping
areas. In the subproblem to which the widest path problem
applies, two images have already been transformed into a
common coordinate system; the remaining task is to select
aseam, a curve that passes through the region of overlap and
divides one of the two images from the other. Pixels on one
side of the seam will be copied from one of the images, and
pixels on the other side of the seam will be copied from the
other image; unlike other compositing methods that average
pixels from both images, this produces a valid photographic
image of every part of the region being photographed. They
weight the edges of a grid graph by a numeric estimate of how
visually apparent a seam through that point would be; the
choice of a bottleneck shortest path as the seam, rather than a
more conventional shortest path, forces their system to find a
seam that is difficult to discern at all of its points, rather than
allowing it to trade off greater visibility in one part of the image
for lesser visibility elsewhere.[3]
If all edge weights of an undirected graph are positive, then the
minimax distances between pairs of points (the maximum edge
weights of minimax paths) form an ultrametric; conversely
every finite ultrametric space comes from minimax distances in
this way.[13] A data structure constructed from the minimum
spanning tree allows the minimax distance between any pair of
vertices to be computed in constant time per distance,
using lowest common ancestor queries in a Cartesian tree. The
root of the Cartesian tree represents the heaviest minimum
spanning tree edge, and the children of the root are Cartesian
trees recursively constructed from the subtrees of the minimum
spanning tree formed by removing the heaviest edge. The
leaves of the Cartesian tree represent the vertices of the input
graph, and the minimax distance between two vertices equals
the weight of the Cartesian tree node that is their lowest
common ancestor. Once the minimum spanning tree edges
have been sorted, this Cartesian tree can be constructed in
linear time.[14]
Run Dijkstra's algorithm on the following directed graph, starting at
vertex 1. After each iteration of the outer loop, show the contents of
the queue Q (the vertices in the queue and their keys). What are the
final distances (in the distance[] array)?
iteration 0: Q={vertex 1 with key 0}

iteration 1: Q={vertex 2 with key 10, vertex 3 with key 50,


vertex 4 with key 65} (distance[1] = 0)

iteration 2: Q={vertex 3 with key 40, vertex 4 with key 65,


vertex 5 with key 14} (distance[2] = 10)

iteration 3: Q={vertex 3 with key 40, vertex 4 with key 65}


(distance[5] = 14)

iteration 4: Q={vertex 4 with key 63} (distance[3] = 40)

iteration 5: Q={} (distance[4] = 63)

2. The bottleneck of a path is the smallest weight WT(u,v) of any


edge (u,v) on the path. Given a directed graph G=(V,E) with edge wts
and a source vertex s, define, for each vertex v,
max_bottleneck(s,v) = the maximum, over all paths p from s to
v, of the bottleneck of p.

The maximum bottleneck paths problem is (given G, s, and WT), to


compute max_bottleneck(s,v) for each vertex v.
(For example, suppose the vertices represent cities, the edges
represent roads, and the weight WT(u,v) of an edge (u,v) is the
clearance of the lowest bridge on the road from u to v. Then
max_bottleneck(s,v) is the height of the largest truck that can get from
s to v.)
2A: For each vertex v in the graph for problem 1, what is
max_bottleneck(s,v)?
Assuming s=1, mb(s,1) = ∞, mb(s,2) = 23, mb(s,3) = 50, mb(s,4) =
65, mb(s,5) = 44
2B: Describe a linear-time algorithm for maximum bottleneck paths
that works for acyclic digraphs. Give a high-level description and
pseudo-code.
High-level description:
The maximum bottleneck of any path from s to w is the maximum
bottleneck of any path from s through any immediate predecessor v of
w to w. This gives the following recurrence: mb(s,v) = max
{ min{WT(w,u), mb(s,w)} : (w,u) ∈ E }. Use this recurrence and
dynamic programming to compute the max bottlenecks:
1. Consider the vertices in topological
order.
2. Set mb(s,s) = ∞.
3. For each vertex v, set mb(s,v) = max
{ min{WT(w,u), mb(s,w)} : (w,u) ∈ E }.

You might also like