8. Write a program
to find the shortest
path between vertices using bellman-ford algorithm.
Distance Vector Algorithm is a decentralized
routing algorithm that requires that each router simply inform its neighbors of its routing
table. For each network path, the receiving
routers pick the neighbor advertising the lowest cost, then add this entry into its routing
table for re-advertisement. To find the shortest
path, Distance Vector Algorithm is based on one of two basic algorithms: the Bellman-Ford and the Dijkstra algorithms.
Routers that use this algorithm have to maintain the distance
tables (which is a one- dimension array -- "a vector"), which tell the distances
and shortest path to
sending packets
to each node in the network.
The information in the distance
table is always up date by exchanging information with the neighboring nodes. The number of data in the table equals to that of all nodes in networks
(excluded itself). The columns
of table represent the directly attached neighbors whereas the rows represent all destinations in the network.
Each data contains
the path for sending
packets to each destination in the network and distance/or time to transmit on that path (we call this as "cost").
The measurements in this
algorithm are the number of hops, latency, the number of outgoing
packets, etc.
The Bellman–Ford algorithm is an algorithm
that computes shortest paths from a single source vertex to all of the other vertices
in a weighted digraph. It is slower than Dijkstra's algorithm for the same problem, but more versatile, as it is capable of handling graphs in which some of the edge weights are negative numbers. Negative edge weights are found in various
applications of graphs,
hence the usefulness of this algorithm. If a graph contains a "negative cycle" (i.e. a cycle whose
edges sum to a negative value) that is reachable
from the source, then there is no cheapest path: any path that
has a point on the negative cycle can be made cheaper by one more
walk around
the negative cycle. In such a case, the Bellman–Ford algorithm can detect negative
cycles and report their existence.
No comments:
Post a Comment