Longest Common Subsequence

Поделиться
HTML-код
  • Опубликовано: 29 ноя 2024

Комментарии • 554

  • @nikkis8102
    @nikkis8102 Год назад +3

    I'm here 8 years later! I need him to go through all the Leetcode 75! 😃

  • @chenjus
    @chenjus 3 года назад +79

    This is the clearest, complete, and most concise explanation of longest common subseq I've seen so far. Thank you so much!

  • @ketan4221
    @ketan4221 6 лет назад +120

    Tushar's favorite line - `Yes, we will use dynamic programming to solve this ;)`

    • @shashanksagarjha2807
      @shashanksagarjha2807 4 года назад

      please check this playlist : ruclips.net/p/PLeF0b8iqbx4mogykbd82-HY9Y1-JS9MDr

    • @kurchak
      @kurchak 3 года назад +5

      haha I always loved that too.

    • @amanrubey
      @amanrubey 2 года назад

      😂😂😂❤

  • @dakshjay
    @dakshjay Год назад +1

    Just wanted to revisit Tushar's videos after completing my employment of 4 years at Google in the Bay Area. big thanks to you Tushar to help me with this and other challenging problems!

  • @thesoftwareman
    @thesoftwareman Год назад +2

    I still come back to this video years later after tripling my SWE salary, priceless content

  • @amanrubey
    @amanrubey 2 года назад +7

    The best part about his lectures are that the way he demonstrates things makes our brain automatically figure out why we are doing this and this is what no other channel on RUclips provides.
    I'm really thankful to Tushar for making iterative dp my second nature 🙏🏼❤

  • @GameKeppers
    @GameKeppers 8 лет назад +107

    reading wikipedia for ages...
    finnaly with your video i do understand the sequence so thank you very much:)
    greetings from Germany:)

    • @RagazzoKZ
      @RagazzoKZ 5 лет назад

      GameKeppers haha, same situation

    • @shashanksagarjha2807
      @shashanksagarjha2807 4 года назад

      please check this playlist : ruclips.net/p/PLeF0b8iqbx4mogykbd82-HY9Y1-JS9MDr

  • @niqbal81
    @niqbal81 7 лет назад +5

    Love, how knowledgeable and clear as a teacher you are. Absolutely in debt. Much respect

  • @NehaJain1704
    @NehaJain1704 9 лет назад +35

    Nothing on the net has made DP more easier..thanks a ton!! :)

  • @rma1563
    @rma1563 6 месяцев назад

    took only 8 minutes to explain what most take 20+ minutes. And you did it great. cleared up everything. Thanks

  • @prashantganeshsamudrala626
    @prashantganeshsamudrala626 4 года назад

    One of the Best explanations I have heard so far in coding

  • @anshusharma11
    @anshusharma11 8 лет назад +2

    All your videos are just awesome. You explain every detail so clearly . I like that you don't rush the things.

  • @satishchandra6623
    @satishchandra6623 3 года назад +1

    The video that started my interest in dynamic programming. Seen this video 4 years ago in 2017 for the first time and with one example I got the whole idea about Dynamic programming. After that I'm able to solve most of the coding problems using Dynamic Programming approach.

  • @ashishgadre
    @ashishgadre 8 лет назад +5

    I think there needs to be more explanation on why there is a max used when the last char don't match. The reason is explained very well in the following section of the wiki page:
    en.wikipedia.org/wiki/Longest_common_subsequence_problem#Second_property
    Suppose that the two sequences X and Y do not end in the same symbol. Then the LCS of X and Y is the longer of the two sequences LCS(Xn,Ym-1) and LCS(Xn-1,Ym).
    To understand this property, consider the two following sequences :
    sequence X: ABCDEFG (n elements)
    sequence Y: BCDGK (m elements)
    The LCS of these two sequences either ends with a G (the last element of sequence X) or does not.
    Case 1: the LCS ends with a G
    Then it cannot end with a K. Thus it does not hurt to remove the K from sequence Y: if K were in the LCS, it would be its last character; as a consequence K is not in the LCS. We can then write: LCS(Xn,Ym) = LCS(Xn, Ym-1).
    Case 2: the LCS does not end with a G
    Then it does not hurt to remove the G from the sequence X (for the same reason as above). And then we can write: LCS(Xn,Ym) = LCS(Xn-1, Ym).
    In any case, the LCS we are looking for is one of LCS(Xn, Ym-1) or LCS(Xn-1, Ym). Those two last LCS are both common subsequences to X and Y. LCS(X,Y) is the longest. Thus its value is the longest sequence of LCS(Xn, Ym-1) and LCS(Xn-1, Ym).

  • @ashdavv
    @ashdavv 8 лет назад

    Superb explanation .. If i am stuck in any problem then instead of google just finding your solution for the problem is the best thing.. Thanks ..

  • @aryankhare9393
    @aryankhare9393 4 года назад

    Your way of teaching makes me visualise things and I really want to thank you for this.

  • @T1Oracle
    @T1Oracle 6 лет назад +1

    Learning how to use a matrix to solve these kinds of questions was a real break through for me. That visualization is better than seeing code, now I can write it any language easily.

  • @ameychavan70
    @ameychavan70 2 года назад +1

    One of the best explanations I ever saw on this topic !!.... Thank you very much sir 😀 👏🏻👏🏻

  • @1234padrino
    @1234padrino 6 лет назад +12

    I wonder how my teachers can explain such simple algorithms in a way that noone understands it. I learned all algorithms from indian students. Thx, I love you man

  • @yanzheng2147
    @yanzheng2147 5 лет назад

    Supper clear! After watching your explanation, I am able to finish the code within 5 min! Thank you!

  • @nathant6010
    @nathant6010 3 года назад +1

    Thank you Tushar. I am sure that no one have explained Dynamic Programming this simple and straightforward. Even we may not be able understand how the values are filled in the DP array dynamically in other explanations. Most of them are always very simple Fibonacci example or very high level. So, for anyone who would like to understand Dynamic Programming, your videos are the best.

  • @GoldenSpud
    @GoldenSpud 6 лет назад

    You are an absolute champion, your answer and explanation was really clear great job.

  • @manhhungnguyen5661
    @manhhungnguyen5661 Месяц назад

    This is the clearest explanation I've seen, thank u so much guy !!!! 🥰

  • @deepTh00ught
    @deepTh00ught 4 года назад +1

    Tushar you are such a good human, thank you a lot

  • @MagigeChacha
    @MagigeChacha 4 года назад

    This is the best explanation for LCS problem so far. You are great bro.

  • @malinisai5297
    @malinisai5297 9 лет назад +21

    I learned most of the stuff from your videos, sir. It's quite helpful.Thank you so much.

  • @jaideepbommidi8611
    @jaideepbommidi8611 9 лет назад

    thank you very much I was able to understand everything.
    i was able to see how the already computed values were used for the calculation avoiding the redundancy, which is clearly a dynamic programming concept.
    thank you for such a wonderful video. Hope you help us more.

  • @vikramadityakukreja4795
    @vikramadityakukreja4795 9 лет назад +7

    Nicely explained and easy to understand . Thanks a lot!

  • @RafaelNascimento-qo1jp
    @RafaelNascimento-qo1jp 2 года назад

    BEST explanation on this topic so far!

  • @ericren4909
    @ericren4909 9 лет назад +2

    Thanks I'm making progress on my interview skills. Awesome tutorials.

  • @aggreym.muhebwa7077
    @aggreym.muhebwa7077 7 лет назад

    +1 for explaining DP in such an easy way. Thanks alot

  • @gauravkumarsingh3234
    @gauravkumarsingh3234 7 лет назад

    I must say your videos are very helpful... I consider only your videos for my Data structure and algorithms exams preparation..

  • @minhthinhhuynhle9103
    @minhthinhhuynhle9103 2 года назад

    You are the best lecturer I currently found on RUclips to teach hard problem using Advance Technique. No one else can eplain in short, precise & natural as you Tushar !!!
    > This will always be your punchline "The best we can do WITHOUT". And it's damn easy to understand in Natural Language rather than cold codes.

  • @creatcodebuild7180
    @creatcodebuild7180 6 лет назад +1

    2018 Anyone? This is one of the most elegant DP with backtracking table algorithms.

  • @deepakbisht7764
    @deepakbisht7764 8 лет назад +16

    THKS man you just save my Semester

  • @robertsun5529
    @robertsun5529 8 лет назад

    Very clear little tutorial! Nice job and thanks!!

  • @WassupCarlton
    @WassupCarlton 7 месяцев назад +1

    good stuff my guy. question: do we NEED the row and column that's full of zeros?

  • @yvestuyishime5209
    @yvestuyishime5209 7 лет назад

    well, i don't know how i could pass quizzes without your videos :( I've been using your videos for most of algorithms and they are ease to understand and not time consuming compared to the time i could spend reading the book and sometime don't even understand the pseudo-code itself. THANK YOU, THANK YOU AND THANK YOU ONCE MORE.

  • @Aldrasio
    @Aldrasio 6 лет назад

    Great explanation, this makes dynamic programming much easier to understand.

  • @shingo9302
    @shingo9302 5 лет назад +3

    Feels so good to finally understand this, thank you!

  • @OdiyaS
    @OdiyaS 8 лет назад +1

    great video! saved me hours of trying to understand the slideshow from class!

  • @Firecloak
    @Firecloak 4 года назад

    clear, short explanation. Thank you so much!

  • @MarvinsRoom_
    @MarvinsRoom_ 4 года назад +1

    Good tutorial. Very articulate and clear 🙏

  • @TheOscarJB
    @TheOscarJB 6 лет назад

    once again, thank you for your teaching, it is easier to understand, compared to my professor's teaching

  • @khalednaami2
    @khalednaami2 6 лет назад

    After searching LCS a lot on the web, finally I found an easy explanation. Thanks a lot.

  • @deansonnier1167
    @deansonnier1167 6 лет назад +1

    What a fantastic lesson! Thank you, Tushar.

  • @alifhasnain3200
    @alifhasnain3200 6 лет назад

    You make every topic very easy to understand. Thanks. :)

  • @Mankind5490
    @Mankind5490 8 лет назад

    Excellent Explanation. Thank you Tushar!

  • @manantank
    @manantank 7 лет назад +1

    i have passed the algorithm subject just by watching your videos... thanks a lot !!

  • @partha95123
    @partha95123 8 лет назад

    Very good tutorials. Thanks a lot Tushar for the video.

  • @dailydestress6189
    @dailydestress6189 3 года назад

    Explained so simply. Thanks a lot.

  • @aditijain515
    @aditijain515 9 лет назад +18

    You have explained all DP problems very well...thanks a ton :)

  • @gaiusjuliuscaesar9296
    @gaiusjuliuscaesar9296 2 года назад

    Great explanation of the process, thanks!

  • @satang500
    @satang500 9 лет назад +2

    I've been looking at lots of lecture notes, tutorials and videos in the Internet to understand DP, but couldn't clearly understand until I watched your video. Your approach of DP is the best I've ever seen and now I'm confident in DP. :)

  • @harinijeyaraman8789
    @harinijeyaraman8789 4 года назад

    Love your videos Tushar ! Thanks ! really appreciate your efforts

  • @ParagAwadhiya
    @ParagAwadhiya 6 лет назад

    Thanks Tushar, you've made it so simple to understand.

  • @BrianOndieki9
    @BrianOndieki9 9 лет назад

    Thank you, you really make DP very easy to understand

  • @jesusantoniososaherrera2217
    @jesusantoniososaherrera2217 8 лет назад

    Very clear and easy to understand.
    Cheers !!!

  • @prateekyadav1109
    @prateekyadav1109 9 лет назад

    your videos are really helpful and you are doing a noble job.

  • @suryamp12
    @suryamp12 9 лет назад

    Dude, I really like your videos. Super helpful during prep. I hope you're having fun at your workplace but you should consider doing this fulltime ;)

  • @apbh
    @apbh 7 лет назад +1

    It would be helpful if you could explain how you arrive at conclusion of solving a given problem using DP? The thought process and finding DP properties in a given problem.

  • @dimitrisdimitriou6969
    @dimitrisdimitriou6969 6 лет назад

    The best explanation on LCS

  • @brandonfenske3282
    @brandonfenske3282 2 года назад

    finally a clear demonstration of LCS

  • @irynasherepot9882
    @irynasherepot9882 4 года назад

    Thank you Tushar, your tutorial are great and helped me a lot!

  • @serhiypidkuyko4206
    @serhiypidkuyko4206 6 лет назад +1

    Hi Tushar
    Thank you for your video
    As for the code: you don't need to create the matrix
    Here is the code in python:
    #
    def longest_common_subseq_(s,t):
    n=len(s)
    result=[0]*(n+1)
    for x in t:
    row=[0]*(n+1)
    for j in range(n):
    if x==s[j]:
    row[j+1]=result[j]+1
    else:
    row[j+1]=max(row[j],result[j+1])
    result=row
    subseq=''
    indices=[]
    for j in range(n):
    if result[j]

  • @johnbrown903
    @johnbrown903 6 лет назад

    ive learned alot from your vids of dynamic programming. Thanks man

  • @jayeshkawli
    @jayeshkawli 5 лет назад

    Amazing video. Would have taken me an entire day had I gone through online sources. This cleared all the things in less than 10 minutes. Thank you so much!!

  • @Jaqen_Hghar
    @Jaqen_Hghar 7 лет назад

    Thanks a lot, your videos are really very nice and clear. Helping me a lot in my Algorithm course.....

  • @sureshchowta
    @sureshchowta 8 лет назад

    Thank you for these videos on Dynamic Programming...

  • @thaneshwarsahu1633
    @thaneshwarsahu1633 7 лет назад +1

    yes sir , your explanation process is very good and I'm very easily understand this tricky concepts
    thank you very much sir

  • @rudolferemyan8133
    @rudolferemyan8133 8 лет назад +157

    Thnx a lot... it's so easy to understand and implement and not try to memorize a code When you have Cool teacher like you)) One more time THNX))

    • @akshaychatterjee3328
      @akshaychatterjee3328 7 лет назад +19

      do u memorize code generally?

    • @cantwaittowatch
      @cantwaittowatch 7 лет назад +2

      its our great teachers in colleges who passed this wealth of memorization knowledge with out giving an explanation like this which makes algorithms difficult to learn. I'm not surprised to hear these comments. I'm glad Tushar is doing such a wonderful job here. Kudos to him!!

    • @avinashtripathi4159
      @avinashtripathi4159 7 лет назад

      Rudolf Eremyan is this algorithm o(n)?

    • @miltonkumar3655
      @miltonkumar3655 7 лет назад

      O(nm)

    • @avinashtripathi4159
      @avinashtripathi4159 7 лет назад

      MILTON KUMAR exactly! And that is not linear time

  • @accelator007
    @accelator007 4 года назад

    By far the best video on this topic.

  • @pdppradeep
    @pdppradeep 7 лет назад

    You made it look some simple tushar!, you are a great teacher., thanks.

  • @DeepakSingh-uf5vv
    @DeepakSingh-uf5vv 7 лет назад

    thankyou so much sir ,cant explain the happiness in words

  • @javadoctor101
    @javadoctor101 7 лет назад

    To everyone who is saying that he is NOT explaining the reasoning, please listen closely and pause at 4:50. He explains at 4:50 why we add 1+ diagonal when chars are same and why we do max(left,top) when they are different.

  • @kalpkumudkumar8163
    @kalpkumudkumar8163 6 лет назад

    nailed bro .... thanks I was struggling with this problem .. now it is much clear .

  • @SmartProgramming
    @SmartProgramming 6 лет назад

    great sir, thanks a lot for this tutorial, keep it up 👍👍👍👍🙂🙂

  • @otalgebra4436
    @otalgebra4436 3 года назад

    Just remember that once you have a match you cannot match anymore down the row.

  • @joydas1685
    @joydas1685 6 лет назад

    Awesome explanation sir. Enjoyed it.

  • @hamzasaeedsippal
    @hamzasaeedsippal 6 лет назад

    thanks. simply and clearly defined.

  • @manavjain5923
    @manavjain5923 8 лет назад +163

    why don't you first explain the mathematical logic and then solve the problem?And also how to derive the logic

    • @nitinjaiman
      @nitinjaiman 7 лет назад +24

      The key to derive the logic is to solve a very small test case yourself and make the matrix by using your brain(without any formula), as test case is small you can use your brain to solve it and populate matrix. Once you have the matrix you have to figure out where does ith value is coming from. On closely analysing the matrix you will figure out how the previous results are being reused. You can now derive a formula for that and write code.

    • @Jack-gu4fc
      @Jack-gu4fc 7 лет назад +43

      I can't speak for anyone else, but when I'm learning this kind of stuff I usually have some sort of textbook that proves these algorithms mathematically. However, it can get a bit hard to grasp just HOW the algorithm is actually solving it through pure pseudocode or induction alone. So, I usually watch these videos first just to get a basic understanding of the algorithm in action which then helps me better contextualize mathematical/logical learning.

    • @neerajjoshi9493
      @neerajjoshi9493 7 лет назад +1

      which textbook you use? i also need to get one.

    • @renatomelo2249
      @renatomelo2249 7 лет назад

      look for Introduction to Algorithms

    • @1tahirrauf
      @1tahirrauf 7 лет назад +3

      "Algorithms unlocked" by Cormen explains the problem and solution logic in beautiful manner. See "Algorithms on String" chapter.

  • @miladnaderi4169
    @miladnaderi4169 9 лет назад

    thank you very much you helped me pass algorithms man

  • @hrishikeshwaikar251
    @hrishikeshwaikar251 8 лет назад

    Very well explained . Thanks for simplicity!

  • @PeculiarPI
    @PeculiarPI 6 лет назад

    Thanks!! You have made a really nice tutorial.

  • @chandrashekar-pb8ym
    @chandrashekar-pb8ym 7 лет назад

    LCS is used to get the distance between the words. We can use this to find K-palindrome
    too. The key is, use the same string as reverse and find the distance using this also, if zero then they are palindrome if not it will give the distance k to be palindrome. Note as we are using the same string in reverse, dropping the K characters will result in palindrome

  • @cook9256
    @cook9256 6 лет назад

    It is so clear now after watched this video. Thanks!!

  • @DanT-iu6oc
    @DanT-iu6oc 3 года назад

    Jesus christ they need to honor this man with a nobel peace prize

  • @colepeterson5392
    @colepeterson5392 2 года назад

    Oh my goodness I may just pass the final tmrw. Thank you.

  • @mohanabalandhanabalan5880
    @mohanabalandhanabalan5880 6 лет назад

    Good explanation. able to understand clearly . thanks a lot

  • @punjabitadka1594
    @punjabitadka1594 3 года назад

    had to watch at 0.75x speed bt understood completely thank you man

  • @camccorm
    @camccorm 8 лет назад +4

    Thank you so much for this video, you explained it very well! Much appreciated!

  • @dein0522
    @dein0522 7 лет назад

    wow you taught better than my professor in my graduate school

  • @YogeshPateliOS
    @YogeshPateliOS 9 лет назад

    Great it's clear lesson,,,,,,,thank you turshar roy

  • @dighechinmayt
    @dighechinmayt 7 лет назад

    Thanks Tushar, your video lectures help me a lot in studies.So much clearly explained! :)

  • @yovomanolov96
    @yovomanolov96 7 лет назад

    Thank you very much , keep "walking" with the great content !

  • @georgekontorousis132
    @georgekontorousis132 5 лет назад

    Very helpful and easy to understand. Thanks

  • @ralphhouthoofdt3505
    @ralphhouthoofdt3505 8 лет назад

    Thanks alot for this excellent walkthrough.

  • @shivamrohilla9379
    @shivamrohilla9379 6 лет назад

    thanks a lot bro
    keep making these types videos
    very helpful in clearing concepts

  • @aashishrulz
    @aashishrulz 8 лет назад

    thanks alot for the videos, helps me alot to understand Dp and Network flow.
    thanks again

  • @varunkumar3594
    @varunkumar3594 8 лет назад

    These videos are enjoyable, you rock man