(Find a minimum spanning tree) Write a
FIGURE 29.23 The vertices and edges of a weighted graph can be stored in a file.
Your program should prompt the user to enter a URL for the file, read data from the file, create an instance g of WeightedGraph, invoke g.printWeightedEdges() to display all edges, invoke getMinimumSpanningTree() to obtain an instance tree of WeightedGraph.MST, invoke tree.getTotalWeight() to display the weight of the minimum spanning tree, and invoke tree.printTree() to display the tree. Here is a sample run of the program:
Enter a URL:
https://liveexample.pearsoncmg.com/test/WeightedGraphSample.txt
The number of vertices is 6
Vertex 0: (0, 2, 3) (0, 1, 100)
Vertex 1: (1, 3, 20) (1, 0, 100)
Vertex 2: (2, 4, 2) (2, 3, 40) (2, 0, 3)
Vertex 3: (3, 4, 5) (3, 5, 5) (3, 1, 20) (3, 2, 40)
Vertex 4: (4, 2, 2) (4, 3, 5) (4, 5, 9)
Vertex 5: (5, 3, 5) (5, 4, 9)
Total weight in MST is 35
Root is: 0
Edges: (3, 1) (0, 2) (4, 3) (2, 4) (3, 5)
Want to see the full answer?
Check out a sample textbook solutionChapter 29 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Mechanics of Materials (10th Edition)
Starting Out with Python (4th Edition)
- :Write some statements that display a list of integers from 10 to 20 inclusive ,each with its square root next to it. Write a single statement to find and display the sum of the successive even integers 2, 4, ..., 200. (Answer: 10 100) Ten students in a class write a test. The marks are out of 10. All the marks are entered in a MATLAB vector marks. Write a statement to find and display the average mark. Try it on the following marks: 580 10 3 85794 (Answer: 5.9)arrow_forwardIn c++ Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, th backwards End each loop with a newline. Ex If courseGrades (7, 9, 11, 10), print: 7 9 11 10 10 11 9 7 Hint Use two for loops. Second loop starts with i=NUM VALS-1. (Notes) Note: These activities may test code with different test values. This activity will perform two tests, both with a 4-element array (int courseGrades(4) See 'How to Use zyBooks Also note: If the submitted code tries to access an invalid array element, such as courseGrades[9] for a 4-element array, the test may generate strange results. Or the test may crash and report "Program end never reached", in which case the system doesn't print the test case that caused the reported message 32344345730rity? 2 using namespace std; 3 4 int main() { 5 6 7 8 9 10 11 12 13 14 const int NUM VALS-4; int courseGrades [NUM VALS]; int i; for (i = 0; i > courseGrades[1]; } y Your solution goes here Yarrow_forwarda) Write a program that asks user to enter number of vertices in a directed graph and thenthe adjacency matrix representing the directed graph. The program, then, must display thenode with the highest outdegree. Assume that nodes are named as 0, 1, 2 and so on.arrow_forward
- display a rectangle of a given width and height, such as **** Write a single for loop that displays the same rectangle.arrow_forward*Please help in javascript* Summary: Given integer values for red, green, and blue, subtract the gray from each value. Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255. Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the (50, 50, 50) gray part. (In other words, equal amounts of red, green, blue yield gray). Given values for red, green, and blue, remove the gray part. Ex: If the input is: 130 50 130 the output is: 80 0 80 import java.util.Scanner; public class LabProgram {public static void main(String[] args) {/* Type your code here. */}}arrow_forwarddont post copied answers posting multiple times sure dislikearrow_forward
- LO: (Remember) Students will recall how to read from standard input. LO: (Apply) Students will write loops that iterate as long as a condition is true. Write a program that reads words from standard input and displays them to standard output. When the word "end" is read, print it out and then stop reading input. Full Screen * maln.cpp New #include 2 using namespace std; 1 3 4- /* 5 * Reads and displays words from standard input until hitting a stop word. 6 */ 7- int main() { 8 9. 10 return 0; 11 annarrow_forwardMatrix Multiplication with OpenMPWrite a program that calculates the product of two matrices, using a parallel for loop. Note that this requires writing a triply-nested for loop, and making one of the for loops parallel.arrow_forwardcoding language c++arrow_forward
- 7. a) Write down the 5 by 5 adjacency matrix for the undirected graph below (Figure 1). A C E B D Figure 1: Undirected Graph for Question 7. (a) b) Write a program that asks a user to enter the number of vertices in an undirected graph and then the adjacency matrix representing the undirected graph. The program, then, must display the number of edges in the given graph. You will find a sample run of the program below. Enter number of vertices: 3 Enter adjacency matrix: 0 1 1 1 0 0 1 0 0 Total number of edges: 2arrow_forwardQ1) A vector is given by x = [7,19,2,14,5,12,4,18,6,13]. Using conditional statements and loops, write a program that creates two vectors from xone (call it N) that contains the number of odd values and their average, and a second (call it T) that contains the number of even values and their median.arrow_forwardcan you give me the code to the folloowing?arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning