Question

In: Computer Science

Using the provided network diagram, write a program in c ++ that finds the shortest path...

Using the provided network diagram, write a program in c ++ that finds the shortest path routing using the Bellman-Ford algorithm. Your program should represent the fact that your node is U. Show how the iterative process generates the routing table for your node. One of the keys to your program will be in determining when the iterative process is done.

Deliverables 1. Provide an output that shows the routing table for your node after each iteration. Add a second table with two columns. One that shows the destination from your node and the second column indicating the number of hops to reach that node. 2. Provide a Word document that explains how your program incorporates the Bellman-Ford algorithm. Ensure you explain how you incorporated the iterative process and determined when the routing table for your node was optimum. You can incorporate your outputs into this document; however, you must identify where in your source code you print the results. 3. Provide a copy of your source code

Solutions

Expert Solution

Here is Implemetation of Bellman-Ford algorithm in C++ language.

Please Upvote or hit that like,thumbs-up button.

Bellman_Ford_algo.cpp

#include<iostream>
// Defining MAX size to 10
#define MAX 10

using namespace std;

typedef struct Edge
{
  int source;
  int destination;
  int weight;
}Edge;

void bellman_ford_algo(int nodevertex,Edge edge[],int source_graph,int nodeedge)
{
  int u,v,weight,i,j=0;
  int distance[MAX];

  for(i=0;i<nodevertex;i++)
  {
    distance[i]=999;
  }

  // distance of source vertex
  distance[source_graph]=0;

  // free all the edges nodevertex - 1 times
  for(i=0;i<nodevertex-1;i++)
  {
    for(j=0;j<nodeedge;j++)
    {
      u=edge[j].source;
      v=edge[j].destination;
      weight=edge[j].weight;


      if(distance[u]!=999 && distance[u]+weight < distance[v])
      {
        distance[v]=distance[u]+weight;
      }
    }

  }

  // checking for negative cycle
  for(j=0;j<nodeedge;j++)
  {
    u=edge[j].source;
    v=edge[j].destination;
    weight=edge[j].weight;

    if(distance[u]+weight < distance[v])
    {
      cout<<"\n\nNegative Cycle present..!!\n";
      return;
    }
  }

  cout<<"\nVertex"<<"  Distance from source";
  for(i=1;i<=nodevertex;i++)
  {
    cout<<"\n"<<i<<"\t"<<distance[i];
  }

}


int main()
{
  int nodevertex,nodeedge,source_graph;
  Edge edge[MAX];

  cout<<"Enter the number of vertices you want : ";
  cin>>nodevertex;


  printf("Enter the source vertex of the graph: ");
  cin>>source_graph;

  cout<<"\nEnter no. of edges you want : ";
  cin>>nodeedge;

  for(int i=0;i<nodeedge;i++)
  {
    cout<<"\nEdge Number "<<i+1<<"=";
    cout<<"\nEnter source vertex here :";
    cin>>edge[i].source;
    cout<<"Enter destination vertex here:";
    cin>>edge[i].destination;
    cout<<"Enter weight here :";
    cin>>edge[i].weight;
  }

  bellman_ford_algo(nodevertex,edge,source_graph,nodeedge);

  return 0;
}

Output:- Refer to screenshot

Again, Please hit that like button , it really motivates me<3

Thank you!!

Have a nice day:)


Related Solutions

i want a program in java that finds the shortest path in a 2D array with...
i want a program in java that finds the shortest path in a 2D array with obstacles from source to destination using BFS and recursion. The path must be stored in a queue. The possible moves are left,right,up and down.
about critical path of a project network is that, A. the critical path is the shortest...
about critical path of a project network is that, A. the critical path is the shortest of all paths through the network B. the critical path is the set of activities that has no slack time C. the critical path is that set of activities that has no positive slack time D. some networks may not have any critical path
Critical Path Network: a. Develop the critical path network. b. Show ES, EF, LS, LF, on the network. c. What are the critical path activities?
Critical Path Network:  a. Develop the critical path network. b. Show ES, EF, LS, LF, on the network. c. What are the critical path activities? d. What are the slack time of the activities? e. What is the completion time of the project? f. What are the expected times of the activities? g. What is the project variance? h. What is its standard deviation?
In C program, Use "do...while" and "for" loops to write a program that finds all prime...
In C program, Use "do...while" and "for" loops to write a program that finds all prime numbers less than a specified value.
Write a C++ program that finds the minimum number entered by the user .The user is...
Write a C++ program that finds the minimum number entered by the user .The user is allowed to enter negative numbers 0, or positive numbers. The program should be controlled with a loop statement. Break statements is not allowed to break from loop. After each number inputted by the user, The program will prompt user if they need to enter another number. User should enter either Y for yes or N for no. Make Sure the user enters either Y...
Part1: Write a program in C/C++ to find the maximum flow in the given Flow Network...
Part1: Write a program in C/C++ to find the maximum flow in the given Flow Network using (i)Ford -Fulkerson algorithm and (ii) Edmond-Karps algorithm Go through the related text and implement each of these algorithms using the efficient data structure. Show the results of different steps of these algorithms for an instance of the flow network with total number of nodesV=6 (please note down that in a flow network there are two special nodes source and sink) and total number...
*****Using Java Write a program that finds the standard deviation while also using a graphical user...
*****Using Java Write a program that finds the standard deviation while also using a graphical user interface.
In the Critical Path Method network diagram, what is unique about the early start and early...
In the Critical Path Method network diagram, what is unique about the early start and early finish date of each node on the critical path?
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
In the space provided below write a C ++ program that computes the total amount of...
In the space provided below write a C ++ program that computes the total amount of money you are depositing in your bank account. Your program does this by asking you to first enter the number and amount of each check you are depositing, and then it asks you to enter the type of cash bills being deposited and how many of each type, also the types of coins being deposited, and the number of each coin type.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT