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

Поділитися
Вставка
  • Опубліковано 17 жов 2024

КОМЕНТАРІ • 85

  • @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.

  • @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

  • @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))

  • @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 ...... :)

  • @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

  • @hustlinggeeks840
    @hustlinggeeks840 3 роки тому +17

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

  • @adityakeshari2295
    @adityakeshari2295 3 роки тому +9

    at 13:48 2nd one is not a BST

  • @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

  • @adityabhandari6688
    @adityabhandari6688 3 роки тому +16

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

  • @sohangajjar1106
    @sohangajjar1106 3 роки тому +14

    this code is very complex to understand.

  • @sscode3809
    @sscode3809 2 роки тому

    Very good explanation di👍👍✨✨

  • @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

  • @yashasvi9301
    @yashasvi9301 3 роки тому +8

    hello to people waiting

  • @varunchoudhary8797
    @varunchoudhary8797 3 роки тому

    Students k liy Aman Dhattarwal se best koi nhi 😍

  • @amansrivastava1232
    @amansrivastava1232 3 роки тому +4

    13:53 possible BSTs 2nd BST is wrong

  • @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......

  • @dhruvsakariya3129
    @dhruvsakariya3129 Рік тому +3

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

  • @hustlewithVaibhav
    @hustlewithVaibhav 3 роки тому +1

    Thank you 🙏🙏

  • @gadgetnation973
    @gadgetnation973 3 роки тому +2

    Bhaiya notes kab milege

  • @rutvikrana512
    @rutvikrana512 3 роки тому +2

    Thank You Apna College For This Amazing Lecture :)

  • @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

  • @CodingMonster23
    @CodingMonster23 7 місяців тому

    Notes Please

  • @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).

  • @shivamdalania
    @shivamdalania 3 роки тому +2

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

  • @jaigaur1303
    @jaigaur1303 3 роки тому

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

  • @avronilbanerjee5302
    @avronilbanerjee5302 2 роки тому

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

  • @varunchoudhary8797
    @varunchoudhary8797 3 роки тому

    Very nice 👍👍

  • @jyotipandey3156
    @jyotipandey3156 3 роки тому

    Guyzzz how willl we get the notes ...🙄

  • @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

  • @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

  • @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

  • @hostellifeofengineers9319
    @hostellifeofengineers9319 3 роки тому +1

    Mam please upload notes

  • @jiosim1377
    @jiosim1377 3 роки тому +1

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

  • @madhavgupta2002
    @madhavgupta2002 2 роки тому

    what is the name of the instructor?

  • @mukeshkumarranjan8584
    @mukeshkumarranjan8584 Рік тому

    N=3 then only 4 BST Tree make

  • @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

  • @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

  • @akbar55555shaikh
    @akbar55555shaikh 3 роки тому

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

  • @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

  • @prem_ium
    @prem_ium 3 роки тому

    please make python lectures too...

  • @ritwickrana3255
    @ritwickrana3255 2 роки тому

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

  • @BeingEntertained
    @BeingEntertained 3 роки тому

    code ka dry run to karado

  • @mananmaheshwari3839
    @mananmaheshwari3839 3 роки тому

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

  • @hopesalive2145
    @hopesalive2145 2 роки тому

    *999k*

  • @deepakagrawal9248
    @deepakagrawal9248 2 роки тому

    very difficult to understand

  • @ShivamRaj-dt9zm
    @ShivamRaj-dt9zm 3 роки тому +1

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

  • @biplobphukan5815
    @biplobphukan5815 Рік тому

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

  • @adityaagarwal2324
    @adityaagarwal2324 3 роки тому +1

    After 19:00 khucch samaj nahi aaya :(

  • @BeingEntertained
    @BeingEntertained 3 роки тому

    vector to dhang se padha do

  • @piyushkumarjha475
    @piyushkumarjha475 2 роки тому

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

  • @sanketdawange
    @sanketdawange Рік тому

    Dtcj

  • @biplobphukan5815
    @biplobphukan5815 Рік тому

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