Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 28, Problem 28.19PE
Program Plan Intro
Display a DFS/BFS tree in a graph
Program Plan:
Exercise.java:
- Import the required packages.
- Create a class “Exercise”:
- Create a text field.
- Create the required buttons.
- Create the label.
- City values vertices gets assigned.
- City value edges get assigned.
- New graph gets created.
- New view gets defined
- Define the start method:
- Create a new border pane.
- New hbox gets created.
- Add the buttons into the pane.
- Set the alignment of the pane.
- New scene gets created
- Set the title of the scene.
- Scene gets placed on the stage.
- The stage gets displayed.
- Action event for the button defined is set.
- Based on the action defined a new tree is defined.
- Define the main method
- Initialize the calls.
- Class “GraphView” gets defined
- Assign the graph.
- Assign the tree
- Define the method “GraphView”
- Assign the graph.
- Define the method “setTree”
- Assign the tree
- Define the method “repaint()”
- Clear the pane.
- Loop that iterates to draw the vertices
- Get the position of x and y coordinates.
- Condition to validate the edge gets defined.
- Loop that iterates to draw the line.
- Define the method “drawArrowLine”
- New lines get created.
- Add the line color.
- Calculate the angle.
- Set the angle.
- Condition to validate the arrow point gets defined.
- Draw the arrow at the required positions.
- Define the class “city”
- Declare the required variables.
- Assign the x and y value.
- Get the name.
- Validate the city name that is entered.
UnweightedGraph.java:
- Import the required packages.
- Create a class “UnweightedGraph”:
- New list for the vertices gets created.
- New list for the neighbor node gets created.
- Create an empty constructor.
- Method to create new graph gets created and adjacency list gets created.
- Method to create an adjacency list gets created.
- Method to return the size of the vertices.
- Method to return the index of the vertices gets defined.
- Method to gets the neighbor node gets defined.
- Method to return the degree of the vertices gets created.
- Method to print the Edges gets created.
- New to clear the graph gets created.
- Method to add vertex gets created.
- Method to add edge gets created.
- Method to perform the depth first search gets defined.
- Method to perform breadth first search gets defined.
- Search tree gets returned.
- Create a class “SearchTree”
- Define the method to return the root.
- Method to return the parent of the vertices
- Method to return the search order gets defined.
- Method to return the number of vertices found gets defined.
- Method to get the path of the vertices gets defined.
- Loop to validate the path gets defined.
- Path gets returned.
- Method to print the path gets defined.
- Method to print the tree gets defined.
- Display the edge.
- Display the root.
- Condition to validate the parent node to display the vertices gets created.
Graph.java:
- A graph interface gets created.
- Method to return the size gets defined.
- Method to return the vertices gets defined.
- Method to return the index gets created.
- Method to get the neighbor node gets created.
- Method to get the degree gets created.
- Method to print the edges.
- Method to clear the node gets created.
- Method to add the edges, add vertex gets created.
- Method to remove the vertices gets defined.
- Method for the depth first search gets defined.
- Method for the breadth first search gets defined.
Displayable.java
- Define the interface.
- Get the x value
- Get the y value.
- Get the name.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Help in C++ please:
Write a program (in main.cpp) that:
Prompts the user for a filename containing node data.
Outputs the minimal spanning tree for a given graph.
You will need to implement the createSpanningGraph method in minimalSpanTreeType.h to create the graph and the weight matrix.
There are a few tabs:
main.cpp, graphType.h, linkedList.h, linkedQueue.h, queueADT.h, minimalSpanTreeType.h, and then two data files labeled: CH20_Ex21Data.txt, CH20Ex4Data.txt
Can you help me with a C++ programming task I am trying to complete for myself please:
Write a program (in main.cpp) that:
Prompts the user for a filename containing node data.
Outputs the minimal spanning tree for a given graph.
You will need to implement the createSpanningGraph method in minimalSpanTreeType.h to create the graph and the weight matrix.
There are a few tabs:
main.cpp, graphType.h, linkedList.h, linkedQueue.h, queueADT.h, minimalSpanTreeType.h, and then two data files labeled: CH20_Ex21Data.txt, CH20Ex4Data.txt
In C++, write a program that outputs the nodes of a graph in a breadth first traversal.
Data File: Please use this data file.
Text to copy:
100 1 3 -9991 4 -9992 5 -9993 2 -9994 -9995 7 8 -9996 4 7 -9997 -9998 -9999 7 8 -999
Diagram: Also, please take a look at the attached figure on and calculate the weights for the following edges:
0 -> 1 -> 4
0 -> 3 -> 2 -> 5 -> 7
0 -> 3 -> 2 -> 5 -> 8
6 -> 4
6 -> 7
9 -> 7
9 -> 8
To calculates these weights, please assume the following data:
0 -> 1 = 1
0 -> 3 = 2
1 -> 4 = 3
3 -> 2 = 4
2 -> 5 = 5
5 -> 7 = 6
5 -> 8 = 7
6 -> 4 = 8
6 -> 7 = 9
9 -> 7 = 10
9 -> 8 = 11
Chapter 28 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 28.2 - What is the famous Seven Bridges of Knigsberg...Ch. 28.2 - Prob. 28.2.2CPCh. 28.2 - Prob. 28.2.3CPCh. 28.2 - Prob. 28.2.4CPCh. 28.3 - Prob. 28.3.1CPCh. 28.3 - Prob. 28.3.2CPCh. 28.4 - Prob. 28.4.1CPCh. 28.4 - Prob. 28.4.2CPCh. 28.4 - Show the output of the following code: public...Ch. 28.4 - Prob. 28.4.4CP
Ch. 28.5 - Prob. 28.5.2CPCh. 28.6 - Prob. 28.6.1CPCh. 28.6 - Prob. 28.6.2CPCh. 28.7 - Prob. 28.7.1CPCh. 28.7 - Prob. 28.7.2CPCh. 28.7 - Prob. 28.7.3CPCh. 28.7 - Prob. 28.7.4CPCh. 28.7 - Prob. 28.7.5CPCh. 28.8 - Prob. 28.8.1CPCh. 28.8 - When you click the mouse inside a circle, does the...Ch. 28.8 - Prob. 28.8.3CPCh. 28.9 - Prob. 28.9.1CPCh. 28.9 - Prob. 28.9.2CPCh. 28.9 - Prob. 28.9.3CPCh. 28.9 - Prob. 28.9.4CPCh. 28.10 - Prob. 28.10.1CPCh. 28.10 - Prob. 28.10.2CPCh. 28.10 - Prob. 28.10.3CPCh. 28.10 - If lines 26 and 27 are swapped in Listing 28.13,...Ch. 28 - Prob. 28.1PECh. 28 - (Create a file for a graph) Modify Listing 28.2,...Ch. 28 - Prob. 28.3PECh. 28 - Prob. 28.4PECh. 28 - (Detect cycles) Define a new class named...Ch. 28 - Prob. 28.7PECh. 28 - Prob. 28.8PECh. 28 - Prob. 28.9PECh. 28 - Prob. 28.10PECh. 28 - (Revise Listing 28.14, NineTail.java) The program...Ch. 28 - (Variation of the nine tails problem) In the nine...Ch. 28 - (4 4 16 tails problem) Listing 28.14,...Ch. 28 - (4 4 16 tails analysis) The nine tails problem in...Ch. 28 - (4 4 16 tails GUI) Rewrite Programming Exercise...Ch. 28 - Prob. 28.16PECh. 28 - Prob. 28.17PECh. 28 - Prob. 28.19PECh. 28 - (Display a graph) Write a program that reads a...Ch. 28 - Prob. 28.21PECh. 28 - Prob. 28.22PECh. 28 - (Connected rectangles) Listing 28.10,...Ch. 28 - Prob. 28.24PECh. 28 - (Implement remove(V v)) Modify Listing 28.4,...Ch. 28 - (Implement remove(int u, int v)) Modify Listing...
Knowledge Booster
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
- please complete the following in JAVA Implement the graph ADT using the adjacency list structure. thanks! also posting a similar question for adjacency matrix. have a good day!arrow_forwardProgramming language: Java Topic: linked listarrow_forwardProvide full C++ code for main.cpp, playlist.h and playlist.cpp Building a playlist (of songs) using a linked list and making some operations such as adding songs, removing songs, shuffling them, etc. (Some parts of this lab will closely follow lab 08 - it is imperative that you complete that lab before working on this project). A Node representing a song has the following data members (similar to struct Node of lab 08, except it doesn't have one member for storing data): string uniqueID string songName string artistName int songLength Node* nextNodePtr Your code must have the following three files: Playlist.h - Class declaration for a linked list of Nodes (very similar to lab 08 but with some changes to methods, as described below) with following private data members: private:Node* first;Node* last;int size; Playlist.cpp - Class definition main.cpp - main() function Checkpoint A For checkpoint A, you need to build a playlist (of songs) by readings data members of several songs…arrow_forward
- unique please Your task for this assignment is to identify a spanning tree in one connected undirected weighted graph using C++. Implement a spanning tree algorithm using C++. A spanning tree is a subset of the edges of a connected undirected weighted graph that connects all the vertices together, without any cycles. The program is interactive. Graph edges with respective weights (i.e., v1 v2 w) are entered at the command line and results are displayed on the console. Each input transaction represents an undirected edge of a connected weighted graph. The edge consists of two unequal non-negative integers in the range 0 to 9 representing graph vertices that the edge connects. Each edge has an assigned weight. The edge weight is a positive integer in the range 1 to 99. The three integers on each input transaction are separated by space. An input transaction containing the string “end-of-file” signals the end of the graph edge input. After the edge information is read, the process…arrow_forwardStudy the scenario and comple the question(s) thatb follows: Convert Strings to Pig Latin using a linked list PigLatinStrings converts a string into a Pig Latin, but it processes only one word. If a word ends with a panctuation mark in the Pig Latin form,put the punctuation at the end of the string. For example: "Hello!" becomes "ello-Hay!" Write a program that prompts the user to input a string and then outputs the string in Pig Latin. Create the program using a Linked List(C++). a. Build a linked list as template either forwards or backwards.b. The linked list should have a function that prints the linked list. This function should be a recursive function.c. Your program must store the characters of a string into a linked list and use the function Rotate to remove the first node of the linked list and put it at the end of the linked list.arrow_forwardMissing Brackets Checking: Write a technique to find on the off chance that an articulation has missing sections or not utilizing StackLinkedList. The technique takes a String articulation as a boundary and return True on the off chance that the articulation's sections are right and Falsearrow_forward
- Java Programming language Please help me with this. Thanks in advance.arrow_forwardC-Language. Stacks or Trees. I am having issues with this program. I am trying to achieve this currently by using a stack in the C language. But I have reached a lull.arrow_forwardTask 3: Is the viewing transformation True or False Prove your answer with a drawing (Draw modeling transformations or show the stack data). glutLookAt( 30.0, 0.0, 30.0, 0.0, 0.0, 0.0, 1.0, 0.0, -1.0) equivalent to the sequence gl Rotatef(90, 0.0, 0.0, 1.0) gIRotatef(45, 0.0, -1.0, 0.0 ) glTraslatef(-30.0, 0.0, -30.0)arrow_forward
- .Define request edge and assignment edge.arrow_forwardLinked List, create your own code. (Do not use the build in function or classes of Java or from the textbook). Create a LinkedList class: Call the class MyLinkedList, (hint) Create a second class called Node.java and use it, remember in the class I put the Node class inside the LinkedList Class, but you should do it outside. This class should haveo Variables you may need for a Node,o (optional) Constructor Your linked list is of an int type. (you may do it as General type as <E>) For this Linked List you need to have the following methods: add, addAfter, remove, size, contain, toString, compare, addInOrder. This is just a suggestion, if you use Generic type, you must modify this Write a main function or Main class to test all the methods,o Create a 2 linked list and test all your methods. (Including the compare)arrow_forwardLinked List, create your own code. (Do not use the build in function or classes of Java or from the textbook). Create a LinkedList class: Call the class MyLinkedList, (hint) Create a second class called Node.java and use it, remember in the class I put the Node class inside the LinkedList Class, but you should do it outside. This class should haveo Variables you may need for a Node,o (optional) Constructor Your linked list is of an int type. (you may do it as General type as <E>) For this Linked List you need to have the following methods: add, addAfter, remove, size, contain, toString, compare, addInOrder. This is just a suggestion, if you use Generic type, you must modify this Write a main function or Main class to test all the methods,o Create a 2 linked list and test all your methods. (Including the compare)arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education