Code Activities: Part 1 - Tree Height (8 pts) Add a method to the LinkedBinaryTr
ID: 3691787 • Letter: C
Question
Code Activities:
Part 1 - Tree Height (8 pts)
Add a method to the LinkedBinaryTree class that returns the height of a tree. Like many tree methods, this will require a fairly simple method in LinkedBinaryTree and another method in BTNode that does most of the work. First, check to see if the root is null. If it is, then the tree is obviously empty and return 0. If it is not null, return root.height().
Part 2 - Decision Tree (16 pts)
Create a decision tree for a topic of your choice. Examples: How to choose a college major? How to select a car? How to determine what to eat for dinner? You must have at least 14 questions that you could potentially ask the user. You will need to add a few missing methods to get your program to work correctly.
Explanation / Answer
Answer for Question 1:
This below method will give the height of given binary tree as longest path.
See this below method is written in self explanatory to understand easily.
/* Compute the "maxDepth" of a tree -- the number of
nodes along the longest path from the root node
down to the farthest leaf node.*/
int maxDepth(struct node* node)
{
if (node==NULL)
return 0;
else
{
/* compute the depth of each subtree */
int lDepth = maxDepth(node->left);
int rDepth = maxDepth(node->right);
/* use the larger one */
if (lDepth > rDepth)
return(lDepth+1);
else return(rDepth+1);
}
}
Answer for Question 2:
Example
Step 1: What type of college degree do you want?
2 year degree or 4 year degree (4 Years)
Step 2: Choose one of the following areas of interest?
Agriculture and Natural Resources
Art, Design, and Performance
Business
Communication
Education and Human Services
Engineering, Math, and Computers
(Communication)
Step 3: Explore the following possible majors:
Advertising
Agricultural Leadership, Education, and Communications
Communications Studies
Electronic Media/Broadcasting
English
Graphic Design
(Graphic Design)
Step 4:
Area Employer Information/Strategies
Print Design
Type Design
Magazine Design
(Print Design)
like these we can make the decision tree
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.