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
Question
Book Icon
Chapter 28, Problem 28.10PE
Program Plan Intro

Find the shortest path

Program Plan:

Exercise.java:

  • Import the required packages.
  • Create a class “Exercise”:
    • Define the main method
      • Prompt user to enter the file.
      • Validate whether the file exists or not.
      • Prompt user to enter the vertices.
      • Loop that read the contents of the file.
      • The token that are present in the file are removed.
      • Add the edges and vertices of the graph into the list.
      • New graph gets created
      • Perform the breadth first search for the graph.
      • Display the path of the graph.

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.

Edge.java

  • Create a class “Edge”
    • Define and declare the required variables.
    • Constructor gets defined.
    • Method that defines Boolean objects gets defined.
      • Return the value after validating the vertices.

Blurred answer
Students have asked these similar questions
What is the output of following code segment?
- Write a for loop with index i that iterates over all consecutive integers from 4 to 10 and prints the current loop index to screen for each value of i. As always, be careful with indentation and use proper python syntax. - Same question as above, but add a logical (if) statement inside the loop that prints both the loop index and the message "is greater than 6" or "is less than or equal to 6" for the appropriate indices. Hint, use the syntax print(i, "string") to print both the loop index and the string at the same time.
- Write a for loop with index i that iterates over all consecutive integers from 4 to 10 and prints the current loop index to screen for each value of i. As always, be careful with indentation and use proper python syntax. - Same question as above, but add a logical (if) statement inside the loop that prints both the loop index and the message "is greater than 6" or "is less than or equal to 6" for the appropriate indices. Hint, use the syntax print(i, "string") to print both the loop index and the string at the same time. - Write the same for loop as in the first question above, but modify it to only print the loop index when i is not equal to 8.

Chapter 28 Solutions

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

Knowledge Booster
Background pattern image
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