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…

ความคิดเห็น • 24

  • @CodingNinjasIndia
    @CodingNinjasIndia  3 ปีที่แล้ว

    Register for Coding Ninjas Scholarship Programme:
    bit.ly/CNSCHOLARSHIP

  • @NaveensinglaYT
    @NaveensinglaYT 2 ปีที่แล้ว +1

    its been 4 years since this video was posted but it is still the best video on the internet

  • @yuv54
    @yuv54 5 ปีที่แล้ว +7

    Man!! Enjoyed a lot. Very well explanation and love the way you explain. Keep it up...

  • @anujjadhav2771
    @anujjadhav2771 3 ปีที่แล้ว

    Very well explained, also which editor is sir using?

  • @sarfarazalam6077
    @sarfarazalam6077 4 ปีที่แล้ว +2

    Great explaination. Thank you!

  • @kaushtubrawat6114
    @kaushtubrawat6114 6 ปีที่แล้ว +1

    Very nicely explained.. thnx sir

  • @abhi4unme2002
    @abhi4unme2002 6 ปีที่แล้ว +2

    height in case of null should be -1 not zero, if you assume height of root is 0 not 1.

    • @geekySRM
      @geekySRM 3 ปีที่แล้ว

      If you do -1, then you should do leftHeight + rightHeight + 2.. which is the same thing what Sir did.

  • @debasismandal1924
    @debasismandal1924 4 ปีที่แล้ว +4

    I'm a simple person
    I see vi
    I press like

  • @namantiwari7155
    @namantiwari7155 6 ปีที่แล้ว +3

    Amazing explanations, helped me a lot!

  • @neetisharma3768
    @neetisharma3768 5 ปีที่แล้ว +2

    thank you :)

  • @vivekgr3001
    @vivekgr3001 4 ปีที่แล้ว

    Good explanation

  • @CodingNinjasIndia
    @CodingNinjasIndia  4 ปีที่แล้ว +2

    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.

  • @letsrock7354
    @letsrock7354 6 ปีที่แล้ว

    well explained

  • @mohitarora2190
    @mohitarora2190 5 ปีที่แล้ว

    how it this better? it is doing it in O(n2) time complexity

  • @RCorpVideos
    @RCorpVideos 6 ปีที่แล้ว +1

    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));
    }

    • @mohitarora2190
      @mohitarora2190 5 ปีที่แล้ว

      yeah but this condition is not necessary. it will still work without this condition.

  • @abhishekgautam1063
    @abhishekgautam1063 5 ปีที่แล้ว

    In which course this topic is been taught?

    • @MultiSudipta
      @MultiSudipta 4 ปีที่แล้ว +1

      Data structure, algorithm....

  • @aniketsriwastva6345
    @aniketsriwastva6345 4 ปีที่แล้ว

    Great explaination

  • @CodingNinjasIndia
    @CodingNinjasIndia  3 ปีที่แล้ว

    Join our Coding Ninjas official telegram community here:
    t.me/codingninjas_official

  • @durbijkewat7671
    @durbijkewat7671 4 ปีที่แล้ว +4

    Diameter Of Binary Tree = left_height + right_height + 1

  • @rockerboy4184
    @rockerboy4184 3 ปีที่แล้ว

    Please make your videos in English