KMP Algorithm Part 1 | Prefix Function
ฝัง
- เผยแพร่เมื่อ 30 ก.ย. 2024
- KMP is a linear time string matching algorithm where the logic or intuition behind this algorithms is very difficult to grasp. So in this video I can explain the concept behind the KMP algorithm, the prefix function. I explain the logic behind building the prefix function and discuss the time complexity as well as the pseudo code.
This is the best explanation of prefix function of KMP algorithm Ive ever seen on youtube! Thank you so much for making this great video!
Thanks for the amazing video this algorithm is quite complex to grasp but after watching you video it is cakewalk
I could not sleep for 2 days not understanding how we chose K less than L in the mismatch case, *thank you*!!
I appreciate you uploading this video. All the other videos I've looked at don't go into the mathematical rigor of how the PI prefix table is generated; they just give an algorithm which can be easily forgotten.
There is a lot of Garbage on KMP in youtube but this is Pure Gold. Was able to get the idea of finding L effectively from this. No other video was able to explain it this thoroughly.
thank you bro, believe or not I have spend one day to learn this algo and now I understand logic, thank you sir again
The best explanation I have ever seen of lps array to get intuition rather than getting code only. Thank you so much for helping me.
Great video man !!! Probably the most elaborated explanation on prefix function.
Thanks a lot!!
why stop uploading videos we need more videos from you about different algorithms
what was this everything was over the head, have to watch again
This video helped me to visualize the article on cp-algorithms. Otherwise it was very confusing to me Thanks
Thanks . It was really helpful. Don't know why downvotes on codeforces.
I'm glad it was helpful! Thanks for watching!
So, is the O(n) thing like this:
To get a drop of 't1' we should have moved earlier 'x1' steps in 'for loop' after the previous drop, and x1 >= t1 (otherwise drop wouldn't be possible);
So like Complexity of Drops is Sum(ti)
Yup!
@@fluentalgorithms4847 Crystal clear explanation, one of the best videos in algos, thanks!
Very nice and simple explanation of a complex algorithm like KMP. Loved it.👍👍
best explanation so far for kmp algo . Thanks a lot man for your efforts!!
amazing explanation...just amazing :O
Glad you liked it!
Hi I have the pattern "zyxwabacddfghabacdjhlop" . Won't pi function return all zero? There are two patterns , one prefix, another suffix .
Will your algorithm work here ?
excellent work.
Toughest topic yet.
why is pi of 8 equal to 1 and not 2? Ps: I'm referring to the last example
I have same doupt
How pi (7 ) =1?
best explanation
bro after much re-watching the video i still can't understand the line if(s[i]==s[pi[i-1]]) pi[i] = pi[i-1] + 1;
k denotes next longest string which is a proper prefix and a proper suffix for substring 0 to i. Shouldn't the value of k should simply be l-1? Its not obvious why it is pie(l-1) rather than l-1.
thx
GREAT
thank you so much. this is very easily understanded to me, previously i saw many videos they are not properly understanded to me but this video gave a clear picture about kmp longest prefix function
So well explained why j = failure[j -1] when the prefix-suffix match can't extend.
Thats an amazing explanation, thank you very much
How can we convert this algorithm so that we have no overlap between prefixes and suffixes? Meaning that lps[i]
finally get it after wasting hours trying other videos. Quite good explanation
You are awesome bro. Great explanation. Thanks, may God bless u.
Is the complexity you calculated for inner while loop amortized complexity of it?
Good explanation. People who dislike it, please write a reason for that. Don't just press the button.
Vera level explaination clear understanding super sir
This is the best video i ever seen for kmp algo . you make kmp algorithm veri easy.
Please try to make more video just like it for other algos , so that we can learn any algo in deep easily.
You explained inner while loop max. iteration really well.
That was the crux inorder to understand TC for prefix function.
Thanks.
Just wonderfully explained... Went through so many high profile videos... But could not understand... Thank you do much... Finally clearly understood... Awsome video....
Thanks finally understood..
Great video, thanks buddy! :D
best explaintation avaiable on the internet watch it patienlty
helped a lot
thnak u
I am not able to understand the time complexity part
Best Explanation... Couldn't grasp from cp algorithms. ur vdo helped a lot
best explanation of prefix function on internet
Thank you so much really helpful
Beautifully explained !! out of the box
Explained as simply as possible. Love it.
Great work, thank you.
Thorough explanation. Thanks a lot
Thanks bro
why does this video has so less views.
if the string is "aaaaaaaaaab" then the inner while loop will run ~n times the complexity will be O(n^2)??Am I correct?
O(1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 9) = O(19)
inner while loop run only one time for n times but in rest of case it will run only one time .
@@sachinsingh1956 thank you
awesome explanation bro
Great work, great explanation
awesome explanation
Really helpful. Thanks.
This was a topic i thought to explain but after i seeing your video i think it's been done in a good way already .