Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Binary Tree - AB 30.3 The height of a binary tree is defined as the number of nodes in the longest path from the root
Binary Tree - AB 30.3
The height of a binary tree is defined as the number of nodes in the longest path from the root to a leaf of the tree. The heights of the trees above are 5 for Tree 1 , and 6 for Tree 2 . In general, the width of an empty tree is 0 , and the width of a nonempty tree is the maximum of the following three quantities: . The width of the left subtree 2. The width of the right subtree 3. The length of the longest path that includes the root (which can be calculated from the heights of the left and right subtrees) When writing these two methods (height and width), you may find it useful to use the max method from the java.lang..Math. Math.max (int a, int b) Assignment: 1. Write a main menu module with the following menu choices: (1) Fill the tree from a file (2) Preorder output (4) Postorder output (5) Count the nodes in the tree (6) Count the leaves in the tree (8) Find the height of the tree (9) Clear the tree (10) Interchange the tree (mirror image) (11) Print level (q) Quit ( fileA.t txt)= KECAJGHOSRV ( fileB. txt )= QJHBADFKNLMPTW 3. You should print appropriate messages, labeling each output. Instructions: 2. For each file, turn in your source code and answers for menu choices 212, appropriately labeled. Note that all requested output must be formatted as node values separated by spaces. For example: TIP \#1: Note that all requested tree output must be formatted as node values separated by spaces. For example: - input values for tree KECAJGHOSRV - print tree inorder ACEGHJKORSV TIP \#2: For printLevel(), the root node is considered to be "level 0 ", not "level 1 ". TIP \#3: For the accumulate(), you are to include the root as part of the sum of nodes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started