Largest Binary Search Tree in BT | C++ Placement Course | Lecture 28.10

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ก.ย. 2024
  • Complete C++ Placement Course (Data Structures+Algorithm) : • C++ Full Course | C++...
    Telegram: t.me/apnikaksh...
    Instagram: / dhattarwalaman
    Notes of this Lecture:

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

  • @ShubhivDogra
    @ShubhivDogra 3 ปีที่แล้ว +65

    this course made me answer all the interview qns asked in my college campus placenment -- 14lpa-gap

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

      @Shubiv Dogra what were the questions based upon??

    • @ShubhivDogra
      @ShubhivDogra 3 ปีที่แล้ว +7

      @@sakshamjain3775 based on stacks and linked lists..

    • @rahul_ji21
      @rahul_ji21 3 ปีที่แล้ว +1

      @@ShubhivDogra congrats

    • @sumitKumar-pf9xo
      @sumitKumar-pf9xo 3 ปีที่แล้ว

      Congo bro 🤗🤗🤗

    • @chanduchandrakanth5131
      @chanduchandrakanth5131 3 ปีที่แล้ว +2

      Bro Which clg r u from?

  • @amayatre3558
    @amayatre3558 3 ปีที่แล้ว +24

    That's what we all wanted from start ❤️❤️Make videos of longer duration but explain properly. This was best, perfectly explained. ❤️

  • @willturner3440
    @willturner3440 3 ปีที่แล้ว +7

    Only and Only in apna college, hats off to the great ma'am

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

    Bohot hi pyara concept...Maza aa gya... Kya toh samjhaya he...Waah

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

    struct Info {
    int size;
    int max;
    int min;
    int ans;
    bool isBST;
    };
    if(root==NULL){
    return{0,INT_MIN,INT_MAX,0,true};//will only come here if already traversed left and right / left is NULL so we put INT_MAX in rightInfo.min as null means it has to be greater than root in all cases and we put INT_MIN in leftInfo.max as null means it has to be less than root in all cases. LOOK ORDER IS REVERSED FOR max and min AND INT_MIN and INT_MAX.
    }
    p.s IT took me 3 days to realise this.sed life

  • @beenaasha506
    @beenaasha506 3 ปีที่แล้ว +5

    Great explanation

  • @PankajSingh-vi3fy
    @PankajSingh-vi3fy 3 ปีที่แล้ว +2

    love that music of keyword.. so satisfying 😌

  • @Zeno_Yoru
    @Zeno_Yoru 3 ปีที่แล้ว +11

    Vaiya. Lecture 28.9???

  • @sudhanwapande2040
    @sudhanwapande2040 3 ปีที่แล้ว +2

    Bohot aala samjhaya aapne.. itna tough concept ko easy kardiya🙏

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

    op, heads off to this video, what a great explanation, jod or what?

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

      @@utkarshverma2604 😂😂😂

    • @its_neel_ok
      @its_neel_ok 3 ปีที่แล้ว +1

      @@devilronak7262 ya toh pubg wala ha kaya.....xD

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

      @@its_neel_ok 😂

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

      @@devilronak7262 xD

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

      @@its_neel_ok xD

  • @lokeshdulani6035
    @lokeshdulani6035 3 ปีที่แล้ว +1

    fucking awesome far better explanation than content available at other sites

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

    Who noticed this is dynamic programing on trees to avoid repetition

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

    great explanation mam, this is what is called perfect explanation

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

    Thank you 🙏🙏

  • @tarunbisht8016
    @tarunbisht8016 3 ปีที่แล้ว +8

    I don't think there is any need to check whose value is minimum left info, right info, and current root value, cause it's obvious that left info's min value will be min and if it is not the case then it's not a bst.

    • @naiyerabbas6481
      @naiyerabbas6481 3 ปีที่แล้ว +1

      Yeah!! I was also thinking about it.. We don't need min and max

    • @avronilbanerjee5302
      @avronilbanerjee5302 2 ปีที่แล้ว

      @@naiyerabbas6481 no
      you have to check what if the left or right child is NULL ?? then the min would be different

  • @NiteshSingh5375
    @NiteshSingh5375 3 ปีที่แล้ว +1

    I think last statement spoken by tutor is not correct. Ans=2 because of max. BST found is due to 20 & 5 but not 15&30. we can not take partial(one side either left or right) Binary tree to accept it as a BST.

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

    COOKING 🍳 AND SERVING(TEACHING) US AT THE SAME TIME🤣
    We can hear 👂 the cooper's whistle behind.

  • @nazeershaik9812
    @nazeershaik9812 9 หลายเดือนก่อน

    #include
    #define ll long long
    #define loop(i,n) for(int i = 0; i < n; i++)
    #define loop1(i,n) for(int i = 1; i left);
    vector rt = help(root->right);
    vector curr (5,0);
    curr[3]=1+lt[3]+rt[3];
    if(root->data>lt[1] && root->datadata,lt[0]);
    curr[1]=max(root->data,rt[1]);
    curr[2]=1;
    curr[4]=curr[3];
    return curr;
    }
    curr[4]=max(lt[4],rt[4]);
    return curr;
    }
    int largestBST(Node* root){
    return help(root)[4];
    }
    int main()
    {
    Node* root;
    cout

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

    curr.min and curr.max ko if statement ke bahar hona chahiye

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

      yes but dont know why this code is not giving error?

    • @chirag-sg4kd
      @chirag-sg4kd 3 ปีที่แล้ว +1

      same doubt but agr bahar rakh rahe hai to ans 1 aa raha hai

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

      @@chirag-sg4kd nahi, bahar rakha to 2 aa raha hai. agar 20 to 10 se replace kiya jai to 4 ata hai, means min, max ko if ke bahar rakhne se sahi output aa raha hai..

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

      @@sanketbhagat1222 if ke bahar bhi aur andhar bhi hona chahiye

    • @TUSHAR-mj1en
      @TUSHAR-mj1en 3 ปีที่แล้ว +1

      @@vinaydangayach386 dekh bhai min max ko update karne ka koi fayada nhi h
      kyuki jab isbst false h to bade wale if condition bhi false hoga
      uka min max kabhi bhi compare hoga hi nhi bro
      aur uske karn ab uss node to milakar kabhi bhi answer nhi banega

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

    I have doubt on line no.37...if current node is BST then on line no.38 the minimum value of current node should be "minimum value from left subtree", as we mentioned left subtree is also bst ..?

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

      it's a recursive approach, think in that way, will your logic work in case of leaf nodes and nodes with only right subtree. think for one node, the last one and slowly move upwards, don't pick random node and only think about it.

  • @maneshwarsingh8688
    @maneshwarsingh8688 3 ปีที่แล้ว +2

    19:55 Wouldn't curr.min = leftInfo.min and curr.max= rightInfo.max directly be applicable instead of comparing with root->data since the said root is already validated to be a BST! So leftInfo.min would always be less than root->data (heck, root->data is greater than leftInfo.max too) and similarly for curr.max also.

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

      yes i also think so... that was not necessary...

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

      I also thought that and it is correct!! What she said is just unnecessary

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

      @Maneshwar Singh No brother we need to do that. Consider a case where a node has only right subtree than in that case curr.min=leftInfo.min will not work because now curr.min is root->data.so we need to that.
      Though that whole line is not required this will do the work
      curr.min=min(leftInfo.min , root->data)

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

      Bro , I asked same doubt in comment section and then I started to search if someone has encountered same doubt or not, then I found you ....So, I think There is no need to write that lengthy stuff

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

      @@adarshdubey1784 There is a need. Look at the comment above

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

    as i am moving forward in this course no. of likes are and views are decreasing
    i guess they are not able to continue in this journey

  • @sanjayswami1155
    @sanjayswami1155 3 ปีที่แล้ว +5

    i think there was no need to right extra conditions for the leaf nodes and it will automatically get calculated , anyone correct me if I am wrong

  • @avronilbanerjee5302
    @avronilbanerjee5302 2 ปีที่แล้ว

    didi you are a legendary person !

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

    bahut sahi ❤❤

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek9398 3 ปีที่แล้ว +1

    IF ROOT ==NULL
    IT NOT ONLY SATISFY THE NO NODE CONDITION BUT IT ALSO SATISFY THE LEAFT NODE CONDITION

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

      Yes,you are right but I cannot understand the logic, can you please explain it?

  • @AmrutanshuMishra-dp1mf
    @AmrutanshuMishra-dp1mf ปีที่แล้ว +1

    i had a doubt when we are updating the value of our curr minimum and maximum cant we simply just say curr.min=left.min and curr.max=right.max as we are checking if the current node is a bst before this ??????

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

    Excellent

  • @shauryashekharsahu7485
    @shauryashekharsahu7485 3 ปีที่แล้ว +5

    Aman bhaiya unacademy m aap padhayenge ya nhi plz bataiye mai bura fas gya hu

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

      🙂😂

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

    Thankyou

  • @hardikagarwal7652
    @hardikagarwal7652 3 ปีที่แล้ว +2

    15 and 30 will not be a BST

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

    Mam, please correct that, curr.min & curr.max if ke bahar hona chahiye..

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

      Kyo?

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

      Does not make a difference anyways. for the other case, you will not be using the values anyways

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

    Student : Notes de de Thakur......

  • @SagarSagar-ym5wx
    @SagarSagar-ym5wx 3 ปีที่แล้ว

    very good

  • @SubhamKumar-fr7gw
    @SubhamKumar-fr7gw 3 ปีที่แล้ว

    paikhana kare me t ek number bate e log

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

    cant we do it like take the inorder then the largest sorted sub array of preorder is no of nodes of largest bst

  • @AlokSingh-jw8fr
    @AlokSingh-jw8fr 3 ปีที่แล้ว +1

    Can anyone please explain me at 12:24 di has made a constructor in structure how's it possible constructors are to be made in classes???????

    • @vasukotadiya6235
      @vasukotadiya6235 3 ปีที่แล้ว +1

      In C++ we can make constructors in structure... You are right but in C language

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

      bro watch full video, it was an error which she corrected at the end

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

    Nice Sir

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

    At last why we are not set the value of curr. Max and curr. Min

  • @AdarshSingh-on5fy
    @AdarshSingh-on5fy 3 ปีที่แล้ว +1

    #include
    using namespace std;
    class node{
    public:
    int data;
    node *left;
    node *right;
    node(int d){
    data=d;
    left=NULL;
    right=NULL;
    }
    };
    class bst{
    public:
    int size;
    int max;
    int min;
    int ans;
    bool isbst;
    };
    bst largestbst(node * root){
    // root is null and size is 0
    if(root==NULL){
    return {0,INT_MAX,INT_MIN,0,true};
    }
    // leaf node condition
    if(root->left== NULL and root->right ==NULL){
    return{1,root->data,root->data,1,true};
    }
    bst left=largestbst(root->left);
    bst right=largestbst(root->right);
    bst curr;
    curr.size=(1+left.size+right.size);
    if(left.isbst and right.isbst and left.maxdata and right.min>root->data){
    curr.min=min(left.min ,min(right.min,root->data));
    curr.max=max(right.max ,max(left.max,root->data));
    curr.ans=curr.size;
    curr.isbst=true;
    return curr;
    }
    curr.ans=max(left.ans,right.ans);
    curr.isbst=false;
    return curr;
    }
    int main(){
    /*
    15
    / \
    20 30
    /
    5
    */
    node *root=new node(24);
    root->left=new node(20);
    root->right=new node(30);
    root->left->left=new node(5);
    cout

  • @adityaagarwal3511
    @adityaagarwal3511 2 ปีที่แล้ว

    why we haven't used public in the structure info

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

    what is the meaning of ans in the list when explaining isn't it the size of the largest BST...then how come it is equal to the root??? I didn't understand that

  • @lavyadav2396
    @lavyadav2396 2 ปีที่แล้ว

    I think on line no. 41 there will be change ----->>> curr.ans = max ( curr.size , max ( leftinfo.ans , rightinfo.ans ) );

  • @shubhamgoel3998
    @shubhamgoel3998 ปีที่แล้ว

    int largestBst(node *root,int *Max,int *Min,bool *isBst) {
    if (root==NULL) {
    *isBst = true;
    return 0;
    }
    int lMax,lMin,rMax,rMin;
    bool isBstLeft,isBstRight;
    int left = largestBst(root->left,&lMax,&lMin,&isBstLeft);
    int right = largestBst(root->right,&rMax,&rMin,&isBstRight);
    *Max = root->data;
    *Min = root->data;
    *isBst = true;
    if (isBstRight == false || isBstLeft == false) {
    *isBst = false;
    return max(left,right);
    }


    if (root->left!=NULL) {
    if (lMax > root->data) {
    *isBst = false;
    }
    else {
    *Max = max(*Max,lMax);
    *Min = min(*Min,lMin);
    }
    }
    if (root->right!=NULL) {
    if (rMin < root->data) {
    *isBst = false;
    }
    else {
    *Max = max(*Max,rMax);
    *Min = min(*Min,rMin);
    }
    }
    if (*isBst == false) {
    return max(left,right);
    }
    return 1+left+right;
    }

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

    comment 0

  • @pradyumn8507
    @pradyumn8507 2 ปีที่แล้ว

    2:20
    4:10

  • @NareshKumawat-w9z
    @NareshKumawat-w9z 11 หลายเดือนก่อน

    this is not applicable in all conditions

  • @pranjalrajput2886
    @pranjalrajput2886 2 ปีที่แล้ว

    Lecture 28.9 is Missing

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

    28.9 lecture??

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

    Can't we just find inorder traversal and check for size of longest increasing sub array in that inorder traversal

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

      It doesnt work that way take a sample input from GFG and dry run your logic

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

      @@azeezmoiz9195 No, i think it will work perfectly just space complexity o(n) ho jayega

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

      @@azeezmoiz9195 even we can do it without using any vector also

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

      @@tarunbisht8016 naah, we can have a case in which two bst subtrees can be combined to give a sorted subarray in a inorder traversal array.

  • @Rohan-ov3fr
    @Rohan-ov3fr 3 ปีที่แล้ว +2

    Bhai kuch samjh bhi aaya kuki mugje ek baar me kuch ni aaya 🥺🥺

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

      Itna easily samjhaya hai fir bhi agar samaj na aaya plz revise kare apni basics

  • @SagarSagar-ym5wx
    @SagarSagar-ym5wx 3 ปีที่แล้ว

    ma'am please send the source code

  • @jaydalsaniya6986
    @jaydalsaniya6986 2 ปีที่แล้ว

    Avaaz bohot Dabi dabi lagg rahi hai

  • @Priyanka_Aarna
    @Priyanka_Aarna 3 ปีที่แล้ว +1

    First one 😊

  • @tanmayjain8542
    @tanmayjain8542 3 ปีที่แล้ว +1

    1st comment

  • @ayushbankia9004
    @ayushbankia9004 3 ปีที่แล้ว +2

    Anyone 12th pcm?

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

      JEE me kitne aaye ?

    • @ayushbankia9004
      @ayushbankia9004 3 ปีที่แล้ว +1

      @@pathikshah bhai bahut kharab aye. 96.2.

    • @pathikshah
      @pathikshah 3 ปีที่แล้ว +14

      Toh padhna JEE ka, idher kya kr rha hai? DSA college me bahut time milega..

    • @girishporwal5183
      @girishporwal5183 3 ปีที่แล้ว +2

      @@pathikshah lol

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

      @@pathikshah LMAO