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

Concept explainers

Question
Book Icon
Chapter 28, Problem 28.3PE
Program Plan Intro

Implement DFS using stack

Program Plan:

Exercise.java:

  • Import the required packages.
  • Create a class “Exercise”:
    • Define the main method
      • Define and declare the vertices.
      • Define and declare the edges.
      • New graph gets created.
      • Perform depth first search on the list.
      • Display the number of vertices present in the graph.
      • Loop that iterates to find the search orders.
      • Loop that iterates to display the parent node.
  • Define and create the class “UnweightedGraphWithNonrecursiveDFS”
    • Create a new constructor.
    • New graph gets using the constructor.
    • Method to create “cloneEdges” gets created.
      • New list gets created.
      • Loop that iterates to add the edges into the list.
      • Loop that iterates to add the neighbor edge into the list.
      • Neighbor copy gets created.
      • Return the neighbor copy.
    • Method to perform “searchTreedfs” is created
      • New list gets created.
      • Loop that iterates and defines the parent node.
      • New stack gets created.
      • Loop that validates the stack is empty or not.
      • Condition to validate the neighbor node gets created.
      • Validate and add the node into the list.
      • Determine the visited and unvisited node.
      • New search tree is returned.

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
(In Java language) Create a class Called NetflixDemo  Create two objects “user1” and “user2” of the Netflix class pictured below) Set various class variables for the Netflix class using these two objects. Call various methods of Netflix class using these two objects.   public class Netflix {public String movies [] = new String[10];public String trendingTop5 [] = new String[5];public String continueWatching [] = new String[5];public String username;public String password;private boolean isAuthenticated;public double balance;public int subscriberSinceYear;public static void logininfo() {Scanner input = new Scanner(System.in);System.out.println("Enter the username");String username = input.nextLine();System.out.println("Enter the password");String password = input.nextLine();boolean isAuthenticated = true;System.out.println(isAuthenticated + " , You have successfully logged in ");System.out.println();}public static void trendingList(){Scanner input = new…
Recursion Practice Welcome back! In this lab, we will be reviewing recursion by practicing with some basic recursion problems. Objectives Increase familiarity with recursive logic by working through several recursive problems. Taking into consideration a few corner cases through analyzing the test cases. Using a regex expression that will remove punctuation. Getting Started This lab includes the following .java file: L4/└── Recursion.java└── Main.java**Main.java is a read-only file used for testing. It is not included in the starter jar.Here is the starter jar if you would like to code in a different environment: L4.jar.   Please complete ALL functions. Make sure to read the description for each function carefully. Do not include any for or while loops in your methods. These can all be completed in a purely recursive style, so do it recursively! In the spirit of incremental development, implement each method one at a time, look at the test cases and take into consideration what is…
Name:- MIT Note:- Please type this java code and also need an output for this given Java program.

Chapter 28 Solutions

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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning