Longest Common Subsequence Dynamic Programming : Interview question

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • Write a program for finding out the longest common subsequence between two strings. Dynamic Programming.

КОМЕНТАРІ • 83

  • @arjun9951
    @arjun9951 6 років тому +29

    Vivek -- I don't know what I would do without your explanations. You are the best algorithms teacher on UA-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 !!

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

  • @footballgeeks4381
    @footballgeeks4381 6 років тому +2

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

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

  • @SanthoshKumar-nj8mm
    @SanthoshKumar-nj8mm 4 роки тому

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

  • @neerajkashyap01
    @neerajkashyap01 6 років тому +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.

  • @Karan-ms5es
    @Karan-ms5es 5 років тому +1

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

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

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

  • @amrishpatidar2579
    @amrishpatidar2579 6 років тому

    your teaching style is very best

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

  • @ΑντρέαςΣωτηρίου-π8γ
    @ΑντρέαςΣωτηρίου-π8γ 6 років тому +1

    you are a beast please expain more topics on programming

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

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

  • @amitrawat2915
    @amitrawat2915 5 років тому

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

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

    Superb explaination 👍🌟

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

  • @asifnaqshi
    @asifnaqshi 5 років тому

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

  • @brave111111
    @brave111111 5 років тому

    Great and simply explained

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

  • @cskwillreturn2473
    @cskwillreturn2473 6 років тому +2

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

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

  • @arghyamitra3281
    @arghyamitra3281 7 років тому

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

  • @yuvrajkthorat
    @yuvrajkthorat 6 років тому +1

    Very nice explaination

  • @quickvideos4386
    @quickvideos4386 5 років тому

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

  • @anjuanjali9315
    @anjuanjali9315 6 років тому

    Easily understood sir....Thank you

  • @rakeshpandey9730
    @rakeshpandey9730 6 років тому +1

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

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

    Good man. UR great explainer
    Thanks

  • @pardeepsharma6502
    @pardeepsharma6502 6 років тому +2

    Please post the logic to calculate lcs string as well.

  • @anilchaudhry804
    @anilchaudhry804 5 років тому +1

    sir please make a video on egg dropping puzzle

  • @bhupalirani6982
    @bhupalirani6982 6 років тому

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

  • @zulaikhabeevi7558
    @zulaikhabeevi7558 7 років тому +1

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

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

  • @naveenkala987
    @naveenkala987 5 років тому

    Great explanation!

  • @satyammeena9474
    @satyammeena9474 5 років тому

    thanks you so much sir
    great explanation

  • @furkansabugar7427
    @furkansabugar7427 6 років тому +1

    Very nice Sir

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

  • @sethi2187
    @sethi2187 7 років тому +1

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

  • @tevaganthanveluppillai720
    @tevaganthanveluppillai720 5 років тому

    Thank you for sharing it.

  • @sailkargutkar1980
    @sailkargutkar1980 5 років тому

    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.

  • @Mei-ir3ml
    @Mei-ir3ml 6 років тому

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

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

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

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

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

  • @user-jd8fr9bj6v
    @user-jd8fr9bj6v 7 років тому

    thank you sir very nicely​ explained

  • @DINESHKUMAR-zi7cm
    @DINESHKUMAR-zi7cm 7 років тому

    Please make a video on LONGEST INCREASING SUBSEQUENCE

  • @the_laptopgamer7167
    @the_laptopgamer7167 6 років тому +1

    Thanks a lot, man.

  • @bhupalibaishya2136
    @bhupalibaishya2136 5 років тому

    Please make video to print the LCS string

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

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

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

  • @waynesimonetti4620
    @waynesimonetti4620 5 років тому

    What's the space complexity?

  • @mihir2014
    @mihir2014 6 років тому

    nicely explained....:)

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

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

  • @pradeepdeshmukh843
    @pradeepdeshmukh843 5 років тому

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

  • @amish1406
    @amish1406 6 років тому

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

    • @svdfxd
      @svdfxd 8 місяців тому

      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.

  • @RajatSingh-yb3tq
    @RajatSingh-yb3tq 5 років тому +1

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

  • @purvakashyap4060
    @purvakashyap4060 6 років тому

    Thank you sir

  • @vyshnavramesh9305
    @vyshnavramesh9305 5 років тому

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

  • @rishabhsinghchauhan4334
    @rishabhsinghchauhan4334 6 років тому

    Sir maza aagya pash k

  • @veerrajuyeleti8541
    @veerrajuyeleti8541 7 років тому

    sir how are you choosing the adjacent element max

    • @vivekanandkhyade
      @vivekanandkhyade  7 років тому

      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 6 років тому

    thanks

  • @pranaychandra8016
    @pranaychandra8016 5 років тому

    sir ji word kese niklega yeh to btaya hi nhi

  • @every_instant
    @every_instant 5 років тому +1

    video starts 7:59

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