Catalan Numbers Application | C++ Placement Course | Lecture 28.6

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

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

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

    If someone has difficulty in understanding the code then follow these steps :
    1. dry run on paper with start =1 and end =1
    2. dry run on paper with start=1 and end =2
    Now finally,
    3. dry run on paper with start =1 and end =3
    You will definitely understand the concept and code after these 3 steps.

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

    We MUST use DP or Memoization in such kind of problems.
    1) DP approach for catalan Numbers :-
    int catalan(int n){
    int dp[n+1];
    dp[0] = 1;
    dp[1] = 1;
    for(int i=2;idata += s;
    inOrderChange(root->right,s);
    }
    Node* copyNode(Node* root,int s){
    if(!root)return NULL;
    Node* n = new Node(root->data+s);
    n->left = copyNode(root->left,s);
    n->right = copyNode(root->right,s);
    return n;
    }
    vector possibleBST(int N,unordered_map &memo){
    if(memo.find(N)!=memo.end()){
    return memo[N];
    }
    vector bsts;
    for(int i=0;ileft = j?copyNode(j,0):NULL;
    n->right = k?copyNode(k,(i+1)):NULL;
    bsts.push_back(n);
    }
    }
    }
    memo[N] = bsts;
    return memo[N];
    }
    vector allPossibleBST(int start,int end){
    unordered_map memo;
    vector v;
    v.push_back(NULL);
    memo[0] = v;
    vector vv;
    vv.push_back(new Node(0));
    memo[1] = vv;
    vector bsts = possibleBST(end-start+1,memo);
    for(auto i:bsts){
    inOrderChange(i,start);
    }
    return bsts;
    }
    Note That We cant use 2D array as memo because memo[0][2] or memo[5][7] have same BST with just different numbers, besides no overlapping is occurred for any start and end numbers, only their differences are overlapped. So we will use 1D array / map for memo and change BSTs numbers with inOrderChange() function.
    Happy Learning ...... :)

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

    at 13:48 2nd one is not a BST

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

    *Correction at 13:36 - the 2ndTree is not a valid BST and the correct version of this will be simply :
    1
    \
    3
    /
    2

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

    Sir your videos are a real help sir you are doing a great job.
    Lots of love and blessing for what you are doing.Cant wait for your job

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

    the formula of catalan numbers is wrong, it should be Cn+1 = Σ(CiCn-1) or Cn = Σ(CiCn-i-1)

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

      pin this comment

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

      Yes that's why I was not getting c2 value correct .

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

      Cn+1= sigma CiCn-i hona chaheye shayad 1 ki jagah i hoga bro

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

    this code is very complex to understand.

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

    One line python code to generate Catalan numbers,
    catalan = lambda n: 1 if n==0 or n==1 else sum(catalan(n-1-i)*catalan(i) for i in range(n))

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

    *Much love and Respect to whole Apna College team for providing this content on TH-cam.* ♥️
    Keep Hustling 🔥

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

    Thank you so much Aman bhaiya and team!!

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

    my code for the catalan sequence looks like this and is better in some way as the values are not getting calculated individually every time
    but using that same values we already calculated in previous iteration
    space complexity increased in my code :
    int catalanUtil(int arr[], int i, int n) {
    if(i < 0) {
    return 0;
    }
    int ans = arr[i]* arr[n] ;
    n++;
    i--;
    ans += catalanUtil(arr, i, n);
    return ans;
    }
    void catalanNum(int n) {

    int c0 = 1;
    int c1 = 1;
    int arr[n];
    arr[0] = 1;
    arr[1] = 1;
    for( int i=2; i

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

    hello to people waiting

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

    13:53 possible BSTs 2nd BST is wrong

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

    Koi last code ko samjha do pls

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

      bhai kaafi logo ko samajh nhi aaya last wala, mujhe bhi nahi aaya

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

    Thank you 🙏🙏

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

    if u r seeing this for the first time, then rewatch this, u probably won't get this fully in 1st watch

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

      Did u understand in second watch?

    • @aishwarywasnik1548
      @aishwarywasnik1548 3 หลายเดือนก่อน +1

      @@jiosim1377 Nice Question!!

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

    Very good explanation di👍👍✨✨

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

    **The formulae of Catalan number was incorrect.Cn-i-1 should be there instead of Cn-i.

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

      The formula of Catalan Number is (Ci-1)*1*(Cn-i) when i goes from 1 to n.
      and
      The formula of Catalan Number when i goes from 0 to n-1 as in this video is (Ci)*1*(Cn-i-1).

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

    How many times are you going to repeat preorder ? It's okay to copy paste.

    • @CarlJohnson-cb9xm
      @CarlJohnson-cb9xm 3 ปีที่แล้ว +1

      Video ki length jitni jada ho utne jada pese milte h neha didi ko

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

    1:40
    4:10
    8:42
    9:09
    13:40
    15:30
    16:20
    21:20
    23:00
    24:00
    24:20
    25:00

    • @grossHumiliation
      @grossHumiliation 10 หลายเดือนก่อน

      Kehna kya chahte ho😂

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

    Thank You Apna College For This Amazing Lecture :)

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

    constructTrees was complicated. I don't understand the explanation 😥

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

    Students k liy Aman Dhattarwal se best koi nhi 😍

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

    I think the recursive sequence for Catalan number is wrong at 1:32

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

    At 16:05 why the possible BST are two only, 3 can be connected in the term 1 in more 2 possible ways......

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

    Very nice 👍👍

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

    Bhaiya notes kab milege

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

    N=3 then only 4 BST Tree make

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

    Mam please upload notes

  • @mr.jyotiranjankalta8098
    @mr.jyotiranjankalta8098 3 ปีที่แล้ว +3

    anyone continue this series please comment ...

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

      yes, what do you want?

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

      @@adityabhandari6688 bro are you able to understand the last code if yes can u explain?

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

      @@jiosim1377 no, i didn't understand last program so I skipped it. Also it is better to use dynamic programming in such questions which we will study at a later stage

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

      @@adityabhandari6688 bro btw how has your progress been so far with this course? R u practicing questions side by side or only doing the questions from this course?

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

      @@adityabhandari6688 bhai mujah bhi samaj nahi aaya :( ........mere kuch oor print ho raha ha

  • @CodingMonster23
    @CodingMonster23 6 หลายเดือนก่อน

    Notes Please

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

    Sir mene B.A programme kar rakhi h but mujhe web development me interest h kya mujhe bhi amazon jesi company me job mil sakti h. Plzz video on this topic bahot saare students h jo non technical se but une web creation or web development aati h or usi me career banana chahte plzz sir es par jarur video banao

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

    the second figure is wrong in 13:54 how can be 3 left child of 2

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

    Why am i not able to understand the logic of the last code written? Is it only me?

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

    please make python lectures too...

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

    I think this video suppose to be possible binary trees, not BST

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

    Pls somebody help me My VS-code is not running in the terminal it's showing that final link failed:No space left on device .

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

      there are many errors and problems to be faced in VS-code , i would suggest u to use GDB online compiler

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

      space compkexity zayada hoga(memory leak hona ka karan) ya harddisk tumhara full hogaya ha

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

    oye i am ritwik ran hope i get placed to product based scene

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

    Formula to calculate the next Catalan Number is wrong #correction at 1:15.

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

    *999k*

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

    C2 or C3 upper jo mathematical definition btai h usse satisfy nhi kr rha...kya h ye

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

    very difficult to understand

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

    I tried to optimise this method
    now loops runs from 0 to (n/2) [so i think].
    and it is giving right ans too.
    can someone tell me is optimized or not?
    int catalan(int n){
    if(n

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

    code ka dry run to karado

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

    what is the name of the instructor?

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

    Ia this course good or does the content become worser as we proceed??

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

      yeah it is good, but you have to practice questions sideways as well

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

    Guyzzz how willl we get the notes ...🙄

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

    pehle khud samjhiye uske baad dusre ko samjhaiye...(BST)

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

    Dtcj

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

    Worst Explanation, after watching this i am more confused now :)

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

    After 19:00 khucch samaj nahi aaya :(

  • @ShivamRaj-dt9zm
    @ShivamRaj-dt9zm 3 ปีที่แล้ว +1

    In 2nd example at 13:45 shouldn't it be
    1
    \
    3
    /
    2
    ?

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

    vector to dhang se padha do

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

    pehle khud samjhiye uske baad dusre ko samjhaiye...(BST)