C++   How to Program (Early Objects Version)
C++ How to Program (Early Objects Version)
10th Edition
ISBN: 9780134448824
Author: Paul Deitel; Harvey M. Deitel
Publisher: Pearson Education (US)
Question
Book Icon
Chapter 19, Problem 19.19E
Program Plan Intro

Number of Levels that a Binary Tree Has

Program Plan:

1. Construct a tree with a root node, and 4 leaf nodes
2. Find the depth of the left subtree in a recursive manner if the tree is not null
3. Find the depth of the right subtree in a recursive manner if the tree is not null
4. Determine the maximum value of the depths of both subtrees
5. Add 1 to the resulting value for the current node
6. Return depth of the root node to get the number of levels in the given binary tree.

Blurred answer
Students have asked these similar questions
Don't reject
Language/Type: C++ binary trees pointers recursion Write a function named hasPath that interacts with a tree of BinaryTreeNode structures representing an unordered binary tree. The function accepts three parameters: a pointer to the root of the tree, and two integers start and end, and returns true if a path can be found in the tree from start down to end. In other words, both start and end must be element data values that are found in the tree, and end must be below start, in one of start's subtrees; otherwise the function returns false. If start and end are the same, you are simply checking whether a single node exists in the tree with that data value. If the tree is empty, your function should return false. For example, suppose a BinaryTreeNode pointer named tree points to the root of a tree storing the following elements. The table below shows the results of several various calls to your function: 67 88 52 1 21 16 99 45 Call Result Reason hasPath(tree, 67, 99) true path exists…
Complete the TODOs in C++ 1. Implement sumNodes function which sums the data of all the nodes of the tree. (Silver Problem)2. Implement printLeafNode function which prints just the leaf nodes of thetree. (Gold Problem) (.hpp file in image) 1st code is driver.cpp #include <iostream> #include "tree.hpp" using namespace std; #define COUNT 10 int main() { Treet; t.createTree(); //cout<<t.root->data<<endl; t.print2DUtil(t.root, 0); // 1, 2, 4, 5, 3, 6, 7 cout<<"\nPreorder traversal of binary tree is \n"; t.preOrderTraverse(t.root); cout<<endl; /********************** Silver problem ***********************/ cout<<"\nSum of all the nodes in tree is: "<<t.sumNodes(t.root); cout<<endl; /********************** Gold problem ***********************/ cout<<"\nPrinting leaf nodes of the tree \n"; t.printLeafNode(t.root); cout<<"\nDeleting the tree \n"; t.deleteTree(t.root); t.root=NULL; cout<<endl; return0; }   2nd code:…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education