Write a program to create a weighted graph. The user inputs how many vertices, how many edges, the starting and ending vertices, and weight of each edge, then print the adjacency matrix. For example, if the user wants to create such a graph, 1 3 The running process looks like this: >Enter the Number of Vertices: 4 Enter the Number of Edges: 4 Enter The Graph Egdes 1 24 1 3 1 1 43 245 The adjacency matrix for given graph is: 1 2 3 4 10 4 1 3 24 005 31 000 43500 Please note: in un-weighted graph, if the adjacency matrix is A, A[i][j]-1 means node i is connected to node j. A[i][j]-0 means node i is not connected to node j. In weighted graph, if the adjacency matrix is A, A[i][i]-k means node i is connected to node j and the weight of the edge

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 23PE
icon
Related questions
Question
100%

This is in java.

Write a program to create a weighted graph. The user inputs how many vertices, how many
edges,
the starting and ending vertices, and weight of each edge, then print the adjacency matrix. For
example, if the user wants to create such a graph,
4
1
3
The running process looks like this:
>Enter the Number of Vertices:
4
Enter the Number of Edges:
4
Enter The Graph Egdes <source> <destination> <weight>
1 24
1 31
1 4 3
2 4 5
The adjacency matrix for given graph is:
1 2 3 4
104 1 3
24 0 05
31 000
43500
Please note: in un-weighted graph, if the adjacency matrix is A, A[i][j]=1 means node i is
connected to node j. A[i][j]=0 means node i is not connected to node j. In weighted graph, if the
adjacency matrix is A, Afillil k means node i is connected to node j and the weight of the edge
is k. A[i][j]=0 means node i is not connected to node j.
Transcribed Image Text:Write a program to create a weighted graph. The user inputs how many vertices, how many edges, the starting and ending vertices, and weight of each edge, then print the adjacency matrix. For example, if the user wants to create such a graph, 4 1 3 The running process looks like this: >Enter the Number of Vertices: 4 Enter the Number of Edges: 4 Enter The Graph Egdes <source> <destination> <weight> 1 24 1 31 1 4 3 2 4 5 The adjacency matrix for given graph is: 1 2 3 4 104 1 3 24 0 05 31 000 43500 Please note: in un-weighted graph, if the adjacency matrix is A, A[i][j]=1 means node i is connected to node j. A[i][j]=0 means node i is not connected to node j. In weighted graph, if the adjacency matrix is A, Afillil k means node i is connected to node j and the weight of the edge is k. A[i][j]=0 means node i is not connected to node j.
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Polynomial time
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning