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.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 the main method
- 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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)
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
- - Do not add any imports, the ones that you need will be given to you.- Do not use recursion.- Do not use break/continue.- Do not use try-except statements, you should be able to anticipateor prevent any errors from happening at all!arrow_forwardPublic Class Utilities { replaceCharacter Method public static void replaceCharacter(char[] array, char target, char replacement) Replaces the target character in the array with the specified replacement. You can assume the array parameter will not be null. You may only use one auxiliary method. Your implementation must be recursive and you may not use any loop construct. Do not use ++ or -- in any recursive call argument. For example, use index + 1, instead of index++. Parameters: array - target - replacement -arrow_forwardplease help me with the following 1) make a sierpenski triangle using java and recursion. Make it similar to the code below. And please comment the code 2) Please make the follow code out put on the console. It a t square fractal import java.awt.image.*;import java.awt.Color;import java.io.*;import javax.imageio.*; public class Main{ static final int DIMENSION = 1000; static BufferedImage image = new BufferedImage(DIMENSION, DIMENSION, BufferedImage.TYPE_INT_RGB); static final int WHITE = Color.WHITE.getRGB(); static final int BLACK = Color.BLACK.getRGB(); private static void drawSquare(int x, int y, int side) { if (side <= 0) return; else { int left = x - side/2; int top = y - side/2; int right = x + side/2; int bottom = y + side/2; for (int i = left; i < right; i++) for (int j = top; j < bottom; j++) { image.setRGB(i, j, BLACK); }…arrow_forward
- Exercise 4 (class Ackermann) The Ackermann recursive function is defined as follows: n +1 А(т - 1,1) A(m – 1, A(m, n – 1)) if m> 0 and n > 0. if m %3D А(т, п) — if m > 0 and n = 0 Its arguments are never negative and it always terminates. Write a Java method which returns the value of A(m,n). Write the following code fragment inside the main method to test Ackermann function and report what will happen. for (m = 0; m <= 4; m++) for (n = 0; n < 6 - m; n++) System.out.printf("A(%d, %d) = %d\n", m, n, ackermann(m, n));arrow_forwarddef winning_card(cards, trump=None): Playing cards are again represented as tuples of (rank,suit) as in the cardproblems.pylecture example program. In trick taking games such as whist or bridge, four players each play one card from their hand to the trick, committing to their play in clockwise order starting from the player who plays first into the trick. The winner of the trick is determined by the following rules:1. If one or more cards of the trump suit have been played to the trick, the trick is won by the highest ranking trump card, regardless of the other cards played.2. If no trump cards have been played to the trick, the trick is won by the highest card of the suit of the first card played to the trick. Cards of any other suits, regardless of their rank, are powerless to win that trick.3. Ace is the highest card in each suit.Note that the order in which the cards are played to the trick greatly affects the outcome of that trick, since the first card played in the trick…arrow_forwardPlease use java and not use arrays The purpose of this assignment is to practice OOP with Fundamental of Data Type, Constructing Objects and Classes, Decisions, Loops. Introduction: In English vocabulary there are many interesting and meaningful phenomena, such as isogram, pangram, malapropisms, anagram, palindrome, etc., which leave a “room” for language-learners to enthusiastically discover secret, surprise, and something different instead of negatively listing words. They make the boring vocabulary lesson an interactive practical course that helps to grasp interest of students as English language-learners.1 Some of these interesting linguistic phenomena2 are: Isogram: referred to a word, phrase, or sentence in which no letter of the alphabet occurs more than once. For example; the words “ambidextrously”, “endolymphatic”, and “unpredictably”. Pangram: A phrase or sentence containing all 26 letters of the alphabet (ideally repeating as few letters as possible). For example; the…arrow_forward
- 19- java. Which of the following is a drawback of using recursion? It may be less efficient than an iterative version. It may have fewer lines of code than an iterative version. It uses lesser memory stack than an iterative version. It runs faster than an iterative version.arrow_forwardWrite the full Java Code for LabProgram.javaarrow_forward(a) Write a method public static void insert(int[] a, int n, int x) that inserts x in order among the first n elements of a, assuming these elements are arranged in ascending order. Do NOT use arraylists. x is the last element in a. n does not include x. (b) Using the insert method from Part (a), write a recursive implementation of Insertion Sort.arrow_forward
- Use Python for this question. Also please comment what each line of code means for this question as well: Inheritance (based on 8.38) You MUST use inheritance for this problem. A stack is a sequence container type that, like a queue, supports very restrictive access methods: all insertions and removals are from one end of the stack, typically referred to as the top of the stack. A stack is often referred to as a last-in first-out (LIFO) container because the last item inserted is the first removed. Implement a Stack class using Note that this means you may be able to inherit some of the methods below. Which ones? (Try not writing those and see if it works!) Constructor/_init__ - Can construct either an empty stack, or initialized with a list of items, the first item is at the bottom, the last is at the top. push() – take an item as input and push it on the top of the stack pop() – remove and return the item at the top of the stack isEmpty() – returns True if the stack is empty,…arrow_forwardC. Using the starter code please modify in Java public class L08 { public static void main(String[] args) { // TO DO: // Test your radix sort implementation here } // TO DO: // Implement // NOTE: You can assume that all strings in the array have the same length public static void radixSort(String[] array) { } //////* HELPER METHODS *////// private static String[] generateStringArray(int wordLen, int arrLen) { String[] array = new String[arrLen]; for(int i = 0; i < arrLen; i++) { StringBuilder sb = new StringBuilder(); for(int j = 0; j < wordLen; j++) { sb.append((char)('a' + Math.random() * ('z' - 'a' + 1))); } array[i] = sb.toString(); } return array; } private static void displayStringArray (String[] array) { for(String s : array) { System.out.println(s); } } private static boolean isSortedInNondescendingOrder(String[] array) { for(int i = 1; i < array.length; i++) { if (array[i].compareTo(array[i-1]) < 0) { return false; } } return true; } } Implement radix sort for…arrow_forwardPythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning