The Bellman-Ford Algorithm is a popular algorithm for computing the shortest paths from a single source vertex to all the other vertices in a weighted digraph. It is widely used in network routing protocols and is also useful in other applications such as detecting negative cycles in a graph.

Here are the steps involved in the Bellman-Ford Algorithm:

  • Initialize the distance to the source vertex as 0 and the distance to all other vertices as infinity.
  • Repeat the following step V – 1 times, where V is the total number of vertices in the graph:
    a. For each edge (u, v) in the graph, calculate the distance to vertex v as the minimum of its current distance and the distance to vertex u plus the weight of the edge (u, v).
  • Check for the presence of negative cycles in the graph by repeating step 2 and checking if any distance is updated. If a distance is updated, then there is a negative cycle in the graph.
  • Return the distances to all the vertices as the output of the algorithm.

Example of finding the shortest paths from vertex A to all the other vertices in the following weighted digraph using the Bellman-Ford Algorithm:

    -1      4
A --------> B
|           | \
|      2    |  3
v           v  v
C --------> D ---> E
      2        -3
  1. Initialize the distance to vertex A as 0 and the distance to all other vertices as infinity: dist[A] = 0, dist[B] = dist[C] = dist[D] = dist[E] = infinity.
  2. Repeat the following step 4 times: a. For each edge (u, v) in the graph, calculate the distance to vertex v as the minimum of its current distance and the distance to vertex u plus the weight of the edge (u, v).
    • For edge (A, B): dist[B] = min(dist[B], dist[A] + weight(A, B)) = min(infinity, 0 + 4) = 4.
    • For edge (A, C): dist[C] = min(dist[C], dist[A] + weight(A, C)) = min(infinity, 0 + 2) = 2.
    • For edge (B, D): dist[D] = min(dist[D], dist[B] + weight(B, D)) = min(infinity, 4 + 3) = 7.
    • For edge (B, E): dist[E] = min(dist[E], dist[B] + weight(B, E)) = min(infinity, 4 + -3) = 1.
    • For edge (C, D): dist[D] = min(dist[D], dist[C] + weight(C, D)) = min(7, 2 + 2) = 4.
    • For edge (D, E): dist[E] = min(dist[E], dist[D] + weight(D, E)) = min(1, 7 + -3) = 1.
      b. The distances after each iteration are:
    • dist[A] = 0, dist[B] = 4, dist[C] = 2, dist[D] = 4, dist[E] = 1.
  3. Check for the presence of negative cycles by repeating step 2 and checking if any distance is updated. Since no distance is updated in this step, there is no negative cycle in the graph.
  4. Return the distances to all the vertices as the output of the algorithm: dist[A] = 0, dist[B] = 4, dist[C] =

DAA-2022

Q-1.

(a) What do you understand by a recurrence ? write a detailed note on the substitution method for solving a recurrence.

(b) Discuss the concept of asymptotic notation and its properties.

Q-2.

What do you understand by time complexity ? What is big O notation ? Write the Quick sort algorithm and discuss its complexity.

Q-3

What do you understand by dynamic programming ? discuss using the example of matrix chain multiplication.

Q-4

What is Huffman code ? discuss the greedy algorithm for constructing the Huffman code.

Q-5

What is minimum spanning tree ? discuss the steps for finding minimum spanning tree using Prim’s Algorithm

Q-6

Discuss Bellman-Ford algorithm that compute shortest paths from a single source vertex to all of the other vertices in a weighted diagraph

Q-7

What is bitonic sequence ? discuss bitonic sort algorithm and it’s time complexity.

Q-8

What is sorting Network ? Discuss the structure of bubble sorting network.

JOIN OUR NEWSLETTER
And get notified everytime we publish a new blog post.