Submited To: Professor Arif SUBMITTED BY: Maria Ahsan (BSEM-F18-038)
Submited To: Professor Arif SUBMITTED BY: Maria Ahsan (BSEM-F18-038)
TASK 4
SUBMITED TO: PROFESSOR ARIF
SUBMITTED BY: Maria Ahsan(BSEM-F18-038)
Bellman-Ford algorithm:
The Bellman-Ford algorithm is an example of Dynamic Programming. It starts with a starting vertex and
calculates the distances of other vertices which can be reached by one edge. It then continues to find a
path with two edges and so on. The Bellman-Ford algorithm follows the bottom-up approach.
Usage:
The Bellman-Ford algorithm is a graph search algorithm that finds the shortest path between a given
source vertex and all other vertices in the graph. This algorithm can be used on both weighted and
unweighted graphs.
Dijkstra Algorithm
Dijkstra's algorithm will assign some initial distance values and will try to improve them step by step. ...
For example, if the current node A is marked with a distance of 6, and the edge connecting it with a
neighbour B has length 2, then the distance to B through A will be 6 + 2 = 8.
Usage:
Dijkstra's algorithm is mainly used to find the shortest path from a starting node / point to the target
node / point in a weighted graph. When Dijkstra's algorithm is applied, it creates a tree of shortest path
from a starting vertex / source to all the other nodes in the graph.
Distance-vector routing protocols use the Bellman–Ford algorithm and Ford–Fulkerson algorithm to
calculate the best route. Another way of calculating the best route across a network is based on link cost,
and is implemented through link-state routing protocols.
The term distance vector refers to the fact that the protocol manipulates vectors (arrays) of distances to
other nodes in the network. The distance vector algorithm was the original ARPANET routing algorithm
and was implemented more widely in local area networks with the Routing Information Protocol (RIP).
Let us understand this algorithm with an example:
Initially, we can see that all the routers have their own routing table. But, these routing tables
are not created synchronously. Whenever a router is booted it creates its routing table.
Now, let us consider that router A has shared records of its routing table with all its neighbour
i.e. B, C & D. For understanding we take the scenario where A is sharing records of its routing
table with router B.
In the diagram below we have discussed the changes in the routing table of router B as it receives records
from router A.
When router B receives the first record ‘Net 1, 1’ it checks its routing table for the route to Net1 and as it
is not there in its routing table it adds Net 1 to it routing table with the next hop to be A and it also adds 1
hop to the existing cost of the record.When router B receives the second record from A ‘Net 2, 1’, it
checks its routing table and finds that it already exists in the routing table. Now, the record cost plus 1
seems to be larger than the cost in the routing table so it discards the entire record.
When router B receives the record R3 ‘Net 4, 1’. It checks its routing table and finds that the route to Net
4 is not there. So, it adds Net 4 to its routing table and adds 1 hop to the existing cost in the record with
next-hop A.
The same thing happens with record R4. Net 5 is not in the routing table of router B. So, it adds the same
to its routing table and adds 1 hop to the cost of record along with the next-hop A.
In a similar way, router A, C and D also update their routing table and send the updated information to
their neighbouring router. The final routing tables of all the routers for the current scenario would be like:
Link state routing protocols
As an example, let us consider the network in Figure and compute the shortest path from A to all possible
destinations. A tabular summary of the algorithm's computation is shown in Table 1, where each line in
the table gives the values of the algorithms variables at the end of the iteration. Let us consider the few
first steps in detail:
When the LS algorithm terminates, we have for each node, its predecessor along the least cost path from
the source node. For each predecessor, we also have its predecessor and so in this manner we can
construct the entire path from the source to all destinations.
What is the computation complexity of this algorithm? That is, given n nodes (not counting the source),
how much computation must be done in the worst case to find the least cost paths from the source to all
destinations? In the first iteration, we need to search through all n nodes to determine the node, w, not in
N that has the minimum cost. In the second iteration, we need to check n−1 nodes to determine the
minimum cost; in the third iteration n−2 nodes and so on. Overall, the total number of nodes we need to
search through over all the iterations is n*(n+1)/2, and thus we say that the above implementation of the
link state algorithm has worst case complexity of order n squared: O(n2). (A more sophisticated
implementation of this algorithm, using a data structure known as a heap, can find the minimum in line 9
in logarithmic rather than linear time, thus reducing the complexity).
Before completing our discussion of the LS algorithm, let us consider a pathology that can arise with the
use of link state routing. Figure 2) shows a simple network topology where link costs are equal to the load
carried on the link, e.g., reflecting the delay that would be experienced . In this example, link costs are not
symmetric, i.e., c(A,B) equals c(B,A) only if the load carried on both directions on the AB link is the
same. In this example, node D originates a unit of traffic destined for A, node B also originates a unit of
traffic destined for A, and node C injects an amount of traffic equal to e, also destined for A. The initial
routing is shown in Figure 2) with the link costs corresponding to the amount of traffic carried.
When the LS algorithm is next run, node C determines (based on the link costs shown in Figure 2) that
the clockwise path to A has a cost of 1, while the counterclockwise path to A (which it had been using)
has a cost of 1+e. Hence C's least cost path to A is now clockwise. Similarly, B determines that its new
least cost path to A is also clockwise, resulting in the routing and resulting path costs shown in Figure
4.2-2b. When the LS algorithm is run next, nodes B, C and D all detect that a zero cost path to A in the
counterclockwise direction and all route their traffic to the counterclockwise routes. The next time the LS
algorithm is run, B, C, and D all then route their traffic to the clockwise routes.