Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 21.1, Problem 21.3CP
Program Plan Intro
Preorder traversal:
It process all the nodes of the tree in the following order.
- First, traverse the root node.
- Then, traverse all the nodes in the left subtree.
- Finally, traverse all the nodes in the right subtree.
Method “preorder” to print the values stored in a binary tree is as follows:
Node preorder(Node bTree)
{
//Check tree is not empty
if (tree != null)
{
//Print the root node value
System.out.print(bTree.value + " ");
//Print value of left subtree
preorder(bTree.left);
//Print value of right subtree
preorder(bTree.right);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Suppose an array is given A = [A, C, E, F, K, L, M, N, Y, Z]
a. Draw a complete TERNARY tree from array A.b. Write preorder and postorder traversal for the created complete ternary.c. Draw the adjacency matrix and adjacency list for the complete ternary tree/graph.
[You must consider the tree direction from top to bottom when drawing adjacencymatrix and list]
What problems do you encounter when you try to define the concept of an inorder traversal for ternary trees?
Draw a single tree whose inorder traversal is
and whose postorder traversal is
f, a, g, b, h, d, i, c, j, e
f.g, a, h, i, d. j, e, c, b
Chapter 21 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 21.1 - Prob. 21.2CPCh. 21.1 - Prob. 21.3CPCh. 21 - Prob. 1MCCh. 21 - Prob. 2MCCh. 21 - Prob. 3MCCh. 21 - Prob. 4MCCh. 21 - Prob. 5MCCh. 21 - Prob. 6MCCh. 21 - Prob. 7MCCh. 21 - Prob. 8MC
Ch. 21 - Prob. 9MCCh. 21 - Prob. 10MCCh. 21 - Prob. 11TFCh. 21 - Prob. 12TFCh. 21 - Prob. 13TFCh. 21 - Prob. 14TFCh. 21 - Prob. 15TFCh. 21 - Prob. 16TFCh. 21 - Prob. 17TFCh. 21 - Prob. 18TFCh. 21 - Prob. 19TFCh. 21 - Prob. 20TFCh. 21 - Prob. 21TFCh. 21 - Prob. 1FTECh. 21 - Prob. 2FTECh. 21 - Prob. 3FTECh. 21 - Prob. 1SACh. 21 - Prob. 2SACh. 21 - Prob. 3SACh. 21 - Prob. 4SACh. 21 - What is a priority queue?Ch. 21 - Prob. 6SACh. 21 - Prob. 7SACh. 21 - Prob. 1AWCh. 21 - Prob. 2AWCh. 21 - Prob. 3AWCh. 21 - Prob. 4AWCh. 21 - Prob. 5AWCh. 21 - Prob. 6AWCh. 21 - Prob. 7AWCh. 21 - Prob. 4PCCh. 21 - Prob. 6PC
Knowledge Booster
Similar questions
- Write code for this question in C++ language only with proper comments and explaination.arrow_forwardAssume that the nodes of a binary tree are all unique and that you are provided the order of elements encountered in a preorder traversal and the order of elements encountered in a postorder traversal. Under what situations can you properly recreate the tree structure using these two traversal orders?arrow_forwardb. Given the array representation of a binary tree [null value means the node is empty]: [null, P, T, X, null, S, Q, U, null, null, Y, W, R, null, null, V] i. Draw the binary tree. i. Write the post-order and in-order traversal sequence of the tree. i. Convert the tree to a complete binary tree.arrow_forward
- Suppose the nodes of a binary tree are unique and that you are given the order of elements as they are encountered in a preorder traversal and the order of the elements as they are encountered in a postorder traversal. Under what conditions can you accurately reconstruct the structure of the tree from these two traversal orders?arrow_forwardAre you familiar with the properties of trees that have minimum spanning? The use of language c is presumed.arrow_forwardQuestion 8 Construct a binary tree by using the inorder traversal given below. Inorder: N, M, P, O, Q M B (0) M N M N M Q N P P P Qarrow_forward
- Give the preorder, inorder, and postorder traversal of the following tree. 65arrow_forwardAssume that each node in a binary tree is unique and that you are provided the order of items encountered in a preorder traversal and the order of elements encountered in a postorder traversal. Under what conditions can the tree's structure be correctly reconstructed using these two traversal orders?arrow_forwardSuppose an array is given A = [A, C, E, F, K, L, M, N, Y, Z] a. Draw a complete BINARY tree from array A. b. Write preorder, inorder, and postorder traversal for the created complete binary tree. c. Draw a complete TERNARY tree from array A. d. Write preorder and postorder traversal for the created complete ternary. Draw the adjacency matrix and adjacency list for the complete ternary tree/graph. [You must consider the tree direction from top to bottom when drawing adjacency matrix and list]arrow_forward
- Q12arrow_forwardExamine a traversal of a binary tree. Let's say that visiting a node means to display the data in the node. What are the result of each of the following traversals of the tree included? It is preorder, postorder, inorder or level order?arrow_forwardDesign an interface for general trees—trees with unbounded degree. Make this interface as consistent as possible with BinaryTrees when the degree of a tree is no greater than 2arrow_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