21 Longest common subsequence Top down DP

Поділитися
Вставка
  • Опубліковано 4 лют 2020
  • Longest Common Subsequence Problem solution using TOP DOWN APPROACH
    Given two sequences, find the length of longest subsequence present in both of them.
    A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous.
    For example, “abc”, “abg”, “bdf”, “aeg”, ‘”acefg”, .. etc are subsequences of “abcdefg”.
    PROBLEM STATEMENT LINK:www.geeksforgeeks.org/longest...
    Playlist Link: • Dynamic Programming | ... .
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3kMohtd
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

КОМЕНТАРІ • 309

  • @shobhaseth2111
    @shobhaseth2111 4 роки тому +72

    Its like you are teaching knapsack all over again! :D

  • @ritiksaini-619
    @ritiksaini-619 4 роки тому +236

    10 am rn
    3rd day of watching your series
    and Now I'm able to write code myself of some questions without you completely explaining it
    Just Superb!!

    • @ketankhandelwal8626
      @ketankhandelwal8626 3 роки тому +7

      Same here.

    • @pranav288
      @pranav288 Рік тому +1

      what's the point of mentioning time

    • @AbhishekYadav-rm4hw
      @AbhishekYadav-rm4hw Рік тому +2

      @@pranav288 He covered these many videos in 2 days, I think this was the point probably .. but who cares

  • @abhisheksoni7405
    @abhisheksoni7405 2 роки тому +63

    At 22:07,
    minute change is needed, in below condition .....j should be J-1, as below.
    t[i][j] = max(t[i-1] [j] , t[i] [j-1]);
    Thanks aditya for superb explanation :)

    • @bite091_jamee7
      @bite091_jamee7 2 роки тому +2

      well u r right but he wrote it many times in video so we should get it by ourselves

    • @sufiyaniqbal5280
      @sufiyaniqbal5280 Рік тому +1

      @@bite091_jamee7 no he wrote so what Abhishek Soni has done write by mentioning this ...thanx aditya

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

      @@sufiyaniqbal5280 as u say

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

      @@bite091_jamee7 bro do u do coding becz i need a coding partner if ur free we can practice together

  • @shubhambansal2161
    @shubhambansal2161 3 роки тому +13

    Bro You are the champ. I haven't seen somebody to explain DP like this. You are doing the great work for the community. Thank you so much. Also, please don't stop making videos, make more content on DSA as everyone should need this kind of explanation.

  • @nityanandbhaskar2155
    @nityanandbhaskar2155 4 роки тому +6

    Thank you very much for this youtube course. I have been rejected at coding interview just because i didn't know how to approach dynamic programming problems. But after practicing it for few months now , I feel confident enough to crack these interviews.

  • @shahkrimabrijesh4650
    @shahkrimabrijesh4650 3 роки тому +3

    This series is awesome based on recursion and memozied version i was able to get the top down without looking at the video in one shot even though i m a newbie to dp.
    salute.

  • @rachanaraut5718
    @rachanaraut5718 4 роки тому +34

    So happy to say that after going through 20 videos, I could code this question even before the 4th minute was hit of this video while simultaneously listening to this video. Thank you Aditya!

  • @HarshSharma-je8rk
    @HarshSharma-je8rk 4 роки тому +170

    Else condition should be t[ i ][ j ] = max ( t[ i - 1 ][ j ], t[ i ][ j - 1 ] ) ; U forgot "-1" in second argument of max function.

    • @TheAdityaVerma
      @TheAdityaVerma  4 роки тому +39

      Yeah, my bad !! Typo !! 😕

    • @bijitashyabirinchi1721
      @bijitashyabirinchi1721 4 роки тому +2

      @@TheAdityaVerma As the size of the matrix is t[m+1][n+1], shouldn't we return t[m+1][n+1] instead of t[m][n] at last?

    • @yadavaditya2932
      @yadavaditya2932 4 роки тому +14

      @@bijitashyabirinchi1721 when we initialize t[m+1][n+1] the array has index from 0 till m and not till m+1 same case with n. Thus we return t[m][n] and not t[m+1][n+1].

    • @ujjwaljain9780
      @ujjwaljain9780 4 роки тому +9

      Search for this comment 😅😅...

    • @koreancaptain2955
      @koreancaptain2955 3 роки тому +19

      @@bijitashyabirinchi1721 you first go and learn 2-D array then come to this

  • @VishalKumar-xr4nm
    @VishalKumar-xr4nm Рік тому +7

    You are great teacher. I was very weak at DP but now after watching your videos, I am able to do most of the problems of DP. 😊

  • @vaibhavm1007
    @vaibhavm1007 4 роки тому +19

    Amazing videos seriously! I was able to do the memoized and bottomup code for this by myself because your explanation of the concepts was so good for knapsack itself! :D

  • @shashwatmahodaya9695
    @shashwatmahodaya9695 4 роки тому +2

    after some months you will have way more viewers than any youTube channel on DP !!
    thanks bruh!!

  • @aayush1204
    @aayush1204 3 роки тому +15

    I was able to write the correct bottom up version of LCS without even completing the video because I've been watching this playlist from the beginning. All thanks to you Aditya 😀😀

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

    After I have seen your KnapSack videos , I didn't even need to see these videos. After understanding the choice diagram , I could do the memoization and tabulation on my own! Thanks to you sir!

  • @arkpandey7679
    @arkpandey7679 4 роки тому +8

    Thanks bhaiya, I was really scared of DP, after watching your series in continuation, I am able to write code and solve DP problems easily.

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

    Best teacher for coding problems. Been following your series and has been eye-opening to say the least!! Awesome work Aditya.
    Thank you.

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

    Great explanation as usual. Just one information. In the DP array towards the "i" dimension we are only referring to at-most 2 rows at a time [i] and [i-1]. So we can create dp array like dp[2][len2+1]; Then we can use modulo operator to reuse this two rows. Memory optimization only O(min(len1,len2))

  • @priyarathore9266
    @priyarathore9266 3 роки тому +3

    Best DP course on internet!

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

    you're explaination of problems are so intuitive that I was able to write code, before you started writing it.

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

    You have explained the concept in a very superb way!! Thanks :)

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

    Solving the problem within 10min but still watch full video dont know why.Thanks buddy its very helpful for us

  • @atharvakalele37
    @atharvakalele37 2 роки тому +1

    Greatest explanation of Dynamic Programming!

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

    I want to thank you so so so so so so so so much man!
    Amazing videos for beginners!!

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

    You know you're a good teacher, when I know how to do this, before starting the video.

  • @ss-ny2oh
    @ss-ny2oh 2 роки тому

    BEST DP series!!!

  • @qR7pK9sJ2t
    @qR7pK9sJ2t 4 роки тому +28

    I never ever thought that I would say this but after @mycodeschool..@AdityaVerma is the next god for CSE students..

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

    Bhai Jeet Gaya Tum!!! OP level teaching!

  • @nknidhi321
    @nknidhi321 2 роки тому +1

    Hands Down !! Thank You.🙌

  • @LearningYouth
    @LearningYouth 2 роки тому +1

    I solved it without watching the whole video...I could solve it because I understood really good in Knapsack time. Thank you Adtiya bhai.

  • @vakhariyajay315
    @vakhariyajay315 Рік тому +1

    Thank you very much.

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

    Sir ,You are just osm ,i wrote Bottom-up(Your Top-Down) Approach without even watching your this video. thanks a lot;)

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

    bhaisaaab maja aagya
    bro ur the best,meri recursion sai bahaut fatjati thi but after watching ur recursion playlist +dp vali matlab ab best muje recursion hi lagg raha hai and dp thx alot bro may god bless u and ur family ....aap jesa teacher ho toh banda kahan sai kahan chala jae...

  • @vinayhegde
    @vinayhegde 2 роки тому +1

    Every time I tried learning DP from any source, used to get confused, and ended up skipping it. With your videos cant stop watching them.. It all makes sense now !! Great going Keep it up!

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

    If DP is an art you are an artist sir

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 3 роки тому +3

    @Aditya Verma Thanks a lot for such a deep insight over these important topics. Please upload more videos on tree and Graphs as well. Thanks

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

    Shat Shat pranam guruji ♥🚀✨
    Able to solve without watching videos asn, watched all previous videos so fundas got strong , thanks 🙏

  • @ritikgupta8478
    @ritikgupta8478 4 роки тому

    Amazing Explanation.!!

  • @Shubh_here
    @Shubh_here 9 місяців тому +1

    Wow sir you are great teacher i had written my code by myself without watching this video thank you so much bhaiya

  • @lifeexplorer2965
    @lifeexplorer2965 4 роки тому +34

    Never seen this kind of approach of converting Memoization to Top down ...
    awesome !

    • @TheAdityaVerma
      @TheAdityaVerma  4 роки тому +14

      Thanks !! Will be uploading more videos in may till then keep sharing to help this channel grow + thats motivates me to make more videos !! ❤️✌️

    • @AnkitKumar-ft5yu
      @AnkitKumar-ft5yu 4 роки тому

      @@TheAdityaVerma sir may is here please upload videos. I am preparing for interview and eagerly waiting for your awesome videos

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

      @@TheAdityaVerma Sir ji august chal rha hai aur videos please daal dijiye, interviews hai samne

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

      @@TheAdityaVerma bro I had a special problem on LCS will you solve it

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

      You should say Memoization to Bottom Up

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

    Explanation is awesome..

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

    Never thought I will learn dp this smooth

  • @crunchworking3601
    @crunchworking3601 11 місяців тому

    Able to solve before watching the video. Thanks a lot Sir

  • @ritikgupta8478
    @ritikgupta8478 4 роки тому +2

    Looking forward for more videos :)

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

    Thank you so much sir🙏❤️

  • @shubhammahindru3563
    @shubhammahindru3563 9 місяців тому

    Some videos are awesome, and other are fantaboulus great to see the videos of LCS after knapsack makes it cherry on the cake, thanks dude thanks a lot

  • @viralonce2671
    @viralonce2671 9 місяців тому

    usually i dont comment but after watching this playlist ,cant stop commenting

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

    Solve Memoise & Bottom-UP by myself, thanks you sir.

  • @subashraj3919
    @subashraj3919 4 роки тому +1

    Good Explanation

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

    This series is recursion without memoization repeating the same thing again and again ..... :) btw nice i came here to learn dp and now expert in recursion and dp.

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

    ek dhum masth explanation🔥

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

    What a guy !! Just love your videos ...plz make some videos on other topics too

  • @umanggupta9950
    @umanggupta9950 4 роки тому +4

    Mast Bhai,
    love from MNNIT

  • @4n3-niteshkumar16
    @4n3-niteshkumar16 2 роки тому

    Dil ko sakun mil jata hai ase video dekhne ke bad 3 video dekha mera all doubt clear ho gaya

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

    Thx a lot man!

  • @piyushyadav2279
    @piyushyadav2279 4 роки тому +1

    nice explanation...

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

    ThankYou!!!!

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

    BEST EXPLANATION

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

    I like when he says: " Bas ho gaya bhai, aur kuchh nahi hai isme"

  • @vishnusaitejanagabandi9009
    @vishnusaitejanagabandi9009 6 місяців тому

    Thankyou sir !

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

    bhaiya i first made the code from by myself then watched it.... thanks to your recursive approach i could make this code by myself..... btw you forgot a -1 at last. thank you bhaiya

  • @pruthvirajk6019
    @pruthvirajk6019 4 роки тому +2

    Awesome!

  • @payelbandyopadhyay2866
    @payelbandyopadhyay2866 4 роки тому +135

    Guruji backtracking mein video banaiye plz. Plz, meri request accommodate karein.

  • @25_minchugowda22
    @25_minchugowda22 3 роки тому

    Your are just awesome❤

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

    maza aa gya bhai video se bohot kch sikhne ko mila,

  • @AJ-gg1jc
    @AJ-gg1jc 3 роки тому

    thanks sir 💌💚

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

    boht badiya padhaya maze aagaye

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

    good explanation bro>>>>

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

    Excellent !

  • @aka_gym_lad
    @aka_gym_lad 4 роки тому

    bhai tu ne best explain kiya

  • @prashant.s.397
    @prashant.s.397 5 місяців тому

    this dude is fire

  • @raviashwin1157
    @raviashwin1157 4 роки тому +1

    halwa bana diya question ko itna asan kaise kar diya bhai,good job bro

  • @Vishal-ds6ly
    @Vishal-ds6ly Рік тому

    thankyou so much sr please make playlist of graph and tree.

  • @aayush5474
    @aayush5474 3 роки тому +5

    happiness is being able to solve the question without even watching the video but i still watch it xD

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

    bro this is bottom up as you also mentioned in a pinned comment in 1st video. Just change the title and description whenever you are free. Video and audio cannot be changed, but title and description can be changed and will avoid confusion for beginners who might come to see your video 1 or 2 years from now once your channel becomes quite big(like abdul bari's channel became big in last couple of years).

  • @sahil1053
    @sahil1053 10 місяців тому

    are bhai shab ye kya kr diya aapne . bina video dekhe hi m question solve kr k aa gya .. itne acche se kon smjhata h

  • @priyanshsoni1401
    @priyanshsoni1401 3 роки тому +58

    Pls change the title to Bottom up -.-

    • @shubham_only
      @shubham_only 3 роки тому +3

      Yeah :)

    • @Manoj-of8nr
      @Manoj-of8nr 3 роки тому +16

      Yes, in his whole playlist he refers to the Tabulation method as Top-down. It should be Bottom-up. Great work Aditya Verma. I highly recommend everyone to watch this playlist to learn DP.
      P.S: Yes, I have watched the whole playlist in a single sitting.

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

      @@Manoj-of8nr
      how much time did it take

    • @jatin1269
      @jatin1269 3 роки тому +6

      his title made me double check on my dp concept xD

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

      @@Manoj-of8nr chal jhoota

  • @VISHALKUMAR-bo9mo
    @VISHALKUMAR-bo9mo 3 роки тому +1

    Please, make a video on finding LCS in O(nlog(n)) time complexity.

  • @kirtxn_
    @kirtxn_ 2 місяці тому

    bhai aditya bhaiya op saxx bhai saaxxxx just loved ur way of teaching brooo 💓💓

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

    Awsome guru

  • @AlbertoRodriguez-oe6jo
    @AlbertoRodriguez-oe6jo 2 роки тому

    As Japanese say on leetcode:
    Take my knees.
    Youu're guru of DSA.

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

    Sir ye to bottom up approach hai kyuki isme apan 0 se upar values daal rahe hain aur pehle wala top down hai na kyuki usme apan n se call karke wo value save kar rahe hain.
    And Sir your content is very good. Keep it up, Thank you.

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

    Thank you for this series. Graph ki bhi bnalo

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

    Please make video on backtracking. I will definitely watch ALL your videos till now.

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

    So smooth

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

    please explain to me what is the need for initialization in the bottom-up approach?

  • @abhimanyuraizada7713
    @abhimanyuraizada7713 Рік тому +1

    Do we have to do bottom up approach in interview mandatorily or just memoisation will work fine?

  • @coderscode5364
    @coderscode5364 4 роки тому +1

    Great

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

    bhaiya toda lighting acha ho jay tohh mazaa a jaye. Otherwise you r GOD

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

    chaa gya bhai 🐱‍🏍

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

    Dude!!! DP simple AF

  • @022_ananyasrivastava8
    @022_ananyasrivastava8 2 роки тому

    21/50 -> 42% done

  • @zehn1022
    @zehn1022 4 роки тому +7

    Can you solve CONTAINS DUPLICATE I, II, III questions of Leetcode?

  • @nainabakolia2044
    @nainabakolia2044 3 роки тому +6

    Please make videos on backtracking and graph too, please :( .

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

    Yes sir backtraking pls!!!!!!

  • @gouravkumar834
    @gouravkumar834 4 роки тому +28

    I think else condition should be like
    T[I] [j] = max( t [i-1] [j], t [I] [j-1] )

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

    Please make a playlist for Backtracking and Branch-Bound

  • @AmanKumar-fd5ec
    @AmanKumar-fd5ec 4 роки тому +4

    the recursive+memoisation code on Leetcode is giving TLE as well

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

      yeah, time constraints of dp questions are very strict in leetcode. Even I solve array questions time limit was not that strict you can easily pass brute force solutions there.

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

      my memoisation code got accepted on leetocode.
      class Solution {
      public int longestCommonSubsequence(String text1, String text2) {
      int m=text1.length();
      int n=text2.length();
      int[][] t=new int[m+1][n+1];
      return lcs(text1.toCharArray(),text2.toCharArray(),m,n,t);
      }
      int lcs( char[] X, char[] Y, int m, int n,int[][] t)
      {
      if(t[m][n]!=0)
      return t[m][n];
      if (m == 0 || n == 0)
      return 0;
      if (X[m-1] == Y[n-1])
      return t[m][n]=1 + lcs(X, Y, m-1, n-1,t);
      else
      return t[m][n]=Math.max(lcs(X, Y, m, n-1,t), lcs(X, Y, m-1, n,t));
      }
      }

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

      Try passing your string by reference. Due to recursive calls by value, it takes some time to create the same string at all function calls. In tabulation there are no recursive calls, therefore it passes.

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

    Plz give dronacharya award to this guy.

  • @kingshukpal301
    @kingshukpal301 4 місяці тому +1

    this question is is also one of the question which gives tle on solving it using memoization and not tabulation

  • @gamersgame43
    @gamersgame43 3 місяці тому

    This is bottom-up approach or also called as tabulation as we start solving from base cases (smaller subproblems) and go towards solving large problem

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

    U r god bro god 🙏🙏