2. The single-source shortest path problem, in
which we have to find shortest paths from
a source vertex v to all other vertices in the
graph. The single-destination shortest
path problem, in which we have to
find shortest paths from all vertices in the
directed graph to a single destination vertex v.
3.
4. With this mapping, we can print the nodes on
the shortest path as follows:
Depth-First Search (DFS) This is probably the
simplest algorithm to get the shortest path. ...
Breadth-First Search (BFS) ...
Bidirectional Search. ...
Dijkstra's Algorithm. ...
Bellman-Ford Algorithm.
5. Algorithm to find the shortest path between
two vertices in an undirected graph
Input the graph.
Input the source and destination nodes.
Find the paths between the source and the
destination nodes.
Find the number of edges in all the paths and
return the path having the minimum number
of edges.
6. DFS does not necessarily yield shortest
paths in an undirected graph. ... If you try to
find the shortest path from one node to
another using DFS, then you will get the
wrong answer unless you follow the edge
directly connecting the start and destination
nodes.ss
7. DFS algorithm
A standard DFS implementation puts each vertex of the graph into one of
two categories:
Visited
Not Visited
The purpose of the algorithm is to mark each vertex as visited while
avoiding cycles.
The DFS algorithm works as follows:
Start by putting any one of the graph's vertices on top of a
stack.
Take the top item of the stack and add it to the visited list.
Create a list of that vertex's adjacent nodes. Add the ones
which aren't in the visited list to the top of the stack.
Keep repeating steps 2 and 3 until the stack is empty.
8. DFS(G, u)
u.visited = true
for each v ∈ G.Adj[u]
if v.visited == false
DFS(G,v) init()
{
For each u ∈ G
u.visited = false
For each u ∈ G
DFS(G, u)
}
9. Given a unweighted graph, a source and
a destination, we need to find shortest
path from source to destination in the
graph in most optimal way.
10.
11. The algorithm we are going to use to
determine the shortest path is called
“Dijkstra's algorithm.” Dijkstra's
algorithm is an iterative algorithm that
provides us with the shortest path from
one particular starting node to all other
nodes in the graph. ... When a vertex is
first created dist is set to a very large
number.
12. Dijkstra's algorithm keeps two sets of
vertices:
S the set of vertices whose shortest paths from
the source have already been determined and
V-S the remaining vertices.The other data
structures needed are:
D array of best estimates of shortest path to
each vertex
Pi an array of predecessors for each vertex
13. initialise_single_source( Graph g, Node s )
for each vertex v in Vertices( g )
g.d[v] := infinity
g.pi[v] := nil
g.d[s] := 0;
14.
15. A negative cycle is one in which the overall
sum of the cycle comes negative.
Negative weights are found in various
applications of graphs. For example, instead of
paying cost for a path, we may get some
advantage if we follow the path
19. A cyclic graph is a directed graph which
contains a path from at least one node back to
itself. In simple terms cyclic graphs contain a
cycle. An acyclic graph is a
directed graph which contains absolutely no
cycle, that is no node can be traversed back to
itself.
20.
21. To test a graph for being acyclic:
If the graph has no nodes, stop. The graph is
acyclic.
If the graph has no leaf, stop. The graph is cyclic.
Choose a leaf of the graph. ...
Go to 1.
If the Graph has no nodes, stop. ...
If the graph has no leaf, stop. ...
Choose a leaf of Graph. ...
Go to 1.
22. The all pair shortest path algorithm is also
known as Floyd-Warshall algorithm is used to
find all pair shortest path problem from a
given weighted graph. As a result of
this algorithm, it will generate a matrix, which
will represent the minimum distance from any
node to all other nodes in the graph.
26. In graph theory, the shortest path problem is
the problem of finding a path between two
vertices (or nodes) in a graph such that the sum
of the weights of its constituent edges is
minimized.
27.
28. single-Pair Shortest Path Problem-
It is a shortest path problem where the shortest
path between a given pair of vertices is
computed.
A* Search Algorithm is a famous algorithm
used for solving single-pair shortest path
problem.
29. Minimum Spanning Tree (MST)
In a weighted graph, a minimum spanning tree
is a spanning tree that has minimum weight
than all other spanning trees of the same graph.
In real-world situations, this weight can be
measured as distance, congestion, traffic load
or any arbitrary value denoted to the edges.
30. Minimum Spanning-Tree Algorithm
We shall learn about two most important
spanning tree algorithms here −
Kruskal's Algorithm
Prim's Algorithm
31.
32. General Properties of Spanning
Tree
We now understand that one graph can have more than one
spanning tree. Following are a few properties of the
spanning tree connected to graph G −
A connected graph G can have more than one spanning tree.
All possible spanning trees of graph G, have the same
number of edges and vertices.
The spanning tree does not have any cycle (loops).
Removing one edge from the spanning tree will make the
graph disconnected, i.e. the spanning tree is minimally
connected.
Adding one edge to the spanning tree will create a circuit or
loop, i.e. the spanning tree is maximally acyclic.
33. Mathematical Properties of
Spanning Tree
Spanning tree has n-1 edges, where n is the
number of nodes (vertices).
From a complete graph, by removing maximum e -
n + 1 edges, we can construct a spanning tree.
A complete graph can have maximum nn-2 number
of spanning trees.
Thus, we can conclude that spanning trees are a
subset of connected Graph G and disconnected
graphs do not have spanning tree.
34. Application of Spanning Tree
Spanning tree is basically used to find a
minimum path to connect all nodes in a graph.
Common application of spanning trees are −
Civil Network Planning
Computer Network Routing Protocol
Cluster Analysis