Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
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
a) Write a program that asks user to enter number of vertices in a directed graph and then the adjacency matrix representing the directed graph. The program, then, must display the node with the highest outdegree. Assume that nodes are named as 0, 1, 2 and so on. You will find a sample run of the program below. Enter number of vertices: 4 Enter adjacency matrix: 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 Node with the highest outdegree: 0
C++ Coding: Arrays Implement a 4x4 two-dimensional array of integers. Use a nested loop to populate the array with values 20 to 35 inclusive. Use a nested loop to output the array as a grid. Use a single loop to output all elements in the second row. Use a single loop to output all elements in the third column. Use a single loop to output all elements in the first diagonal (r==c). Use a single loop to output all elements in the opposing diagonal. Example Output: 20 21 22 2324 25 26 2728 29 30 3132 33 34 35Row 2: 24 25 26 27Col 3: 22 26 30 34Diagonal 1: 20 25 30 35Diagonal 2: 23 26 29 32
[Fish Tank] You play with a clown fish that has an initial size so. The fish can eat other fish in a tank organized in m columns and n rows. The fish at column i and row j has a positive size si,j. When your fish eats another fish, it grows by that amount. For example, if your clown fish has a size of 10 and eats a fish of size 5, it becomes of size 15. You cannot eat a fish that is bigger than your size. The game starts by eating any fish in the first (left-most) column that is not bigger than yours. After that, you advance one column at a time by moving right. You have only three allowed moves. You either stay at the same row, move one row higher or one row lower. You will always move to the right. Thus, you will make exactly m moves to advance from left to right. Your goal is to exit the fish tank from the right with the biggest possible size. The figure below shows an example with the best answer highlighted. In this case, the final fish size is 71 (10+8+7+24+22). You are required…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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