bartleby

Concept explainers

Question
Book Icon
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.

Blurred answer
Students 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
C+ Write a program that outputs the shortest distance from a given node to every other node in the graph. I NEED THESE HEADER FILES INCLUDED IN THE PROGRAM PLEASE These are the header files: graphType.h, linkedList.h, linkedQueue.h, queueADT.h, testProgGraph.cpp, unorderedLinkedList.h, weightedGraph.h
Explain this code by putting comments in detail. Language used is c++. Topic is Linkedlist   // void deleteByData(int data) {    //     if(head->data == data) {    //         head = head->next;    //     }     //     next = head;    //     Node *prev = next;    //     while (next != NULL) {    //         if (next->data == data) {    //             prev->next = prev->next->next;    //         }    //         prev = next;    //         next = next->next;    //     }    // }; };

Chapter 28 Solutions

Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition

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