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
Question
Chapter 25, Problem 25.9PE
Program Plan Intro
Program Plan:
- Include the required import statement.
- Define the main class.
- Define the main method using public static main.
- Allocate memory to the class “Test”.
- Define the “Test” class.
- Declare the object for the BST.
- Insert the values into the tree.
- Call the “postorder” method.
- The try-catch block is used to get the input from the user and do the postorder traversal.
- Display the output.
- Define the “BST” class.
- Declare the required variables.
- Create a default BST class.
- Define the “clone” method.
- Create an object for the “BST” class.
- Call the “copy” method with the argument.
- Return the tree.
- Define the “copy” method.
- If the “s” is not null, insert the element into the tree.
- Copy the “t” value into left and right subtrees.
- If the “s” is not null, insert the element into the tree.
- Define the “equals” method.
- Create the object for the array list.
- Call the “toArray” method.
- Return the two array.
- Define the ArrayList of “getElementInorder” method
- Create the object for the array list.
- Call the “getElementInorder” method.
- Return the list.
- Define the “getElementInorder” method.
- If the “root” is equal to null, return the value.
- Call the “getElementInorder” method.
- Add the element into the list.
- Call the “getElementInorder” method.
- Create a binary tree from an array of objects.
- Define the “search” method.
- Start the traverse from the root of the tree.
- If the search element is in the left subtree set that value in “current” variable otherwise set the “current” variable as right subtree value.
- Define the “insert” method.
- If the root is null create the tree otherwise insert the value into left or right subtree.
- Define the “createNewNode”
- Return the result of new node creations.
- Define the “inorder”
- Inorder traverse from the root.
- Define the protected “inorder” method
- Traverse the tree according to the inorder traversal concept.
- Define the “postorder”
- Postorder traverse from the root.
- Define the protected “postorder” method
- Traverse the tree according to the postorder traversal concept.
- Define the “preorder”
- Preorder traverse from the root.
- Define the protected “preorder” method
- Traverse the tree according to the preorder traversal concept.
- Define the “TreeNode” class
- Declare the required variables.
- Define the constructor.
- Define the “getSize” method.
- Return the size.
- Define the “getRoot” method
- Return the root.
- Define the “java.util.ArrayList” method.
- Create an object for the array list.
- If the “current” is not equal to null, add the value to the list.
- If the “current” is less than 0, set the “current” as left subtree element otherwise set the “current” as right subtree element.
- Return the list.
- Define the “delete” method.
- If the “current” is not equal to null, add the value to the list.
- If the “current” is less than 0, delete the “current” as left subtree element otherwise delete the “current” as right subtree element.
- Return the list.
- Define the “iterator” method.
- Call the “inorderIterator” and return the value.
- Define the “inorderIterator”
- Create an object for that method and return the value
- Define the “inorderIterator” class.
- Declare the variables.
- Define the constructor.
- Call the “inorder” method.
- Define the “inorder” method.
- Call the inner “inorder” method with the argument.
- Define the TreeNode “inorder” method.
- If the root value is null return the value, otherwise add the value into the list.
- Define the “hasNext” method
- If the “current” value is less than size of the list return true otherwise return false.
- Define the “next” method
- Return the list.
- Define the “remove” method.
- Call the delete method.
- Clear the list then call the “inorder” method.
- Define the “clear” method
- Set the values to the variables
- Define the interface.
- Declare the required methods.
- Define the required methods.
- Define the main method using public static main.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Test perfect binary tree)
A perfect binary tree is a complete binary tree with all levels fully filled. Define a
new class named BSTWithTestPerfect that extends BST with the
following methods: (Hint: The number of nodes in a perfect binary tree is
2^(height+1) - 1.)
/** Returns true if the tree is a perfect binary tree
*/
public boolean isPerfectBST()
Use https://liveexample.pearsoncmg.com/test/Exercise25_03.txt to test your
code.
Class Name: Exercise25 03
(Test perfect binary tree) JAVA
A perfect binary tree is a complete binary tree with all levels fully filled. Define a new class named BSTWithTestPerfect that extends BST with the following methods: (Hint: The number of nodes in a perfect binary tree is 2^(height+1) - 1.)
/** Returns true if the tree is a perfect binary tree */public boolean isPerfectBST()
Use https://liveexample.pearsoncmg.com/test/Exercise25_03.txt to test your code.
Class Name: Exercise25_03
(Please Help. My professor did not teach us any of this and will not answer my emails)
Design a class named Queue for storing integers. Like a stack, a queue holds elements. In a stack, the elements are retreived in a last-in-first-out fashion. In a queue, the elements are retrieved in a first-in-first-out fashion. The class contains:
An int[] data field named elements that stores the int values in the queue
A data field named size that stores the number of elements in the queue
A constructor that creates a Queue object with defult capacity 8
The method enqueue(int v) that adds v into the queue
The method empty () that returns true if the queue is empty
The method getSize() that returns the size of the queue
Chapter 25 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 25.2 - Prob. 25.2.1CPCh. 25.2 - Prob. 25.2.2CPCh. 25.2 - Prob. 25.2.3CPCh. 25.2 - Prob. 25.2.4CPCh. 25.2 - Prob. 25.2.5CPCh. 25.3 - Prob. 25.3.1CPCh. 25.3 - Prob. 25.3.2CPCh. 25.3 - Prob. 25.3.3CPCh. 25.3 - Prob. 25.3.4CPCh. 25.4 - Prob. 25.4.1CP
Ch. 25.4 - Prob. 25.4.2CPCh. 25.4 - Prob. 25.4.3CPCh. 25.4 - Prob. 25.4.4CPCh. 25.4 - Prob. 25.4.5CPCh. 25.5 - Prob. 25.5.1CPCh. 25.5 - Prob. 25.5.2CPCh. 25.5 - Prob. 25.5.3CPCh. 25.5 - Prob. 25.5.4CPCh. 25.5 - Prob. 25.5.5CPCh. 25.6 - Prob. 25.6.1CPCh. 25.6 - Prob. 25.6.2CPCh. 25.6 - Prob. 25.6.3CPCh. 25.6 - How do you replace lines 9499 in Listing 25.11...Ch. 25 - Prob. 25.1PECh. 25 - (Implement inorder traversal without using...Ch. 25 - (Implement preorder traversal without using...Ch. 25 - (Implement postorder traversal without using...Ch. 25 - Prob. 25.6PECh. 25 - Prob. 25.7PECh. 25 - (Implement bidirectional iterator) The...Ch. 25 - Prob. 25.9PECh. 25 - Prob. 25.10PECh. 25 - Prob. 25.11PECh. 25 - (Test BST) Design and write a complete test...Ch. 25 - (Modify BST using Comparator) Revise BST in...Ch. 25 - Prob. 25.15PECh. 25 - (Data compression: Huffman coding) Write a program...Ch. 25 - Prob. 25.17PECh. 25 - (Compress a file) Write a program that compresses...Ch. 25 - (Decompress a file) The preceding exercise...
Knowledge Booster
Similar questions
- JAVA CODE Learning Objectives: Detailed understanding of the linked list and its implementation. Practice with inorder sorting. Practice with use of Java exceptions. Practice use of generics. You have been provided with java code for SomeList<T> class. This code is for a general linked list implementation where the elements are not ordered. For this assignment you will modify the code provided to create a SortedList<T> class that will maintain elements in a linked list in ascending order and allow the removal of objects from both the front and back. You will be required to add methods for inserting an object in order (InsertInorder) and removing an object from the front or back. You will write a test program, ListTest, that inserts 25 random integers, between 0 and 100, into the linked list resulting in an in-order list. Your code to remove an object must include the exception NoSuchElementException. Demonstrate your code by displaying the ordered linked list and…arrow_forwardTopic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. (See attached photo for reference) void isEmpty() This method will return true if the linked list is empty, otherwise return false. void clear() This method will empty your linked list. Effectively, this should and already has been called in your destructor (i.e., the ~LinkedList() method) so that it will deallocate the nodes created first before deallocating the linked list itself.arrow_forwardC++ pleasearrow_forward
- Computer Science JAVA Write a program that maintains the names of your friends and relatives and thus serves as a friends list. You should be able to enter, delete, modify, or search this data. You should assume that the names are unique. use a class to represent the names in the friends list and another class to represent the friends list itself. This class should contain a Binary Search Tree of names as a data field. (TreeNode Class BinarySearchTree Class FriendsList Class)arrow_forwardTopic: Singly Linked ListImplement the following functions in C++ program. Read the question carefully. (See attached photo for reference) int count(int num) This will return the count of the instances of the element num in the list. In the linked list in removeAll method, having the method count(10) will return 3 as there are three 10's in the linked list. Additionally, you are to implement these methods: bool move(int pos1, int pos2) This method will move the element at position pos1 to the position specified as pos2 and will return true if the move is successful. This will return false if either the specified positions is invalid. In the example stated, operating the method move(1, 3) will move the 1st element and shall now become the 3rd element. The linked list shall now look like: 30 -> 40 -> 10 -> 50 int removeTail() This method will remove the last element in your linked list and return the said element. If the list is empty, return 0. You can use the…arrow_forwardContext: This code is for a binary search tree and there's no inputarrow_forward
- Course: Data Structure and Algorithms Language: Java Kindly Answer in 1 hour. Read Carefully and give answer with all necesary details. Check the image also. Question7: Write a java/c++ code or an algorithm to solve the following problem. After that dry run and show output of algorithm using an example binary tree. Without dry run I will not accept. Write a recursive function/algorithm that finds the minimum value node from a Binary tree. (Caution: This is a simple binary tree not binary search tree i.e; tree is not in any order. So minimum node may be anywhere in tree.)arrow_forwardUse java or python to solve Note: 1) Assume that the Node class and Linked Lists constructors are already written. You ONLY need to write the revinsert0 method/function 2) No need to write the Tester Class. 3) Use of Built in Method is not allowed except count(). You must take an inplace approach and modify the given list. 5) You cannot use arrays to solve this problemarrow_forwardkindly don't copy the code from other websites because it's incorrect.. Thanks Linked Lists C Programming : Develop a Student Information System. The system need to implement the insertNode(), deleteNode() and displayList() functions. The insertNode() function is used to insert a new node of student record to the linked list. Assume that the input id is always unique, thus the linked list shall contain the student records with their respective id numbers are in ascending order. The displayList() function is used to display the list after inserting new node and/or after deleting a node. Please refer to the given structure definition shown in Figure 1, Your system interface should consider a few element such as user friendly, attractive and appropriate word. You may add more suitable data in the structure but limited to not more than 3. The deleteNode() function is used to remove a record of the targeted id from the linked list. The deleteNode() function shall return the target id if the…arrow_forward
- Objectives: The code for the different stack and queue operations in both implementations (array and linked list) are discussed in the lectures: and are written in the lectures power point. So the main object of this assignment is to give the student more practice to increase their understanding of the different implementation of these operations. - The students also are asked to write by themselves the main methods in the different exercises below; The Lab procedures: The following files must be distributed to the students in the Lab - arrayImpOfStack.java // it represents an array implementation of the stack. - pointerImOfStack.java // it represents a Linked List implementation of the stack. - pointerImOfQueue.java // it represents a pointer implementation of the queue. Then the students by themselves are required to write the code for the following questions Ex1) Given the file arrayImpOfStack.java then write a main method to read a sequence of numbers and using the stack…arrow_forward48. Fullness Experiment: a. Design and implement a method height for BinarySearchTree that returns the height of the tree (you have already done this if you completed Exercise 32). b. Define the fullness ratio of a binary tree to be the ratio between its minimum height and its height (given the number of nodes in the tree). For example, the tree in Figure 7.5a has a fullness ratio of 1.00 (its minimum height is 3 and its height is 3) and the tree in Figure 7.6c has a fullness ratio of 0.33 (its minimum height is 3 and its height is 9). Implement a method fRatio to be added to the BinarySearchTree class that returns the fullness ratio of the tree. C. Create an application that generates 10 "random" trees, each with 1,000 nodes (random integers between 1 and 3,000). For each tree output its height, optimal height, and fullness ratio. d. Submit a report that includes your code for the height method, the fRatio method, the application code, sample output, and a short discussion. The…arrow_forwardcan you help me with no.11 in c++? thanksarrow_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