Lowest Common Ancestor of a Binary Tree | Tree Data Structure playlist C++ | Hello World | Hindi

Sdílet
Vložit
  • čas přidán 31. 07. 2021
  • This is the video under the series of DATA STRUCTURE & ALGORITHM in a TREE Playlist. We are going to understand How to Find the Lowest Common Ancestor of a Binary Tree. We understand How to use the Height of the Binary for Finding the Diameter of the Binary Tree.
    Join My Telegram channel for more Updates: telegram.me/helloworldbyprince
    ► 236. Lowest Common Ancestor of a Binary Tree
    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
    According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”
    Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1
    Output: 3
    Explanation: The LCA of nodes 5 and 1 is 3.
    We also Provide courses on Competitive Programming and Data structure and Algorithms. Please see our Full Playlist on our Channel.
    ----------------------------------------------------------------------------------------:
    Lowest Common Ancestor of a Binary Tree: leetcode.com/problems/lowest-...
    code in This Video: github.com/Prince-1501/Hello_...
    ----------------------------------------------------------------------------------------
    *Follow me *
    LinkedIn► / iamprince
    Facebook► / helloworldofficials
    Instagram► / helloworldbyprince
    Twitter► / prince_king_
    Telegram► telegram.me/helloworldbyprince
    ----------------------------------------------------------------------------------------
    ►Our Playlists on:-
    ► Tree: • Tree Data Structure & ...
    ► Hashing: • Hashing Data Structure...
    ► Matrix: • Matrix (Multidimension...
    ► STL: • Standard Template Libr...
    ► Leetcode: • LeetCode Solutions And...
    ►Competitive Programming: • Full course in Competi...
    ►C++ Full Course : • C++ full Course in HINDI
    ►Algorithms: • L-01 || Prefix Sum Arr...
    ►Data Structure: • Data Structures with C...
    ------------------------------------------------------------------------
    🌟 Please leave a LIKE ❤️ and SUBSCRIBE for more AMAZING content! 🌟
    ✨ Tags ✨
    Lowest Common Ancestor of a Binary Tree
    The tree Data structure in Hindi
    How to find the LCA of two nodes
    Lowest Common Ancestor
    Use of Tree Data structure in real Life
    question asked in Google
    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

Komentáře • 38

  • @329shashwatsharma6
    @329shashwatsharma6 Před rokem +2

    Itne saare videos dekhne ke baad ...sirf isi me smjh aaya ...finally ...thank u sir ji...

  • @SaurabhMishra0709
    @SaurabhMishra0709 Před 3 lety +12

    Your videos are very helpful....plese never stop this series 🙏🙏

  • @priyabansal9911
    @priyabansal9911 Před 3 lety +9

    Prince sir videos thoda speed se upload karo. Daily ek video toh atleast kar diya karo. By the way awesome content next Aditya verma of tree 👍🏻

  • @sohebshaikh3344
    @sohebshaikh3344 Před 2 lety +1

    Agar aap ka bhai ek din google m bhi hogya na selection tho koi hairani ki baat nhi hogi
    bhot accha samjha the ho aap
    code ka hr ek line k bhot acche se explain krte ho

  • @shubhambhatt2704
    @shubhambhatt2704 Před rokem +3

    Please make a series of BST also. 🙏🙏
    Great content

  • @siddhantsingh8721
    @siddhantsingh8721 Před rokem

    you the best bhaiya

  • @Alokkumar-xu8sf
    @Alokkumar-xu8sf Před 3 lety +4

    op sir

  • @lokeshchandel531
    @lokeshchandel531 Před rokem

    Very nicely explained bhaiya solution aache se samj me aaya hai your way of explanation is amazing

  • @udaytewary3809
    @udaytewary3809 Před rokem

    really thankyou bhaiya apke explanation ke liye

  • @ProgrammingWithProject
    @ProgrammingWithProject Před 3 lety +1

    sir plz make this type of awesome without worrying views and subscriber

  • @technojam5944
    @technojam5944 Před 8 měsíci

    Best explanation of this code ever

  • @himanshusahu6879
    @himanshusahu6879 Před rokem +1

    make video on bst also bhaiya

  • @gokulnaathb2627
    @gokulnaathb2627 Před 2 lety +1

    Very nicely explained, bhaiya, thank you so much

  • @vikassharma2094
    @vikassharma2094 Před 2 lety

    very well explained!!

  • @shivangigupta7569
    @shivangigupta7569 Před 2 lety

    You are just best.

  • @muskanbansal7782
    @muskanbansal7782 Před rokem +1

    Plz make more such videos on trees ☺️

  • @cricedge4454
    @cricedge4454 Před 2 lety +2

    Node* LCA(Node *root, int n1, int n2)
    {
    Node* ans=root;
    int k=root->data;
    if((n1==k) || (n2==k) || (n1k) ||(n1>k && n2k)
    LCA(root->right,n1,n2);
    }

  • @Pawankumar-fu9yb
    @Pawankumar-fu9yb Před rokem

    path. pop_back()
    Bool wale function me end me ise use kyu kiye ho bhaiya

  • @pkyadav6230
    @pkyadav6230 Před 2 lety +3

    bhai youtube pr bhot sari videos hain but mai apke videos pr kyon ata hoon maloon hai?/KYONKI AP SAMJHA NE KE LIYE VIDEOS BNATE HO .... AUR SAB CZcams KO .....POCKET MONEY KAMANE KA ZARIYA SMJHTE HAIN

  • @cr7johnChan
    @cr7johnChan Před 2 lety

    //Khud kya hai bhai ,Thank you for making us believe in trying it ourselves
    int funct(TreeNode*root,TreeNode*p,vector&arr){
    if(root==NULL)return 0;
    arr.push_back(root);
    if(root->val==p->val)return 1;

    else{
    if(funct(root->left,p,arr))return 1 ;
    if(funct(root->right,p,arr))return 1;

    }
    arr.pop_back();
    return 0;
    }


    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
    vectorarr1;
    vectorarr2;
    funct(root,p,arr1);
    funct(root,q,arr2);
    int n=arr1.size(),m=arr2.size();
    n= (n>m)?n:m;
    int i;
    for(i=0;ival!=arr2[i]->val)break;
    }
    return arr1[i-1];
    }

  • @CodeNinja18
    @CodeNinja18 Před 5 měsíci

    class Solution {
    public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
    if(!root) return NULL;
    if(root->val== p->val || root->val== q->val) return root;
    TreeNode* left = lowestCommonAncestor(root->left,p,q);
    TreeNode* right =lowestCommonAncestor(root->right,p,q);
    if(left && right) return root;
    else if(left && !right) return left;
    else if(!left && right) return right;
    else return NULL;
    }
    };

  • @UnKnown-id7ih
    @UnKnown-id7ih Před 2 lety +1

    Bhiya aapne bahot aacha smjhaya mgr dimag kharab ho gya
    .

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 2 lety +3

      Koi baat nahi
      Dhere dhere samjh me aayega yaar
      Ekdum se pressure mat lo