Height Balanced Binary Tree | C++ Placement Course | Lecture 27.9

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • Complete C++ Placement Course (Data Structures+Algorithm) : • C++ Full Course | C++...
    Telegram: t.me/apnikaksh...
    Instagram: / dhattarwalaman
    Notes of this Lecture:

Комментарии • 91

  • @priyanshkhatri
    @priyanshkhatri 3 года назад +60

    Done with the 100th video. Started this playlist once before but gave up at arrays due to not being confident enough if i had a proper grasp on the topics or not. Things were different this time around. Before moving forward, I would like to thank every single member of Apna College team. Thank you for the amazing animation, brilliant teaching and enjoyable questions. Sad that only a few people have reached this far till now.

  • @divyarthsingh589
    @divyarthsingh589 3 года назад +21

    One of the best explanations in whole series is done by this teacher!! She explains very well!! Aisa lagra hai jaisa binary tree hi sabse best samajh mein aaya hai!!

  • @hardiknegi7066
    @hardiknegi7066 3 года назад +8

    Done with the 100th lecture ,a major thanks to all the educators for this legit course.

  • @051-rahulchourasia8
    @051-rahulchourasia8 3 года назад +24

    completed century..... Big thanx to Apna college, Animator, and Aman bhaiya. May God bless u all.

  • @ogbuddha7835
    @ogbuddha7835 2 года назад +2

    As you can see only 64 people have reached here till now including me. So congratulations to you for being one of the best of the best 😍🥳

  • @sleepypanda7172
    @sleepypanda7172 3 года назад +7

    temp notes:
    // #include
    // using namespace std;
    // class Node
    // {
    // public:
    // int data;
    // Node *left;
    // Node *right;
    // Node(int value)
    // {
    // left = NULL;
    // right = NULL;
    // data = value;
    // }
    // };
    // int height(Node *root)
    // {
    // if (root == NULL)
    // {
    // return 0;
    // }
    // int k = height(root->left);
    // int f = height(root->right);
    // int check = max(k, f) + 1;
    // return check;
    // }
    // bool balancedtree(Node *root)
    // {
    // if (root == NULL)
    // {
    // return true;
    // }
    // if (balancedtree(root->left) == false)
    // {
    // return false;
    // }
    // if (balancedtree(root->right) == false)
    // {
    // return false;
    // }
    // int a = height(root->left);
    // int b = height(root->right);
    // if (abs(a - b) left = new Node(2);
    // root->left->left = new Node(3);
    // // root->left->left->left = new Node(4);
    // // root->left->left->left = new Node(5);
    // root->right = new Node(4);
    // cout right,&rh) == false)
    {
    return false;
    }
    *height=max(lh,rh)+1;
    if (abs(lh-rh) left = new Node(2);
    root->left->left = new Node(3);
    root->left->left->left = new Node(4);
    root->left->left->left = new Node(5);
    root->right = new Node(4);
    int height=0;
    cout

    • @SudakshinaMaitra
      @SudakshinaMaitra Год назад +1

      thank you so much for providing notes under most of the videos

  • @vishalgoel7661
    @vishalgoel7661 2 года назад +1

    You are calculating height of each node repeatedly for each node which makes its times complexity to above O(n)

  • @jayeshmandavkar9837
    @jayeshmandavkar9837 3 года назад +2

    Completed 100th video.........!! for c++ DSA series, being a mechanical engineer I wanted to go in IT industries and this series is really helping me out in my journey. Initially I was not enough confident but now with the time I am growing day by day, hope so I shall be able to complete all the playlist. A big big THANKS to Apna collage team.

  • @illumi.........7864
    @illumi.........7864 Год назад +2

    bool isBalanced(Node* root){
    if(root == NULL){
    return true;
    }
    int LH = Height(root->left);
    int RH = Height(root->right);
    if(abs(LH-RH) left);
    isBalanced(root->right);
    return true;
    }
    return false;
    }
    I think this one is easier to understand.......

  • @StoryGicRohit
    @StoryGicRohit 3 года назад +17

    She Explains every point very well :) Didi Rocks ❤

  • @piyushborkar6803
    @piyushborkar6803 3 года назад +8

    Aman bhaiya can you make a podcast with sagar dodeja (IES officer ,Gate topper).Because you both are my inspiration 🙏🏼😘😍

  • @siddheshwarpanda7615
    @siddheshwarpanda7615 2 года назад +1

    Great work. Century completed🤩🤩

  • @prasaddalwee7533
    @prasaddalwee7533 2 года назад +5

    simple code:
    int balanced_height_tree(Tree* node, int &bal)
    {
    if(node==NULL)
    return 0;
    int l=balanced_height_tree(node->left,bal);
    int r=balanced_height_tree(node->right,bal);
    if(abs(l-r)>1)
    bal=0;
    return max(l,r)+1;
    }
    bool bal_tree(root)
    {
    int bal=1;
    balanced_height_tree(root,bal);
    return bal;
    }

  • @KovidhVSBhati
    @KovidhVSBhati 7 месяцев назад +1

    lh - rh right);
    return max(lHeight, rHeight) + 1;
    }
    bool isBal(Node* root)
    {
    int lh = CalcHeight(root->left);
    int rh = CalcHeight(root->right);
    if ( lh - rh right = new Node(3);
    root->left->left = new Node(4);
    root->left->right = new Node(5);
    root->right->left = new Node(6);
    root->right->right = new Node(7);
    root->right->right->right = new Node(7);
    root->right->right->right->right = new Node(7);
    cout

  • @saikeerthanchiluka4027
    @saikeerthanchiluka4027 Год назад +1

    Because we are visiting a node only once and we are doing single operation

  • @amayatre3558
    @amayatre3558 3 года назад +5

    Please can some one tell me how that height pointer calculated the height of the node simultaneously with checking the node.

    • @shaheenrafiq5974
      @shaheenrafiq5974 3 года назад +1

      Basically she keeps making integers LH and RH for each node and sends their pointer to the left and right children so that it may get updated with the height of their children and so on.

    • @rajmhatre20
      @rajmhatre20 3 года назад +2

      @@shaheenrafiq5974 everytime it will be 0 then? how can we calculate max(lh,rh)

    • @gauravupreti9340
      @gauravupreti9340 3 года назад

      @@rajmhatre20 In leaf node lh and rh are 0, thus *height becomes 1, thus either lh/rh of calling function becomes 1 as we are calling by address and not by value, then this cycle continues.

  • @aastikchaudhary3714
    @aastikchaudhary3714 3 года назад +4

    100 Videos Completed!!
    Thanks Apna College!

  • @prbai3844
    @prbai3844 3 года назад +1

    #include
    using namespace std;
    struct Node {
    int data;
    struct Node*left;
    struct Node*right;
    Node(int val){
    data=val;
    left =NULL;
    right=NULL;
    }
    };
    int height(Node* root)
    {
    if(root==NULL) return 0;

    return max (height(root->left),height(root->right))+1;
    }
    bool isbalanced(Node* root)
    {
    if(root==NULL)
    return true;
    if(isbalanced(root->right)==false)
    return false;
    if(isbalanced(root->right)==false)
    return false;

    int lheight=height(root->left);
    int rheight=height(root->right);

    if(abs(lheight-rheight)left = new Node(2);
    root->right = new Node(3);
    root->left->left = new Node(4);
    root->left->right = new Node(5);
    root->right->left = new Node(6);
    root->right->right= new Node(7);
    if(isbalanced(root))
    cout

  • @ogbuddha7835
    @ogbuddha7835 2 года назад +3

    Congratulations to me for completing 100 videos today 🙋 a more 116 to go 😘😍❤️

  • @girishporwal5183
    @girishporwal5183 3 года назад +4

    Amazing explainations didi .You are the best.
    Ty AC team

  • @shreyankshrestha9274
    @shreyankshrestha9274 3 года назад +3

    done with hundred lectures .
    Sukriya baba for such a great course

  • @alqamashaikh1879
    @alqamashaikh1879 2 года назад

    Chaloo 100th lecture accomplished

  • @adarshverma9957
    @adarshverma9957 3 года назад +6

    your videos are amazing bhaiya

    • @yashasvi9301
      @yashasvi9301 3 года назад +2

      bhai pdh bhi rahe ho sath me ki ni

    • @adarshverma9957
      @adarshverma9957 3 года назад +1

      @@yashasvi9301 padh raha hu bhai

    • @ujefmalek77
      @ujefmalek77 3 года назад

      Abhi to behna samaja rahi hai😁

  • @madhurimgupta2887
    @madhurimgupta2887 3 года назад +4

    she is amazing in clearing each concept!!

  • @saikeerthanchiluka4027
    @saikeerthanchiluka4027 Год назад +1

    Here TC I guess O(n)

  • @ankurkhandelwal1375
    @ankurkhandelwal1375 3 года назад +2

    Pointer vaali technique theek se samajh nhi aayi 🥺

  • @informationwithk.s5022
    @informationwithk.s5022 Год назад

    Data Structure Lab 10: AVL Tree Implementation in C++| AVL Insertion | AVL Rotations | AVL vs BST
    ruclips.net/video/VojjAbExgfg/видео.html

  • @Veds5861
    @Veds5861 Год назад +1

    Shradha didi op tutor

  • @shaantyagi2187
    @shaantyagi2187 2 года назад +1

    Century ho gayi Bhaisahab, ab apun chand pe jayega!

  • @zahidatanveer6892
    @zahidatanveer6892 2 года назад +2

    can someone plz explain how height variable counted without incrementing lh and rh variable.

    • @sawanpatel3491
      @sawanpatel3491 2 года назад

      we passed address of lh & rh not values. so when we will reach to leaf of left sub tree , there the lh becomes 1 then the height will increment by one. then we back to leaf-1 node of left subtree where *height=max(lh, rh)+1& lh ==1 so height=1+1;
      and so on.......

    • @Amotivation-fo4wu
      @Amotivation-fo4wu 2 года назад

      because of recurtion

  • @srijankunduchowdhury
    @srijankunduchowdhury 2 года назад

    100 done!! :)

  • @melodytunes2204
    @melodytunes2204 3 года назад +2

    bhaiya ek suggestion h ki aap last ki videos jinme bacho ko zada doubts h un videos k liye live class rakhlo

    • @melodytunes2204
      @melodytunes2204 3 года назад +1

      aur ya fir comments section m jo doubts h unhe lekar video record krdo taki apko video dubara bhi na banana pde aur content aur zada better hojaye

  • @prashantchakrawarti42
    @prashantchakrawarti42 3 года назад +2

    Thanku soo much Sirji and Didi 🌺 ji

  • @suryansh70
    @suryansh70 2 года назад +1

    very good and crystal clear explaination

  • @dam7854
    @dam7854 3 года назад +2

    we should also do *height=0 if(root==NULL)
    right? because we did the same in the previous video(video no 98) while calculating diameter in O(n) .

    • @rahul_ji21
      @rahul_ji21 3 года назад +2

      Yeah I guess

    • @adityabhandari6688
      @adityabhandari6688 3 года назад

      yes, in last video we did it and I don't know why we did it. Can someone please explain

    • @rahul_ji21
      @rahul_ji21 3 года назад

      @@adityabhandari6688 actually we don't to do it at all, when recursion reaches the final stack it automatically takes height as 0

    • @adityabhandari6688
      @adityabhandari6688 3 года назад

      @@rahul_ji21 ok, thanks

  • @AYUSHGUPTA-jk8xu
    @AYUSHGUPTA-jk8xu 3 года назад

    int height(Node *root)
    {
    if (root == NULL)
    {
    return -1;
    }
    return max(height(root->left), height(root->right)) + 1;
    }
    bool isBalanced(Node* root)
    {
    if (root == NULL)
    return true;
    int lh = height(root->left);
    int rh = height(root->right);

    if (abs(lh - rh) left) && isBalanced(root->right))
    return true;
    return false;
    }

  • @sudhanwapande2040
    @sudhanwapande2040 3 года назад +1

    Microsoft didi op 🔥💥

  • @pritamsarkar3371
    @pritamsarkar3371 2 года назад

    class Node:
    def __init__(self,val=0,left=None,right=None):
    self.val = val
    self.left = left
    self.right = right
    root = Node(1)
    root.left = Node(2)
    root.right = Node(3)
    root.left.left = Node(4)
    root.left.left.left = Node(5)
    def check_balanced(root):
    if not root:
    return (0,0)
    lh,lf = check_balanced(root.left)
    rh,rf = check_balanced(root.right)
    ch = max(lh,rh)+1
    cf = max(abs(lh-rh),lf,rf)
    return (ch,cf)
    if __name__=="__main__":
    height,balanced_factor = check_balanced(root)
    print("balanced") if balanced_factor

  • @insipration819
    @insipration819 3 года назад +2

    How many days remaining for completion of this course

  • @shivamsoni2553
    @shivamsoni2553 3 года назад +2

    Bhaiya discord link not working on apni kaksha channel please update it 😬

  • @sohammukherjee1392
    @sohammukherjee1392 2 года назад

    Where is the function abs???

  • @niyatisrivastava5407
    @niyatisrivastava5407 2 года назад

    I think you should show full code at a glance..can't make out

  • @Chachavimdhayak1
    @Chachavimdhayak1 2 года назад

    2 minute silence for those who were thinking that she is teaching AVL Tree😂

  • @gauravnikam8843
    @gauravnikam8843 3 года назад

    The Numbers of views on this shows how many people leave what they started pretty soon.
    Nonetheless *First Milestone Completed*

  • @ayushSharma-fx3pf
    @ayushSharma-fx3pf Год назад

    Are notes to do bhai video age peeche karke kab tak banaye

  • @poorviagarwal7692
    @poorviagarwal7692 3 года назад

    Sometimes plz do explain by tracing also

  • @harshchauhan-coolmind3615
    @harshchauhan-coolmind3615 2 года назад

    2:21 Use zee roh kehte hai!!

  • @informationwithk.s5022
    @informationwithk.s5022 Год назад

    Data Structure Lab 10: AVL Tree Implementation in C++| AVL Insertion | AVL Rotations | AVL vs BST
    ruclips.net/video/VojjAbExgfg/видео.html

  • @factStorybybong
    @factStorybybong 2 года назад

    Century Completed... ❤❤❤

  • @sloppybug9856
    @sloppybug9856 3 года назад

    if root == NULL
    return -1;

  • @girishkumar3799
    @girishkumar3799 2 года назад

    ye LH & RH kaise count ho rhe h ?
    rh aur lh ki value to update kaise ho rhi h?

  • @anuragpandey3341
    @anuragpandey3341 3 года назад

    100 videos done

  • @CodingMonster23
    @CodingMonster23 7 месяцев назад

    Notes please

  • @hideme420
    @hideme420 2 года назад

    Kbhi dry run bhi krdiya kro didi😔🥲

  • @sgcreations5638
    @sgcreations5638 2 года назад

    very clean , clear and concise explanation ❤.

  • @chamangupta4624
    @chamangupta4624 3 года назад

    100 complete💕

  • @Ankitsingh-my1vu
    @Ankitsingh-my1vu 3 года назад +2

    I haven't find best explanation for this topic and this video lecture is unfortunetly no exception

  • @sonalidutta825
    @sonalidutta825 3 года назад

    While understanding recursion i just realized TENET is based on recursion only😂😂😂

  • @xoxitop729
    @xoxitop729 2 года назад

    Notes

  • @Kunal-jp8tn
    @Kunal-jp8tn 3 года назад

    Very informative thanks.

  • @manishisaxena2712
    @manishisaxena2712 3 года назад

    Maje aagai 💯 percent high with josh

  • @shikhamaurya4453
    @shikhamaurya4453 3 года назад

    Dhanyawaad

  • @ashwinvarma9349
    @ashwinvarma9349 3 года назад +1

    shouldnt that be static int?

    • @shivanshshukla8911
      @shivanshshukla8911 3 года назад

      no

    • @ashwinvarma9349
      @ashwinvarma9349 3 года назад

      @@shivanshshukla8911 why not?

    • @shivanshshukla8911
      @shivanshshukla8911 3 года назад +1

      @@ashwinvarma9349 If u take it as static, then u are storing left height of all nodes in same variable[ as static variable lives in memory throughout all recursion chains], so it is better to store left height of diff nodes in diff variables[ as there might be chance of overlap].

    • @gauravupreti9340
      @gauravupreti9340 3 года назад

      Then, lh and rh will always be equal.

  • @rajdave9862
    @rajdave9862 3 года назад

    God bless you all team

  • @lazypanda6161
    @lazypanda6161 3 года назад

    ❤❤

  • @AlokSingh-jw8fr
    @AlokSingh-jw8fr 3 года назад

    Century. The pitch wasn't easy to play as the ball was spinning a lot (i.e. questions). But I kept my calm and composure. I didn't let the questions dominate me for long. I will try to convert this hundred into a double hundred. I won't let that momentum slip away.
    Thanks to my coaches aman bhaiya and this di and the rest of the team.