How to Find the Diameter Of Binary Tree(Better Approach) - C++
ฝัง
- เผยแพร่เมื่อ 17 ก.ย. 2024
- Get COURSES For FREE Using This Scholarship Test. Register Here Now: www.codingninj... In this video you will learn how to calculate the diameter of a Binary tree with a slightly different approach.
0:20: Diameter of a Binary Tree.
2:06 : Assumptions for calculating the diameter of a Binary tree.
3:10 Condition where diameter of binary tree will be the sum of lh and rh.
3:30 Condition where both the nodes are on the left side in that case lhe diameter will be ld.
3:35 Condition where both the nodes are on the right side in that case the diameter will be rd.
4:30 Code for the problem
10:00 Time complexity for Binary tree.
--------------------------------------------------------------------------------
Join our Coding Ninjas official telegram community here: t.me/codingnin...
--------------------------------------------------------------------------------
Coding Ninjas is one of the leading EdTech company providing India’s Highest rated programming courses in C++, Data Structures and Algorithms, Java, Python, Machine Learning, web development, Data Science, Android Development, Kotlin, React.
To explore our courses, click here: bit.ly/2WWmdE1
To explore our Free Trial Courses click here: bit.ly/2YqUL1Y
-----------------------------------------------------
To watch more exciting videos on programming, subscribe to our channel here: bit.ly/36n3g08
------------------------------------------------------
Explore more on our social media platforms:
Facebook: / codingninjas
Instagram: / coding.ninjas
Linkedin: / 1319…
Register for Coding Ninjas Scholarship Programme:
bit.ly/CNSCHOLARSHIP
its been 4 years since this video was posted but it is still the best video on the internet
Man!! Enjoyed a lot. Very well explanation and love the way you explain. Keep it up...
Very well explained, also which editor is sir using?
Great explaination. Thank you!
Thank you
Very nicely explained.. thnx sir
height in case of null should be -1 not zero, if you assume height of root is 0 not 1.
If you do -1, then you should do leftHeight + rightHeight + 2.. which is the same thing what Sir did.
I'm a simple person
I see vi
I press like
Amazing explanations, helped me a lot!
thank you :)
Good explanation
IGot queries related to Binary tree , Let us know in the comments section
In this video you will learn how to calculate the diameter of a Binary tree with a slightly different approach.
0:20: Diameter of a Binary Tree.
2:06 : Assumptions for calculating the diameter of a Binary tree.
3:10 Condition where diameter of binary tree will be the sum of lh and rh.
3:30 Condition where both the nodes are on the left side in that case lhe diameter will be ld.
3:35 Condition where both the nodes are on the right side in that case the diameter will be rd.
4:30 Code for the problem
10:00 Time complexity for Binary tree.
well explained
how it this better? it is doing it in O(n2) time complexity
Hi Sir,
I think in height() one more if condition should be there for checking the leaf and here is the total code for finding the height of the binary tree. Well I am writing this code in C language.
int height(struct node *head){
if(!head){
return 0;
}
if(!head->left && !head->right){
return 0;
}
return 1+ max(height(head->left),height(head->right));
}
yeah but this condition is not necessary. it will still work without this condition.
In which course this topic is been taught?
Data structure, algorithm....
Great explaination
Join our Coding Ninjas official telegram community here:
t.me/codingninjas_official
Diameter Of Binary Tree = left_height + right_height + 1
Please make your videos in English