Maximum Depth of Binary Tree | Height of Tree| Tree Data Structure playlist C++ | Hello World

preview_player
Показать описание
This is the video under the series of DATA STRUCTURE & ALGORITHM in a TREE Playlist. We are going to understand How to find the Maximum Depth of a Binary Tree or Height of a Binary Tree. We understand the Recursive code of the same Tree step by step.

104. Maximum Depth of Binary Tree | Height of Binary Tree

Given the root of a binary tree, return its maximum depth.
A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Input: root = [3,9,20,null,null,15,7]
Output: 3

We also Provide courses on Competitive Programming and Data structure and Algorithms. Please see our Full Playlist on our Channel.
----------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------
*Follow me *
----------------------------------------------------------------------------------------

►Our Playlists on:-

------------------------------------------------------------------------

🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟

✨ Tags ✨
Maximum Depth of Binary Tree
What is Tree Data Structure in Hindi
Height of Binary Tree
Code of Binary tree in c++
Use of Tree Data structure in real Life
question asked in Google
how to crack Google Interview
off-campus placement
how to learn to code for beginners
Practice Tree data structure
tree in data structure
Best Telegram channel for Off-campus Placement drive
Tree in a data structure in Hindi
Tree Full playlist for Beginners

#Tree #Leetcode #programming
Рекомендации по теме
Комментарии
Автор

I don't know how do we even learn to think like that, the way you came up with the solution recursively, already having an intution what the final recursive call going to return and building up to the final solution. Do people who are really good at DSA just born with this talent? or does it come from practice. I don't think I'll even be able to be as good as you or any other DSA Youtuber. Some people are too good to be true. I'm really beating myself over it and getting depressed.

hikikomori
Автор

Finally I understood this topic just because of you!!!!
Thankyou sirr!!!!❤

AAYUSHSHARMAPCECS
Автор

Guru ji pan papper wala sabse best hai isi pr continue rhiye

satyaprakashsingh
Автор

Bhaiya you are the best in explaining thank you yaar. i understood everything so clear.

akulanvn
Автор

we can do straight bfs traversal as height of the tree would be= no.of levels, but ya if height of left and right sub tree are asked the we can do like as taught
vector<vector<int>> ans;
// edge case
if(!root) return 0;
queue<TreeNode*> q;
q.push(root);
while(!q.empty()) {
vector<int> temp;
int size = q.size();
for(int i=0; i<size; i++) {
TreeNode* node = q.front();
q.pop(); // as FIFO so pop will be from front
if(node->left) q.push(node->left);
if(node->right) q.push(node->right);
temp.push_back(node->val);
}
ans.push_back(temp);
}
return ans.size();
}

vitaminprotein
Автор

Bhaiya hum root->left mei kitne node hai unko store kar lenge ek variable mei and then root ->right ko bhi store kar lenge and maximum print kar denge.
Sahi approach hai bhaiya

AnkitKumar-ozwl
Автор

Got more clear understanding...Thanks🙏

kamalkushwaha
Автор

Great Video Brother :) my friend suggested your tree videos, truly commendable.

rohitsoni
Автор

Homework Done! Can't thank you enough bhaiya:D

tanvisharma
Автор

Bhaiya please AAP recursion tree se he recursion ka code btaya karo...usme concept ek dum badiya clear hota he...ese m dande bnakr thoda ajeeb sa lagta h

itsaayush
Автор

I was able to solve it from different approach .. but thanks for this ❤ 📹

sudhadevi
Автор

Arey Bhai Bhai bhai bhai!
Kya mast smjhaate ho bhai❤️

Thanks for being exist🔥

alexmercer
Автор

Aapke graph ki series ke karn yeh khud kar paya hoon .
int maxDepth(TreeNode* root) {
queue<TreeNode*>q;
if(root==NULL)return 0;
int ans=0;
TreeNode*temp;
q.push(root);
while(!q.empty()){
int s=q.size();
while(s!=0){
temp=q.front();
q.pop();
if(temp->left!=NULL){
q.push(temp->left);
}if(temp->right!=NULL){
q.push(temp->right);
}

s--;
}ans++;
}return ans;
}

crjohnChan
Автор

definition of height of binary tree is really confusing
according to definition
Height of Binary tree is the number of edges along the longest path from root to leaf.
where leaf node height is 0 .

but here it's different and leaf node height is 1. can you pls explain which definition is correct ?

RN-jozt
Автор

Simple and accepted solution:-

func maxDepth(_ root: TreeNode) -> Int {
if root == null {
return 0
}

if root.left == null && root.right == null {
return 1
}

let maxDepthLeft = maxDepth(root.left)
let maxDepthRight = maxDepth(root.right)

return max(maxDepthLeft, maxDepthRight) + 1
}

patilashish
Автор

sir you explained really well thank you so much. Great explanation.

maneeshapanu
Автор

Sir, very nice explanation, thank you so much <3

mdwahid
Автор

Question ko solve krne lga..
Total No. Of node se, leftmost, rightmost se
40 mins nikal gye.. most test fass rhe the
After that, I view this full vedio...
I was Like,
Ekdum inhone wqt bdl diya, jazzbat bdl diye, zindgi bdl di...eh mazak ho rha hai 🥲

AbhishekKumar-deeo
Автор

Sir Hume iska iterative solution ni krna haii ?? Ya karna chaiye

sanjeevgupta
Автор

int depth(node* root ) {
static int h = 0;
if (root == NULL) {
return 0 ;
}
h++;
if (root->left == NULL) {
depth(root->right);
} else if(root->right){
depth(root->left);
}
else return -1;
return h;
}

jeetkishore