Minimum Edit Distance Dynamic Programming

  Рет қаралды 551,277

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер: 511
@mylilcritic
@mylilcritic 8 жыл бұрын
Legend! I couldn't figure it out after an hour of looking at my lectures but within 3 minutes of you explaining it just clicked! Thank you!
@shubhampathak1080
@shubhampathak1080 9 жыл бұрын
I have got my exam tomorrow and this video really helped me to understand the edit distance algorithm thoroughly. Probably one of the best explanation that one can find on KZbin for edit distance. Thank you very much !
@vaibhavmourya65
@vaibhavmourya65 Жыл бұрын
mine is tmrw.. 8 years same vibe
@nihadbkirli347
@nihadbkirli347 Ай бұрын
@@vaibhavmourya65 2024 same vibe tomorrow exam
@vaibhavmourya65
@vaibhavmourya65 Ай бұрын
@@nihadbkirli347 I am graduate now 2024 batch
@sbahuddin
@sbahuddin 11 ай бұрын
I spent hours and couldn't figure it out. You explained the concept so nicely in just 9 minutes.
@namazbaiishmakhametov6424
@namazbaiishmakhametov6424 4 жыл бұрын
Crap, man, in a little over three months it will be 6 years since you shot this video, and it helped me today! Thanks a lot, Tushar, and I hope you're doing well these corona-days!
@melogens994
@melogens994 9 ай бұрын
I have been spamming your videos before the olympiad in informatics and they are quite literally my lifeline. Thanks so much for these videos!
@novicaovuka5480
@novicaovuka5480 6 жыл бұрын
Man, you helped me a lot. I have an exam soon. And I have to learn a lot of code which I don't understand. After watching your video, man, that code is so easy. Thanks a lot.
@amanbhandari349
@amanbhandari349 4 жыл бұрын
You learn code!!??? Wtf
@tuncdogukan
@tuncdogukan 7 жыл бұрын
I got the idea of the algorithm quickly. It's a nice and clear implementation with good explanation. Thanks for the effort to pass on the knowledge.
@aashkas
@aashkas Жыл бұрын
Thank you, I had been looking at some dp question for days. Your explanation and graph really became a breakthrough.
@evergreen7781
@evergreen7781 4 жыл бұрын
I can say that, you have the best Dynamic Programming KZbin tutorial in the market ❤️❤️❤️
@ksankitha
@ksankitha 8 жыл бұрын
Tushar your explanations are extremely clear and have been immensely helpful Great job .Looking forward to more videos from you .Please keep them coming !
@pvpk1994
@pvpk1994 8 жыл бұрын
Man! Respect! Awesome Job! ..i spent hours together breaking my head on this before seeing this video! Lucid Explanation!
@ertagon
@ertagon 2 жыл бұрын
Simple and straightforward. I looked at 3 different videos before this. This is a really good explanation.
@DominicClaxton
@DominicClaxton 8 жыл бұрын
I didn't understand this until I watched your video. Thanks a lot!
@FF-ne2qz
@FF-ne2qz 8 жыл бұрын
You didn't say why this works. It is very important!
@bioinfo9386
@bioinfo9386 8 жыл бұрын
He actually did, even in detail- you´d better watch the clip again..
@azklinok
@azklinok 8 жыл бұрын
He did not. He told us the method, not its proof.
@wanghaochen3515
@wanghaochen3515 8 жыл бұрын
What kind of proof do you need? If they are the same, then do nothing, if not, add 1 more operation to whatever gets the least in previous ops. To me, the logic is pretty obvious.
@azklinok
@azklinok 8 жыл бұрын
The logic is obvious to all of us. I want to know WHY the logic works, and gets us the right answer.
@wanghaochen3515
@wanghaochen3515 8 жыл бұрын
azklinok Well. First of all, if two characters are same, you don't do anything, that's clear right? If not, then there's 3 possible moves: delete, replace and insert. Suppose your rows represents str1, cols represents str2. If you wanna delete, you go back to previous column, which is T[i][j-1], because you'd like to retrieve the last character in str2. Similarly, if you wanna insert, you go back to previous row, which is T[i-1][j]. For replacing current character, you need to retrieve last character in both str1 and str2, which is T[i-1][j-1]. At last, you get the minimum among the above 3 moves and plus 1 to it to get T[i][j]. I'm not sure if I articulate it in a proper way, at least that's how I understand this problem.
@xlOogh0stoOlx
@xlOogh0stoOlx 9 жыл бұрын
Thank you so much. I have computer algorithm exam tomorrow and this video really helps me. You're the man.
@Daniel-to5jd
@Daniel-to5jd 4 жыл бұрын
the best video i have found on this topic so far, you explain it better than in a paid coursera course
@tristangrobler4950
@tristangrobler4950 8 ай бұрын
This is really cool! 9 years since posting and it helped. Nice work!
@4ythere
@4ythere 9 жыл бұрын
Hey, I feel you should also hover over optimal subproblems and what a state of the DP represents, For example, In this question, when not equal, you take the min of(top,left,diagonal) , where in you should explain that the top refers to inserting a[i], left refers to deleting a[i] and diagonal refers to editing a[i]. On a side note, you should have mentioned the case where the cost of edit, insert and delete are different.
@sankethb.k642
@sankethb.k642 5 жыл бұрын
Thank you
@manoharyedla360
@manoharyedla360 4 жыл бұрын
@@sankethb.k642 worst lecture
@abhishekk.3977
@abhishekk.3977 4 жыл бұрын
7:00 - Diagonal ( EDIT) 7:25 - Left ( DELETE ) Top -> Insert (Implied)
@beanlighter9491
@beanlighter9491 4 жыл бұрын
yes but this is how indians study can you guys recommend me a more detailed lectures?
@Cube2deth
@Cube2deth 4 жыл бұрын
@@parmoksha +1 I don't know why they complain! His videos are not meant for proof or theory or how he thought of the solution just how to solve a problem, which is what we are all trying to learn
@ayanpaul27
@ayanpaul27 4 жыл бұрын
Short and crisp explanation.. Thank u so much... Finally i got to understand this
@amith89rm
@amith89rm 4 жыл бұрын
I salute this guy!!! Thanks so much for the video. I was cracking my head to solve this problem. your explanation helped me understand in less than 10 minutes
@sagnikrana7016
@sagnikrana7016 4 жыл бұрын
Hey Amith, I understood the approach. Could you help me explain why this method works?
@kushal1
@kushal1 4 жыл бұрын
Thank God, you did before I am learning DP. Intuition building is hard and there is a way. My instructors don't know it. You know it and you show it.
@cppprogramming
@cppprogramming 7 жыл бұрын
Tushar, your explanation of how to populate the table, and then how to work it backwards to identify operations was awesome. Thank you.
@janedawg09
@janedawg09 11 ай бұрын
your clear explanation as to how each number came up for each cell is really helpful (also the shortcut). i've been having a hard time understanding the this but you removed the complexity with your explanation
@prashantjindal8697
@prashantjindal8697 8 жыл бұрын
Your videos on dynamic programming are extremely helpful....!!! Great Job Tushar.....!!!!
@studyaccount794
@studyaccount794 2 жыл бұрын
Bro really drew the 2d array even before starting the video.
@digusbickus
@digusbickus 3 жыл бұрын
I've been slamming my head against this problem for days. Cheers! You made it very understandable and easy to grasp.
@mr.mystiks9968
@mr.mystiks9968 5 жыл бұрын
Awesome video. I already knew how to write out the DP table and but deriving the edit operations being done from the table was the crucial part I did not understand. This was a big help.
@abhijeetkumar2204
@abhijeetkumar2204 4 жыл бұрын
Evergreen video even u can watch this video 10 year later and understand the dp.
@mesosiderite4670
@mesosiderite4670 2 жыл бұрын
you're better than my teacher greetings from Quebec
@studywithrobin2715
@studywithrobin2715 3 жыл бұрын
You explain it a lot better than some of the newer videos.
@daydreameravani
@daydreameravani 8 жыл бұрын
Without you video, I will definitely fuck up on leetcode. Thx a lot! Please keep doing this!
@yusniamaliah4522
@yusniamaliah4522 8 жыл бұрын
i have been looking for tree edit distance theory, and this is the best explanation ever. i just watch at once, i really understand. thanks for sharing education. I'm subscribing U right now..
@karthikeyanm.v8381
@karthikeyanm.v8381 6 жыл бұрын
thing is that you teach better than my professor . thank you bro
@monapanah
@monapanah 9 ай бұрын
Bravo! one of the best teachers in this field! thank you
@DignsagYT
@DignsagYT 7 жыл бұрын
Until this video I could not wrap my head around it. So thank you very much. Straight to the point.
@CodeFromSoul
@CodeFromSoul 3 жыл бұрын
How the hell people think so out of the box to solve problem, I can never imagine this problem can be solved this way... really burst up 🤯
@abhijithtk
@abhijithtk 9 жыл бұрын
I think this is one of the best explanations out there for this problem. Thanks much. Your implementation is very simple too. love it.
@YanuarTriAdityaNugraha
@YanuarTriAdityaNugraha 9 жыл бұрын
+Abhi Tk Absolutely, very easy to understand. Keep going.
@simiyutube
@simiyutube 3 жыл бұрын
old video Tushar Roy but really helpful. I appreciate your help. Made this pretty straight forward.
@yinkaige5169
@yinkaige5169 2 жыл бұрын
Great explanation! So so much easier this way to understand this way
@AntiochsAdvocate
@AntiochsAdvocate 3 жыл бұрын
Got stuck on this problem in an NLP textbook and this really helped tysm :)
@sharpdemon
@sharpdemon 9 жыл бұрын
Wow very nice man! I will definitely go through all your videos to brush up my algorithms!
@ankursuri3853
@ankursuri3853 6 жыл бұрын
This is the best explanation I have found sofar. Thanks so much Tushar! Keep up the good work.
@uditkanotra9393
@uditkanotra9393 4 жыл бұрын
please understand where the formula came from Use f[i][j] to represent the shortest edit distance between word1[0,i) and word2[0, j). Then compare the last character of word1[0,i) and word2[0,j), which are c and d respectively (c == word1[i-1], d == word2[j-1]): if c == d, then : f[i][j] = f[i-1][j-1] Otherwise we can use three operations to convert word1 to word2: (a) if we replaced c with d: f[i][j] = f[i-1][j-1] + 1; (b) if we added d after c: f[i][j] = f[i][j-1] + 1; (c) if we deleted c: f[i][j] = f[i-1][j] + 1; Note that f[i][j] only depends on f[i-1][j-1], f[i-1][j] and f[i][j-1], therefore we can reduce the space to O(n) by using only the (i-1)th array and previous updated element(f[i][j-1]).
@alessiodenny6123
@alessiodenny6123 4 жыл бұрын
excellent thanks ! More useful than 3 hours of lectures at school
@afiyatiamaluddin9034
@afiyatiamaluddin9034 4 жыл бұрын
Thank you very much, this is my AHA MOMENT. This is what I'm looking for all this time.
@achilles165
@achilles165 9 жыл бұрын
Great series of videos to prepare of interviews... already subscribed to your channel... One suggestion though... instead of directly jumping to the matrix right from start... it would be awesome if you could explain the solution for a min or 30 seconds, in terms of what you will be doing before jumping to solving of the table. Although you kind of mention the formula in the end, but it would be better if it is verbally explained at the beginning and then mathematically written at the end. That would help people in understanding that how DP can solve this problem in the first place.
@bernardoalvarenga2607
@bernardoalvarenga2607 6 жыл бұрын
Excellent explanation, great clarity. I've seen a video from CS50 on the subject that was a mess. This is great.
@willgoydych4403
@willgoydych4403 Жыл бұрын
This guy really casuallly out here just helping peopel
@sigmoid3596
@sigmoid3596 4 жыл бұрын
respect !! i pass the exam because of you
@ce097priyaraina2
@ce097priyaraina2 Жыл бұрын
best explanation i have seen so far..
@1piecegaming622
@1piecegaming622 3 жыл бұрын
thanx thanx thanx bro....Dynamic programming is sick to understand but this logic helps me a lot....Thnaks bhaai
@perfectfalse1
@perfectfalse1 2 жыл бұрын
THIS WAS A HUGE HELP. Thank you for posting this.
@gururajraykar9254
@gururajraykar9254 3 жыл бұрын
Just awesome video. Was searching short video which i can learn this algorithm.
@PAIETES19
@PAIETES19 9 жыл бұрын
Best explanation on the internet! Thanks for the video
@the_sweet_heaven
@the_sweet_heaven 4 жыл бұрын
Nice problem, Nice solution, and of course excellent explanation. +1 tushar
@eshwareducationsolutions2091
@eshwareducationsolutions2091 9 жыл бұрын
this is the best explanations. Thanks much. Your implementation is very simple too. I really helped for my exam.
@cadmonyuen6141
@cadmonyuen6141 9 жыл бұрын
You are doing a really good job. Keep up man.
@Harow77
@Harow77 Жыл бұрын
Thanks sir, cleared all my doubts in a short time.
@vvsatyanarayanareddyn4641
@vvsatyanarayanareddyn4641 9 жыл бұрын
DP was my nightmare , always used give up , after watching your videos, its like DP marathon at weekend. thanks a lot
@noone-ip8qs
@noone-ip8qs 4 ай бұрын
How is it going on now
@akshaytata
@akshaytata 9 жыл бұрын
Holy Shit, Who is the guy who made this algorithm! Awesome explanation!
@ghakol
@ghakol 3 жыл бұрын
thank you so much for this video!! i have a test on this in a few hours and this explanation was really helpful :)
@sheikhs1475
@sheikhs1475 7 жыл бұрын
Love from Pakistan. So simple. So concise. So comprehensive.
@taoyan8007
@taoyan8007 8 жыл бұрын
I completed this question on leetcode online judge, after watching this video I had a deeper understanding of Dynamic programming
@MegaMiley
@MegaMiley 6 жыл бұрын
Thank you!! This is the second time already a video of you made a problem 'click' for me :D, it all makes so much sense now!
@KameshwaranTheInsane
@KameshwaranTheInsane 7 жыл бұрын
I owe you so much Perfectly presented. You had explained this within 10 minutes Thank you very much...
@muthurajramalingakumar2361
@muthurajramalingakumar2361 4 жыл бұрын
Thanks for the upload! The intuition behind taking the Min of three cells would be helpful.
@Anne-ug4jv
@Anne-ug4jv 6 жыл бұрын
I have NLP exams tomorrow. Thank you very much for this!
@ts-gaming-29531
@ts-gaming-29531 9 жыл бұрын
Very good short video . Good job.
@agrimasrivastava2060
@agrimasrivastava2060 9 жыл бұрын
Thanks a lot Tushar. One of the best explanations I came across. :)
@milesstephenson4873
@milesstephenson4873 6 жыл бұрын
Thanks, Tushar. Very clear explanation.
@PremshainyKumarChintapal-vw3ip
@PremshainyKumarChintapal-vw3ip 2 ай бұрын
sir i want to say one word just wonderful
@rialaurent-hughes7191
@rialaurent-hughes7191 8 жыл бұрын
Thank you, that was perfect. Explained better than my lecturer
@ahmedboutaraa8771
@ahmedboutaraa8771 4 жыл бұрын
shout out to you man. really empowering content.
@dhanashreepawar9329
@dhanashreepawar9329 7 жыл бұрын
Good and clear explanation. Easy to understand!!!
@manasbudam7192
@manasbudam7192 9 жыл бұрын
absolutely better explanation than wikipedia!!!........thank you man!
@bhargavtenali
@bhargavtenali 8 жыл бұрын
Your videos deserve a great applause :)
@a50x
@a50x 6 жыл бұрын
Great explanation, easy to understand, really helped me to clearly understand DP
@logicraju
@logicraju 8 жыл бұрын
Awesome video, bro ! Was very useful !
@sagarrathore8242
@sagarrathore8242 3 жыл бұрын
such a great explanation sir😁
@josegermanparra6064
@josegermanparra6064 4 жыл бұрын
Thanks for a clear and concise explanation!
@yuhua1994
@yuhua1994 8 жыл бұрын
Helpful video! Totally understand after watching your videos :)
@maielshazly6054
@maielshazly6054 8 жыл бұрын
Your explanation is really clear. Thank you very much
@latheefjunior
@latheefjunior 8 жыл бұрын
Bro, you've done a wonderful job here. Thanks!!!
@dimitrisdimitriou6969
@dimitrisdimitriou6969 8 жыл бұрын
Tushar! Awesome! Great job!
@alvaro1121
@alvaro1121 6 жыл бұрын
Thank you my friend! Very clear explanation of the algorithm
@rdforte
@rdforte 3 жыл бұрын
This was very informative and helpful. Thankyou!
@sahnawaz
@sahnawaz 8 жыл бұрын
one thing he did not mention how we detect addition. so when computing all kind operations, if you move up the cell (e.g from (2,1) to (1,1) that means we need to add that particular row character in the conversion.
@umerwaqas5943
@umerwaqas5943 8 жыл бұрын
wonderfull way to teach. it was so difficult for before watching this. thanks
@jarias14
@jarias14 8 жыл бұрын
Thank YOU for explaining this in detail.
@vyshnavramesh9305
@vyshnavramesh9305 4 жыл бұрын
In MIT DP 3 video, Eric explains the logic behind the "min(the three cells)" beautifully. In short its the representation of insert, delete, replace.
@srinivasdesai3801
@srinivasdesai3801 6 жыл бұрын
I have few suggestions, 1. As many people have pointed out, I don't think I'm getting to know why this solution works before seeing the complete video. It would be helpful if Tushar goes over other approaches as well to prove that this solution works or mathematical proof shall be sufficient. 2. I think it would be better if the video explains what happens to the string(s) when we delete a character(s) and how the comparison shall be made rather than asking to the take the minimum of top, left and diagonal 3. Adding to the second point, if the characters are not same, I don't think it is just 1 + Min(cost(top), cost(dia), cost(left)). I think it shall be min(1 + cost(top), 1 + cost(left), 2 + cost(dia)). Because, when we are taking from the diagonal we are removing one element from str1 and one from str2. Assuming cost of removal is 1, it shall be 2 + cost(diag) rather than 1 + cost(dia) I welcome any suggestions for correction.
@ericchen1248
@ericchen1248 6 жыл бұрын
Nope, it's talking about changing one string into the other, so you're either operating on str1 or str2. If you want to go down that route, then by the way string is stored by computer memory, insertion or deletion should cost much more than changing. This is just the definition of edit distance. Of course, if you want to go to variants where there are different costs, your point is correct. As for the explaining part many people are asking about, he has a lot of videos on dynamic programming itself, it's basically all the same logic, and would be rather redundant for viewers otherwise. You can check out other videos explaining DP to get a better understanding, but here is a cut short version Dynamic Programming works because when looking for answers for a question with length of n, we can look at it as an answer for question of length n - 1 ( or some other lesser length, generally something that can be achieved from an atomic operation ), plus some trivial atomic operations. So in the case of edit distance, what is an atomic operation on string edits. We have insertion, removal, or changing. And if you create a table like the one in the video, the three separate n-1 length question corresponds to the three cells to the left, diagonal, and top. The minimum of the three is choosing the best way to starting point from the previous three states, and + 1 is the cost to go from that state to the current state.
@uditkanotra9393
@uditkanotra9393 4 жыл бұрын
Use f[i][j] to represent the shortest edit distance between word1[0,i) and word2[0, j). Then compare the last character of word1[0,i) and word2[0,j), which are c and d respectively (c == word1[i-1], d == word2[j-1]): if c == d, then : f[i][j] = f[i-1][j-1] Otherwise we can use three operations to convert word1 to word2: (a) if we replaced c with d: f[i][j] = f[i-1][j-1] + 1; (b) if we added d after c: f[i][j] = f[i][j-1] + 1; (c) if we deleted c: f[i][j] = f[i-1][j] + 1; Note that f[i][j] only depends on f[i-1][j-1], f[i-1][j] and f[i][j-1], therefore we can reduce the space to O(n) by using only the (i-1)th array and previous updated element(f[i][j-1]).
@tejasnaik1671
@tejasnaik1671 3 жыл бұрын
Great logic bro!!! Really made the problem ez
@sritharan20
@sritharan20 9 жыл бұрын
Hi Tushar, Great Job Man, one small suggestion-> it would be great maybe if you tell about the practical application of the programs we can actually do some real time implementation of it and i think it add more value to it :). Kudos Happy coding!!!
@sarikaranjitkumar174
@sarikaranjitkumar174 4 жыл бұрын
Thank you for the great explanation!
@sahithikambhampati4571
@sahithikambhampati4571 4 жыл бұрын
Super explanation , This is so much usefull for me
@malvikark124
@malvikark124 4 жыл бұрын
Great explanation. Thanks so much!
@masoomakram4270
@masoomakram4270 9 жыл бұрын
Awesome explanation... Finally I understood. Thank You.
@maralsalamzadeh1052
@maralsalamzadeh1052 3 жыл бұрын
Perfect description 👌
@younusahmed23
@younusahmed23 7 жыл бұрын
hey thank you for this video it was extremely helpful and it helped me understand a complex concept in only 10 minutes. Awesome video
@apoorvchaturvedi6614
@apoorvchaturvedi6614 9 жыл бұрын
very nice explanation...thank you Tushar.
@Toxx98
@Toxx98 9 жыл бұрын
Thank you for your videos, helped me understand it properly.
Minimum Edit distance (Dynamic Programming) for converting one string to another string
28:22
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 169 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 157 М.
Lecture 21: Dynamic Programming III: Parenthesization, Edit Distance, Knapsack
52:41
Subset Sum Problem Dynamic Programming
9:07
Tushar Roy - Coding Made Simple
Рет қаралды 542 М.
If you're ambitious but lazy, please watch this video...
12:57
Mark Tilbury
Рет қаралды 228 М.
0/1 knapsack problem-Dynamic Programming | Data structures and algorithms
27:31
Jenny's Lectures CS IT
Рет қаралды 1,4 МЛН
2 1 Defining Minimum Edit Distance 7 04
7:05
From Languages to Information
Рет қаралды 20 М.
Edit Distance of two strings - Real world application
18:25
Gaurav Sen
Рет қаралды 70 М.
How I learned to code in 3 months (and got several offers)
12:54
Coding Jesus
Рет қаралды 210 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН