Graph Theory Assignment 4
Graph Theory Assignment 4
Semester: 7th
Nabajyoti Dewri
GAU-C-17/257
Information Technology(IT)
B.Tech 7th sem
1. Explain the Dijkstra algorithm and analyze its complexity.
Ans:
It is a greedy algorithm that solves the single-source shortest path problem for a
directed graph G = (V, E) with nonnegative edge weights, i.e., w (u, v) ≥ 0 for each edge
(u, v) ∈ E.
Dijkstra's Algorithm maintains a set S of vertices whose final shortest - path weights
from the source s have already been determined. That's for all vertices v ∈ S; we have d
[v] = δ (s, v). The algorithm repeatedly selects the vertex u ∈ V - S with the minimum
shortest - path estimate, inserts u into S and relaxes all edges leaving u.
Because it always chooses the "lightest" or "closest" vertex in V - S to insert into set S, it
is called as the greedy strategy.
With adjacency list representation, all vertices of the graph can be traversed using
BFS in O(V+E) time.
In min heap, operations like extract-min and decrease-key value takes O (logV) time.
So, overall time complexity becomes O(E+V) x O(logV) which is O((E + V) x logV) =
O(ElogV)
This time complexity can be reduced to O (E+VlogV) using Fibonacci heap.
Ans:
Solves single shortest path problem in which edge weight may be negative but no
negative cycle exists.
This algorithm works correctly when some of the edges of the directed graph G may have
negative weight. When there are no cycles of negative weight, then we can find out the
shortest path between source and destination.
It is slower than Dijkstra's Algorithm but more versatile, as it capable of handling some of
the negative weight edges.
This algorithm detects the negative cycle in a graph and reports their existence.
Based on the "Principle of Relaxation" in which more accurate values gradually recovered
an approximation to the proper distance by until eventually reaching the optimum
solution.
Given a weighted directed graph G = (V, E) with source s and weight function w: E → R,
the Bellman-Ford algorithm returns a Boolean value indicating whether or not there is a
negative weight cycle that is attainable from the source. If there is such a cycle, the
algorithm produces the shortest paths and their weights. The algorithm returns TRUE if
and only if a graph contains no negative - weight cycles that are reachable from the
source.
Recurrence Relation
Dijkstra follows a simple rule if all edges have non negative weights, adding an edge will
never make the path smaller. That's why it follows the greedy strategy and picks up the
shortest path and in turn which turns out optimal.
Let's start with A.
A -> A will be marked as 0, everything else from A will be infinity.
In next turn
A -> B will be 1.
A -> D will be 99.
A -> C will be 0.
Still A -> C is 0, when there is a shorter path from A -> D -> B -> C costing -200. Dijsktra
will not be able to find out this and it fails.