Longest Common Subsequence Dynamic Programming : Interview question

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ธ.ค. 2024

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

  • @arjun9951
    @arjun9951 6 ปีที่แล้ว +29

    Vivek -- I don't know what I would do without your explanations. You are the best algorithms teacher on TH-cam. You are the best I've ever seen. Keep doing what you're doing, it's helping a lot of people!

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

      i know im asking randomly but does anyone know of a method to get back into an instagram account?
      I was stupid lost my login password. I would appreciate any tips you can give me.

  • @kennash4916
    @kennash4916 7 ปีที่แล้ว +9

    Sir, Your videos on Dynamic programming are awesome. Please make following videos if possible, Sir :
    1) Given a string, determine if a permutation of the string could form a palindrome.
    2) Count All Palindrome Sub-Strings in a String
    3) Find all distinct palindromic sub-strings of a given string
    4) Longest common substring
    5) Longest Palindromic Substring
    6) Print all palindrome permutations of a string
    7) Print all palindromic partitions of a string

  • @lawbindpandey402
    @lawbindpandey402 4 ปีที่แล้ว

    One of the best Algorithm teachers available on you tube !! Simply ,loved it !!

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

    Haven't seen better teacher than you. Thanks for your 📹 🙏🙏

  • @quangle9049
    @quangle9049 7 ปีที่แล้ว +5

    Thanks Vivekanand for your nice video. In my opinion, you should provide some explanation to the audience about why
    - choosing the diagonal cell + 1 in the case of two characters are the same (for example LCS(x[m], y[n]) = LCS(x[m-1], y[n-1]) + 1 and (m-1, n-1) is the diagonal cell position);
    - choosing the max of the upper row, same column as LCS(x[m-1], y[n]) and same row, left column as LCS(x[m], y[n-1]) when two characters are different.

  • @AnandKumar-wk4os
    @AnandKumar-wk4os 6 ปีที่แล้ว +5

    This video clear all confusion of LCS .
    well explanation

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

    Very well explained.It was easy to understand LCS after watching this video.

  • @premprakash8220
    @premprakash8220 6 ปีที่แล้ว

    really you deserve it.you teaches in so simple and easy manner.

  • @SanthoshKumar-nj8mm
    @SanthoshKumar-nj8mm 4 ปีที่แล้ว

    Great Explanation sir.This is really useful for many please dont stop this

  • @rebelutionarygaming8875
    @rebelutionarygaming8875 7 ปีที่แล้ว

    I like your explanations. Also its nice to see how you have changed since early videos like this till now. Looking forward to new videos soon.

  • @amitrawat2915
    @amitrawat2915 5 ปีที่แล้ว

    Bro!!!!!😍.....itna ache se koi kese smjha skta hai.

  • @Karan-ms5es
    @Karan-ms5es 6 ปีที่แล้ว +1

    Please discuss the time complexities as well with each algorithm. That would be really helpful.

  • @sonampahariya4495
    @sonampahariya4495 6 ปีที่แล้ว +4

    The Algorithm code needs a correction as it can through array limit exception on line 4/5 T[i][j] = T[i-1][j-1]+1 when i=0 or j=0.

  • @amrishpatidar2579
    @amrishpatidar2579 7 ปีที่แล้ว

    your teaching style is very best

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

    sir, the question is
    find the number of characters that can be removed in the given string to make it a palindrome. using dynamic programming
    We have to return the count sir.
    Eg :
    input1:mabm
    output1: 1(explanation: by removing b we get palindrome)
    input2: abbbcdae
    output2 : 3(explanation: by removing c,d,e we get palindrome)

  • @mitalkhapandi8617
    @mitalkhapandi8617 4 ปีที่แล้ว

    Superb explaination 👍🌟

  • @ΑντρέαςΣωτηρίου-π8γ
    @ΑντρέαςΣωτηρίου-π8γ 6 ปีที่แล้ว +1

    you are a beast please expain more topics on programming

  • @reassume4826
    @reassume4826 5 ปีที่แล้ว +8

    How to stop sleepiness?
    Give an algorithm. I want to wake up all day and night and study.

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

      I heard that RedBull makes you awake or few hours.

  • @GagandeepSingh-zm4ch
    @GagandeepSingh-zm4ch 6 ปีที่แล้ว +10

    please tell why are u taking diagonal +1 if elements match and maximum of above and left elements if they are different....!!!!

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

      In the first instance we were looking for common subsequence between ab and b, so if we already had the count of subsequence between a and null (which is diagonally top left of the current cell) and then included b (which is common to both and is the current cell), then the common subsequence would increase by 1 (0 + 1). So when we find a common character we look at what the count of the subsequence was before that character was included, we do this by looking at the value of the cell diagonally top left of the current cell

  • @brave111111
    @brave111111 5 ปีที่แล้ว

    Great and simply explained

  • @quickvideos4386
    @quickvideos4386 5 ปีที่แล้ว

    You are best. I really mean it.. Keep it up.

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

    Sir, I think you have to take the 2d matrix of size [str1.length+1][str2.length+1] and loops will be up to

  • @benvahaba
    @benvahaba 5 ปีที่แล้ว

    at the end of the video the algorithm is a little wrong because if i=0 and j=0 and str1[i]==str2[j] than you cant do T[i-1][j-1]. ty very much for the video though. really helped me

  • @gopaldas7905
    @gopaldas7905 6 ปีที่แล้ว

    sir,your video is very easy to learn...sir please upload more videos on algorithm...please sir

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

    Wouldn't the complexity be O(nm), when n and m are the lengths of the two initial strings? (They need not be of equal length after all).

  • @asifnaqshi
    @asifnaqshi 5 ปีที่แล้ว

    Great explanation !!! But it would be great if you can explain how this algorithm is derived !!!

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

    needs more explanation on why we compare the values of those two cells?

  • @naveenkala987
    @naveenkala987 5 ปีที่แล้ว

    Great explanation!

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

    Very nice explaination

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

    Please post the logic to calculate lcs string as well.

  • @hadim
    @hadim 5 ปีที่แล้ว

    Good man. UR great explainer
    Thanks

  • @anjuanjali9315
    @anjuanjali9315 6 ปีที่แล้ว

    Easily understood sir....Thank you

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

    Thank you! Much better than the explanation in my textbook. However, I feel that you fail to explain why the logic works.

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

    Very nice Sir

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

    sir plzz make a video on SHORTEST UNCOMMON SUBSEQUENCE using dynamic programming.

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

    Would you please provide detailed pseudo code for back tracking? I would appreciate it.

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

    Please make a video on Binomial Tree and Binomial Heap and its operation with example

  • @MiddleEasternInAmerica
    @MiddleEasternInAmerica 4 ปีที่แล้ว

    what DSA books do you read ? How did you become so fluent in DSA this way ?

  • @raghavsethi4906
    @raghavsethi4906 4 ปีที่แล้ว

    But we can't use this method if the size of strings are very large right?

  • @arghyamitra3281
    @arghyamitra3281 7 ปีที่แล้ว

    Sir your lectures are too good..air can u please upload the videos for prime and dijaktra algorithm

  • @bhupalirani6982
    @bhupalirani6982 6 ปีที่แล้ว

    Sir, please make some videos on graph like finding out the number of connected islands and all! Thanks!

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

    sir please make a video on egg dropping puzzle

  • @satyammeena9474
    @satyammeena9474 6 ปีที่แล้ว

    thanks you so much sir
    great explanation

  • @tevaganthanveluppillai720
    @tevaganthanveluppillai720 6 ปีที่แล้ว

    Thank you for sharing it.

  • @RajatSingh-yb3tq
    @RajatSingh-yb3tq 5 ปีที่แล้ว +1

    why @11:12 he is so angry on me.................lol

  • @ArpitDhamija
    @ArpitDhamija 5 ปีที่แล้ว

    actually you have done in reverse order , you should make matrix first and then derive the relations

  • @supamdeepbains5172
    @supamdeepbains5172 4 ปีที่แล้ว

    how do we know the size of our 2d list is it len(str1 * lenstr2)

  • @swetharanik1822
    @swetharanik1822 5 ปีที่แล้ว

    From cell b and r..assume if first row consists of all ones ie both are same den how vl u select?

  • @Mei-ir3ml
    @Mei-ir3ml 6 ปีที่แล้ว

    Plz make a video on Count the number of palindromic subsequnces of the given string.

  • @DINESHKUMAR-zi7cm
    @DINESHKUMAR-zi7cm 7 ปีที่แล้ว

    Please make a video on LONGEST INCREASING SUBSEQUENCE

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

    Thanks a lot, man.

  • @amish1406
    @amish1406 6 ปีที่แล้ว

    Can you please explain how did you come up with this algorithm approach?

    • @svdfxd
      @svdfxd 11 หลายเดือนก่อน

      doesn't matter if he got it from a book. what matters is whether he was able to explain it properly, so that someone new to DP can understand. His explanation is awesome.

  • @user-jd8fr9bj6v
    @user-jd8fr9bj6v 7 ปีที่แล้ว

    thank you sir very nicely​ explained

    • @vivekanandkhyade
      @vivekanandkhyade  7 ปีที่แล้ว

      thanks gaurav...more videos are lined up...

  • @mihir2014
    @mihir2014 6 ปีที่แล้ว

    nicely explained....:)

  • @waynesimonetti4620
    @waynesimonetti4620 5 ปีที่แล้ว

    What's the space complexity?

  • @ferhatakbulut6572
    @ferhatakbulut6572 4 ปีที่แล้ว

    I tried to write code to find the letter themselves and i came up with this:
    def find_index(arr, x, y):
    if not x or not y:
    yield (x, y)
    return
    if arr[x-1][y] == arr[x][y] and arr[x-1][y-1] == arr[x][y] and arr[x][y-1] == arr[x][y]:
    yield tuple((x, y))
    yield from find_index(arr, x-1, y-1)
    if arr[x-1][y] == arr[x][y]-1 and arr[x-1][y-1] == arr[x][y]-1 and arr[x][y-1] == arr[x][y]-1:
    yield tuple((x, y))
    yield from find_index(arr, x-1, y-1)
    if arr[x-1][y] == arr[x][y]:
    yield from find_index(arr, x-1, y)
    if arr[x][y-1] == arr[x][y]:
    yield from find_index(arr, x, y-1)
    arr is the array with all the numbers and x0 and y0 are the coords of the corner right bottom most number.
    The code works for all the cases in the video but i don't know if it will for others, can someone help me to test the code rigorously?

    • @ferhatakbulut6572
      @ferhatakbulut6572 4 ปีที่แล้ว

      The whole code looks like this:
      str1 = 'abcvdefgh'
      str2 = 'bqdycvefgh'
      arr = [[0 for _ in range(len(str1))] for _ in range(len(str2))]
      for i in range(len(str2)):
      for j in range(len(str1)):
      if str2[i] == str1[j]:
      arr[i][j] = arr[i-1][j-1] + 1
      else:
      arr[i][j] = max(arr[i-1][j], arr[i][j-1])
      def find_index(arr, x, y):
      if not x or not y:
      yield (x, y)
      return
      if arr[x-1][y] == arr[x][y] and arr[x-1][y-1] == arr[x][y] and arr[x][y-1] == arr[x][y]:
      yield tuple((x, y))
      yield from find_index(arr, x-1, y-1)
      if arr[x-1][y] == arr[x][y]-1 and arr[x-1][y-1] == arr[x][y]-1 and arr[x][y-1] == arr[x][y]-1:
      yield tuple((x, y))
      yield from find_index(arr, x-1, y-1)
      if arr[x-1][y] == arr[x][y]:
      yield from find_index(arr, x-1, y)
      if arr[x][y-1] == arr[x][y]:
      yield from find_index(arr, x, y-1)
      letters_coord = reversed(list(find_index(arr, i, j)))
      longest = ''
      for i in letters_coord:
      longest += str2[i[0]]
      print(longest)

  • @bhupalibaishya2136
    @bhupalibaishya2136 5 ปีที่แล้ว

    Please make video to print the LCS string

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

    Sir, but the program you wrote only makes the matrix ready....but it doesn't tell about How to form the corresponding lcs STRING from matrix.. Thus this video is amazing but incomplete

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

      Please reply to my query sir..as the complete coding solution for it is very important... and without it the video is incomplete

  • @rishabhsinghchauhan4334
    @rishabhsinghchauhan4334 6 ปีที่แล้ว

    Sir maza aagya pash k

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

    video starts 7:59

  • @sailkargutkar1980
    @sailkargutkar1980 6 ปีที่แล้ว

    youtube please increase the speed by default by 3 for vivekanand khyade's videos.
    By the way very well explained sir.Thanks.

    • @vimalsheoran8040
      @vimalsheoran8040 5 ปีที่แล้ว

      document.getElementByTagName("video")[0].playbackRate = 3.0; paste this snippet in your console and you'll see the magic.

  • @pradeepdeshmukh843
    @pradeepdeshmukh843 6 ปีที่แล้ว

    Hello Sir
    can you please post the video for suffix tree?

  • @vyshnavramesh9305
    @vyshnavramesh9305 5 ปีที่แล้ว

    Why 2D matrix? why diagnol+1? why max?

  • @purvakashyap4060
    @purvakashyap4060 7 ปีที่แล้ว

    Thank you sir

  • @veerrajuyeleti8541
    @veerrajuyeleti8541 8 ปีที่แล้ว

    sir how are you choosing the adjacent element max

    • @vivekanandkhyade
      @vivekanandkhyade  8 ปีที่แล้ว

      hey friend , can u plz tell me the timing of the part in the video which your question is related about? Thanks a lot for commenting. I will surely solve ur doubt.

    • @sriramkukkadapu1049
      @sriramkukkadapu1049 6 ปีที่แล้ว

      Hello Sir, 2 doubts.
      1) If the result matrix is below, how to find the length which we need to find ?
      Result matrix:
      0 0 0 0 0 0 0 0
      0 0 1 1 1 1 1 1
      0 0 1 1 2 2 2 2
      0 0 1 1 2 2 2 2
      0 0 1 1 2 3 3 3
      0 0 1 1 2 3 3 4
      0 0 1 1 2 3 3 4
      0 0 1 1 2 3 3 4
      2) How to print the result string ?

  • @l3aIIin23
    @l3aIIin23 7 ปีที่แล้ว

    thanks

  • @pranaychandra8016
    @pranaychandra8016 5 ปีที่แล้ว

    sir ji word kese niklega yeh to btaya hi nhi

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

    Reallyy You too specila in Teaching!!!!!!!!!!!!!!!!!!!

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

    stupid way of explaining things without giving the proper algorithm , where is the optimal substructure ? where is the proof of correctness ?

    • @vimalsheoran8040
      @vimalsheoran8040 5 ปีที่แล้ว

      why don't you google that

    • @cwash08
      @cwash08 5 ปีที่แล้ว

      @@vimalsheoran8040 its a valid criticism, its what many people watch these videos for