Professional Documents
Culture Documents
Find The Maximum Depth or Height of Given Binary
Find The Maximum Depth or Height of Given Binary
Find The Maximum Depth or Height of Given Binary
Sponsored
Olymptrade
Install now
Recommended Problem
Illustration:
maxDepth(‘1’) = max(maxDepth(‘2’),
maxDepth(‘3’)) + 1 = 2 + 1
because recursively
maxDepth(‘2’) = max (maxDepth(‘4’),
maxDepth(‘5’)) + 1 = 1 + 1 and (as
height of both ‘4’ and ‘5’ are 1)
maxDepth(‘3’) = 1
Return max_depth.
C++
#include <stdio.h>
#include <stdlib.h>
return (node);
}
int main()
{
struct node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
getchar();
return 0;
}
Java
Python3
C#
Javascript
Output
Height of tree is 3
C++
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// A Tree node
struct Node {
int key;
struct Node *left, *right;
};
queue<Node*> q;
// Driver program
int main()
{
// Let us create Binary Tree shown in
Node* root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
Java
Python3
Javascript
Output
C++
// A Tree node
struct Node {
int key;
struct Node *left, *right;
};
// Driver program
int main()
{
root->left->left = newNode(4);
root->left->right = newNode(5);
Java
Output
Like 202
Previous Next
R ECO M M E N D E D A RT I C L E S
Page : 1 2 3 4 5 6
Article Contributed By :
GeeksforGeeks
Expert
Load Comments
W H AT ' S N E W
View Details
View Details
View Details
Company
About Us
Careers
In Media
Contact Us
Privacy Policy
Copyright Policy
Learn
Algorithms
Data Structures
Machine learning
CS Subjects
Video Tutorials
Courses
News
Top News
Technology
Business
Finance
Lifestyle
Knowledge
Languages
Python
Java
CPP
Golang
C#
SQL
Kotlin
Web Development
Web Tutorials
Django Tutorial
HTML
JavaScript
Bootstrap
ReactJS
NodeJS
Contribute
Write an Article
Improve an Article
Internships
Video Internship
▲