Awesome video! So helpful!!! And the ---> "There'll never be a time when I'll add and then delete a character because that's stupid." was funny, had to pause the video to laugh for a moment. XD
@gkcs5 жыл бұрын
😁
@utkarshjain80243 жыл бұрын
"Adding a character to A is equivalent to deleting a character from B", this was the one line that made me understand the entire problem. Really clear explanation!
@huangleonard15572 жыл бұрын
This is the very first edit distance tutorial which gives me no feeling of what the fxxx are you talking about. Excellent!!
@aakashpathak216 жыл бұрын
I was stuck for an hour because of the thing that how we can compute (i, j - 1) instead of ( i + 1, j)...saw a lot of videos but you are the one who actually explained :) Thanx bro!
@vlogs.anurag5 жыл бұрын
exactly
@saurabhjoshi93193 жыл бұрын
I watch the whole video just because of this point Well explained
@vinayak186f33 жыл бұрын
I'm still stuck ,unable to backtrack , the goal was to convert pqqrst to qqttps , but he ended up with qqts 😥
@heenaagarwal67954 жыл бұрын
When I search for a problem explanation on youtube, and I find your video at the top of the output list of my search, I get a sense of relief and a smile on my face. Now I will watch the video.
@gkcs4 жыл бұрын
So glad to hear that Heena, thank you 😁
@SurjitSingh14-c6i3 жыл бұрын
@@gkcs what is wrong public: int ct=0; string lcs(string s, string t) { int dp[s.length()+1][t.length()+1]; for(int i=0;i0) { // replace ct+=1; } else if(x==0&&y>0) { // insert ct+=y; } } int x=s.length()-p1; int y=t.length()-p2; if(p2>=t.length()&&p1
@mohitksahu3 жыл бұрын
I watched many videos but could not understand the addition point. Till now, this is the best explanation I have come across for this problem. Thanks a lot, Gaurav. You are the savior.
@sachinsharma9053 жыл бұрын
This is the most articulate explanation of this problem in the whole internet space.Thanks man.
@pranavgaur63994 жыл бұрын
The only reason I was able to understand the logic behind this problem(after watching several videos) was because you explained the logic behind insertion which no one else did.. keep up the amazing work
@studgaming61606 жыл бұрын
I didn't understand the how minimum function takes minimum of 3 elements of array from Tushar Roy's video, Then I came here and I UNDERSTOOD. Thank You brother. Keep making such awesome videos.
@anushkachakraborty86352 жыл бұрын
Of all the edit distance explanation videos I have seen, This was the most passionately and relatable explained. Thankyou so much :)
@BingumallaAmaresh5 жыл бұрын
The first part of the video explaining the function and the logic that follows for DP was what I just needed. Thanks :)
@lovehasija39954 жыл бұрын
Awesome Explanation. I get shocked to see so many videos explaining the algorithm without the intuition or derivation. You did it really well, thanks for sharing. It's really helpful.
@gkcs4 жыл бұрын
😁
@sanjarcode Жыл бұрын
Learning and thinking like this is way better than just saying DP and then learning it.
@dznuts1232 жыл бұрын
Just to clarify, adding a character to string 1 is not literally the same as deleting a character from string 2. The minus 1 from string 2’s index is an abstraction, because after implicitly adding a character to string 1, the character at the index in string 2 is taken care of. We don’t need to minus 1 from string 1 index, because the index did not change during the additive process.
@MegaArti20003 жыл бұрын
Had to watch it twice, but I think I got it. Thx.
@amitpurohit88164 жыл бұрын
Sir your explanation is awesome....I watched tonnes of videos for this problem...But yours was the most effective..thank you!!
@gkcs4 жыл бұрын
Thank you :)
@amitpurohit88164 жыл бұрын
@@gkcs I'm surely gonna recommend your dp videos to all my friends who are beginners in dp
@musicislife18445 жыл бұрын
Awesome video!! Thank you so much!! I have a humble request...please add more videos on dynamic programming problems the way you teach makes things look way easier than they are!! Keep it up!. Thanks a lot!!!
@rohangarg54735 жыл бұрын
No doubts in Edit distance now, thanks👍
@vrdash4 жыл бұрын
Edit Distance that eluded me for so long makes so much sense now. I thought I would have to just blindly believe in the Algorithm :p
@fullemptiness4 жыл бұрын
Coming from coursera course, suck in explaining the problem. Thanks, your explanation helped!
@SportsMoments172 жыл бұрын
13:13 we have not only one possibility, we have two possibilities because diagonally and vertically both are 4
@ocean_sunrise6 жыл бұрын
thank you gaurav, saved my life :)
@gkcs6 жыл бұрын
Glad it helped!
@sahilkakkar56283 жыл бұрын
Good Explanation, really helpful!
@PriyankaSingh-pn8xv3 жыл бұрын
Awesome explanation
@iiillliii13862 жыл бұрын
proud of you my friemd
@yobro70514 жыл бұрын
this guy always seems so much energetic
@nikhilgumidelli63084 жыл бұрын
Brilliantly explained !
@saurabhsharma71236 жыл бұрын
The concern of this video was why computing ( i + 1, j), instead of (i, j - 1) is wrong. That would lead to cyclic recursions!
@gkcs6 жыл бұрын
Exactly!
@priyeshshrivastava84256 жыл бұрын
Hi Gaurav, if we are converting i+1,j to i,j-1 why are we still taking Ca the cost of addition, and not Cd?
@sidharthsk38076 жыл бұрын
U IIT Kharagpur
@AayushThokchom5 жыл бұрын
@@gkcs As Priyesh asked in the comment. My understanding is: this approach can only be applied if Cd < Ca. If Ca
@gkcs4 жыл бұрын
@@priyeshshrivastava8425 Because although the operation is equivalent, we cannot change the costs of the operations. That's usually an input to the problem.
@pranavkochhar93523 жыл бұрын
VERY WELL EXPLAINED!!
@aparichitsingh3846 жыл бұрын
Again a nice one. Thanks for this :) Cheers!
@gkcs6 жыл бұрын
Thanks Aparichit! :) I am sorry I must have forgotten, but I don't remember thinking of a follow up video on Centroid Decomposition. Was it something I said? Centroid Decomposition: kzbin.info/www/bejne/Y33KlZRja8R0n7s
@aparichitsingh3846 жыл бұрын
Sorry for this! I didn't get any notification for : kzbin.info/www/bejne/opnYY2x5apata9U Going to watch it tonight. Thanks a lot for reply bhaiya :)
@gkcs6 жыл бұрын
Have fun! Btw, it has a mistake, so I added a correction video in the description :)
@aparichitsingh3846 жыл бұрын
yes I'm talking about that correction video! (didn't get any notification for that. so, misunderstood)
@madhukiranattivilli23212 жыл бұрын
I'm not sure if I clearly understood the concept of "adding to A is same as deleting from B". Lemme know if my writeup has flawa... (1) To implement dynamic programming technique, higher state should always reduce to a lower state. But in the case of adding a character to A, a higher state moves to an even higher state. So, this needs to change. 1 way is to delete character from B, instead (2) Difference in the sizes of strings A and B wud be 1 whether a character is added to A, or a character is deleted from B. So, to help the problem in (1), delete character from B (3) If A=pqqrst and B=qqttps, adding character to A would implicitly mean adding the final character of B to A as well. So A becomes pqqrsts. Now A and B have the same terminal characters. They have to be removed, because the algo does addition/deletion/transition always to the terminal characters, and so not deleting them will block the work of the rest of the algorithm. Hence, this change makes A,B = pqqrst, qqttp. And this would also be the state if s is deleted from B without making any changes to A (3) is the main point. (1) and (2) are supporting points Comments?
@AjayKumar-qm5fu6 жыл бұрын
Commendable effort bro
@gkcs6 жыл бұрын
Thanks!
@riturajjoshi59356 жыл бұрын
Congrats on the new mic!
@gkcs6 жыл бұрын
Thanks!
@rishabhb26885 жыл бұрын
Very well explained ! Thank you !
@LearnWithBahman6 жыл бұрын
Officially, I am a fan now, hopefully, one day we work together.
@gkcs6 жыл бұрын
😁
@prateekkanujiya97755 жыл бұрын
U r awesome bro. Respect
@AkhileshKumarCSE6 жыл бұрын
Hello Gaurav, could you please help me understanding the at 12:58 - 13:05 here you are pointing at 'p' then saying add a char to get to 'q' ?
@gkcs6 жыл бұрын
I have replied to your other comment on this :)
@ShivamKendre-fc3su4 жыл бұрын
Really nice
@yuvrajoberoi78344 жыл бұрын
Excellent explanation of this problem. Also, you gave me a better appraoch to appraoch a proble. I have seen problems like design autocorrect feature etc. and there this thing can be very helpful right?
@gkcs4 жыл бұрын
The autocorrect feature also has to take into consideration "probable words". For example, the word "runvwe" is closer to "timber" than we might expect. It's because our keyboards are designed that way. Our fingers also have typical ways of typing, and our mind make phonetic to spelling translations when we aren't sure of the spelling. All in all, it's a complex problem to solve. Neural networks have been seen to perform well in autocorrect applications. I would go with one of those :)
@yuvrajoberoi78344 жыл бұрын
@@gkcs Hey, thank you for giving your time to explain this.
@hussainburhanuddin37053 жыл бұрын
Wow, I really loved this video, Your explanation was really easy to understand. But, you didn't explain how the initial table would be created, at 10:59 , as I understood the table had 1,2,3,4,5,6 because Ca and Cd were = 1. I am not able to get my head around how the set up the initial table (end states) values for different values of Ca and Cd.
@gkcs3 жыл бұрын
We make a table full of zero values, with dimensions equal to length of the two string m * n.
@hussainburhanuddin37053 жыл бұрын
@@gkcs Okay, that makes sense. But how would you fill the values for row 0 and column 0 if Ca,Cd != 1???
@HimanshuSingh_925 жыл бұрын
Why you are considering going right towards p and going down towards q as deletion operation?
@gkcs5 жыл бұрын
Check out the other edit distance video on the channel, which explains this.
@SATISHKUMAR-xk7cn6 жыл бұрын
Excellent explanation !! keep it up.
@jkrw35406 жыл бұрын
Can you explain, why you have added and deleted from the end of the string and not from other part of the string ? Also, how do I know what character I am going to add in the first string to make it the second string ?
@kartikshet16 жыл бұрын
Great explanation. I have one issue with dynamic programming, even if I come up with the recursive function, I find it hard to convince myself that it leads to the solution, I find myself stuck there.
@gkcs6 жыл бұрын
It'll improve soon 😁
@ocean_sunrise6 жыл бұрын
I think it will help you to trace your program step by step just like dynamic programming
@AkhileshKumarCSE6 жыл бұрын
Hello Gaurav could you please help me understanding the concept of "Addition" here ? f(i + 1, j) = f(i, j - 1) ? Example given two strings "p", "q" , how will we convert "p" --> "q" using "Addition" operation ? As per logic which i understood from this video it would go like below :- f(1,1) f(1,0) = "q" --> " " (I guess this is 'j - 1' , effectively deleting from string "q" than adding in "p"). " " --> "p". (Addition : adding 'p' into NULL string). So basically we converted "q" --> "p" not "p" --> "q" which was the objective of Edit distance ? correct me if i understood wrong and help me understanding correctly please !
@gkcs6 жыл бұрын
Both are equivalent. Converting A to B is exactly as expensive as converting B to A. So we pick any one and follow the steps. If the steps need to be printed, we can simply invert the operations that are optimal and the answer will be the same :)
@AkhileshKumarCSE6 жыл бұрын
Thank you !
@barshalamichhane67613 жыл бұрын
Thank you so much!!
@hey.............4 жыл бұрын
great explanation Gaurav. Thank you for the help.
@gkcs4 жыл бұрын
Thanks Varun!
@anirudhatalmale55755 жыл бұрын
outstanding
@innocent10296 жыл бұрын
could you do a video on finding if a string is interleaved of two other strings?
@akashchatterjee51794 жыл бұрын
Can anyone please say that why LCS -max length(S1,S2) logic fails...
@Ankitbomb15 жыл бұрын
That helped. Thanks man!
@rathinavelsankaralingam29294 жыл бұрын
Thank you man! Just Thank You /\ You should live long :)
@archip31126 жыл бұрын
Hi Gaurav, Please explain the case when the given two strings are of different size?
@gkcs6 жыл бұрын
Hey Archi, The same algorithm applies! The matrix is of size M*N, where they M and N are the lengths of the two strings. 😋
@archip31126 жыл бұрын
you are right. Thanks !
@faizaomer57374 жыл бұрын
Uffff Thanks Allah... Finally i got it output concept... Thank you Tutor
@ayushgarg59294 жыл бұрын
Jai Shri Ram🚩
@Shrimangal1004 жыл бұрын
in d[1][1] your output is 0+1, but in d[1][2] it is only 1 and not 1+1. Kindly explain
@alexanderrivera19384 жыл бұрын
Can one of the strings be longer than the other?
@gkcs4 жыл бұрын
Yes
@ilikememes90524 жыл бұрын
Ohhh God !! I can't understand anything in algorithms 😭😭😭. Have to watch multiple times.
@mandeep21924 жыл бұрын
because u like memes :P
@shreyanshtiwari3495 Жыл бұрын
great!
@anandchowdhury92624 жыл бұрын
Tushar should see your videos..
@stalera4 жыл бұрын
using the approach described above for words "smitten" and "arbrikitten", the actual difference should be 5 but I get as 4. the issue I see is that i is repeated in the second string and that is causing the issue. I'm sure I'm missing something if you could help me understand. Thanks.
@gkcs4 жыл бұрын
I tried the code: github.com/gkcs/Competitive-Programming/blob/master/src/main/java/main/java/videos/EditDistance.java The difference is 5. Where did you get 4?
@stalera4 жыл бұрын
@@gkcs my bad, shouldn't the difference be 6? arbrik 6 characters and remaining are same. If I use the LevenshteinDistance algorithm it gives 6. Am I missing something here? The issue is because arbrikitten has 2 'i' which is being considered both the times for 'i' in smitten. Shouldn't it be considered only once?
@stalera4 жыл бұрын
hey man, do you think I'm missing something here? it could be some silly mistake if you can help me figure out.
@gkcs4 жыл бұрын
ideone.com/jjou1K
@stalera4 жыл бұрын
@@gkcs appreciate your efforts to respond to each of the comments man. that takes hell lot of patience. Hope you've not kept an assistant to do that ;)
@visheshsrivastav21076 жыл бұрын
Bhaiya can you upload a video for hardest gcd problem (codechef april cook off problem)
@gkcs6 жыл бұрын
Coming up next :)
@sulekhakumari-hs4gy5 жыл бұрын
want more from strings
@fullemptiness4 жыл бұрын
In the Edit Distance problem you need to know the source and target strings before solving the problem, but in the text correction application, you haave no idea what is the target string!
@gkcs4 жыл бұрын
Yes. A frequency based trie is useful in those cases.
@samarpanharit42686 жыл бұрын
I am unable to understand 😶😶
@gkcs6 жыл бұрын
Which bit?
@samarpanharit42686 жыл бұрын
Got it now after watching it thrice😂 thanks for asking
@axc42806 жыл бұрын
Far from Topic Can you tell me what is difference between C++ and Java when we learn it and from what kind of matter we have to be attentive...
@pallavisompalli26896 жыл бұрын
Will you marry me? 😭
@thebibhuty6 жыл бұрын
This channel is related to programming not bharat matrimony ;)