Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
bartleby

Videos

Textbook Question
Book Icon
Chapter 29, Problem 29.9PE

(Find a minimum spanning tree) Write a program that reads a connected graph from a file and displays its minimum spanning tree. The first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled as 0,1,..., n-1. Each subsequent line describes the edges in the form of u1, v1  w1 | u2, v2, w2 |…. Each triplet in this form describes an edge and its weight. Figure 29.23 shows an example of the file for the corresponding graph. Note we assume the graph is undirected. If the graph has an edge (u, v), it also has an edge (v, u). Only one edge is represented in the file. When you construct a graph, both edges need to be added.

FIGURE 29.23 The vertices and edges of a weighted graph can be stored in a file.

Chapter 29, Problem 29.9PE, (Find a minimum spanning tree) Write a program that reads a connected graph from a file and displays , example  1

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  Chapter 29, Problem 29.9PE, (Find a minimum spanning tree) Write a program that reads a connected graph from a file and displays , example  2

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)

Blurred answer
Students have asked these similar questions
Hands-On Assignments Part II Assignment 1-5: Querying the DoGood Donor Database Review the DoGood Donor data by writing and running SQL statements to perform the following tasks: 1. List each donor who has made a pledge and indicated a single lump sum payment. Include first name, last name, pledge date, and pledge amount. 2. List each donor who has made a pledge and indicated monthly payments over one year. Include first name, last name, pledge date, and pledge amount. Also, display the monthly payment amount. (Equal monthly payments are made for all pledges paid in monthly payments.) 3. Display an unduplicated list of projects (ID and name) that have pledges committed. Don't display all projects defined; list only those that have pledges assigned. 4. Display the number of pledges made by each donor. Include the donor ID, first name, last name, and number of pledges. 5. Display all pledges made before March 8, 2012. Include all column data from the DD PLEDGE table.
Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.java is provided with method stubs. Follow each step to gradually complete all methods. Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() method includes basic method calls. Add statements in main() as methods are completed to support development mode testing. Step 0. Declare private fields for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (String). Note the provided final variable indicates the gas tank capacity of 14.0 gallons. Step 1 (2 pts). 1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2)…
Find the error: daily_sales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday',                     'Wednesday', 'Thursday', 'Friday',                     'Saturday'] for i in range(7):         daily_sales[i] = float(input('Enter the sales for ' \                                      + day_of_week[i] + ': ')

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Explain why the parameter of a copy constructor must be a reference.

Starting Out with C++: Early Objects (9th Edition)

Look at the following classes: public class Ground { public Ground() { System.out.println(You are on the ground...

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Program to find HCF & LCM of two numbers in C | #6 Coding Bytes; Author: FACE Prep;https://www.youtube.com/watch?v=mZA3cdalYN4;License: Standard YouTube License, CC-BY