Question: 5. Pre-order and post-order traversal (10 points) Additionally, create and traverse the following trees: root Implement the textbook's algorithm (not the Java implementation) for pre-order

 5. Pre-order and post-order traversal (10 points) Additionally, create and traverse

5. Pre-order and post-order traversal (10 points) Additionally, create and traverse the following trees: root Implement the textbook's algorithm (not the Java implementation) for pre-order and post-order traversal. To "process" or "visit" a node means to print the data at that node. height = 3 level 1 (1) Algorithm preorder(p): perform the "visit" action for position p { this happens before any recursion} for each child c in children(p) do preorder(c) {recursively traverse the subtree rooted at c} Code Fragment 8.12: Algorithm preorder for performing the preorder traversal of a subtree rooted at position p of a tree. Thanks to https://stanford.eduldassarchive desisto best 1151/images/tree height figure.png Root Algorithm postorder(p): for each child c in children(p) do postorder(c) {recursively traverse the subtree rooted at c} perform the "visit" action for position p {this happens after any recursion) com Code Fragment 8.13: Algorithm postorder for performing the postorder traversal of a subtree rooted at position p of a tree. yahoo unc cs google maps Thanks to Goodrich, Algorithms and Data Structures in Java, 6th Edition med Feel free to reuse the tree and code from problem 2 as a test case. Thanks to http://www.cs.unc.edu/-dewan/compl14/05/recitation/ Rubric: Student name and today's date is a comment in the first line of the programs: -10 points if fails Screenshot and program code: -10 points if fails All lines of program output shown: -10 if fails Tree creation for two additional trees: 4 points Pre-order traversal and output for all three trees: 3 points Post-order traversal and output for all three trees: 3 points The tree from problem 2: Pre-order traversal output: 10 6 4 8 18 15 21 Post-order traversal output: 4 8 6 15 21 18 10 Please paste a screenshot of a successful program run with all lines of output, and copy-and-paste the source code from your main program's.java file, here. You do not need to include the TreeNode.java file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!