KMP algorithm | Pattern search algorithm | string search algorithm

KMP algorithm | Pattern search algorithm | string search algorithm

Techdose

5 лет назад

91,738 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@diveshrajput572
@diveshrajput572 - 19.02.2021 20:52

Very much helpful rather than other videos

Ответить
@Dee_Rai
@Dee_Rai - 02.03.2021 15:47

You are doing a great job. Learning alot from your videos.

Ответить
@protyaybanerjee5051
@protyaybanerjee5051 - 12.03.2021 21:37

Which software/hardware do you use to whiteboard ?

Ответить
@sharanpreetchadha3579
@sharanpreetchadha3579 - 26.03.2021 16:48

Sir , please make video on Boyer Moore algo , there is no good video about it on the net

Ответить
@satishshingade8514
@satishshingade8514 - 03.04.2021 19:15

u should take different examples .. everything else was great

Ответить
@anirbanpal9432
@anirbanpal9432 - 19.05.2021 10:05

Best explanation, I'll be honest before watching it I have already watched 3 videos and 2 articles, but none of it could give me as much clarification as this video did. Thanks @Tech Dose

Ответить
@katilak1827
@katilak1827 - 21.05.2021 12:37

Mind-Blowing Man, You are just Awesome!

Ответить
@anonymoussloth6687
@anonymoussloth6687 - 29.05.2021 16:49

I don't understand one thing. suppose we have a pattern like this:
txt: a a a b a (and so on...)
pat: a a a b b
lps: 0 1 2 0 0

In this case, where there is a mismatch at the last a and b, I understand why pat is started at 0. because there is no prefix that is also a suffix at that point in the pattern.

But why is the txt pointer not shifted back?? How can we be sure that if the pattern is just shifted one place to the right (like in the naive/brute force method) that we won't find a match?

meaning:
a a a b a ...
a a a b b

I know in this case it is not a match, but how can we be sure that this is the case always?

My question basically is, in this algo, we have a i pointer that is iterating through the txt and a j pointer that is iterating through the pat. when there is a mismatch, the j pattern is shifted back a certain amount (which i understand why) but the i pointer is not shifted at all. THIS is what I don't understand. j pointer is shifted based on if there is a prefix that is also a suffix and that makes sense. But i dont understand why the i pointer is not shifted REGARDLESS of whether a prefix is found or not.

Ответить
@sharuk3545
@sharuk3545 - 07.06.2021 22:30

if string abmnbc then Longest PS is 1 but in yout logic its 0

Ответить
@nidhiprakash5084
@nidhiprakash5084 - 21.06.2021 08:47

Can u please give the playlist name in the description too?

Ответить
@shourabhpayal1198
@shourabhpayal1198 - 30.06.2021 19:05

Greatest of all time

Ответить
@v.sreesairam9488
@v.sreesairam9488 - 09.07.2021 16:19

vector<int> lps(string s)
{
int n=s.size();
vector<int> ans(n,0);
ans[0]=0;
i=0;
int j=0;
for(j=1;j<n;j++)
{
if(s[i]==s[j])
{
i++;
}
else
{
while(i>0&&s[i]!=s[j])
{
i=ans[i-1];
}
}
ans[j]=i;
}
return ans;
}
bhaiya ye sahi hai khya please reply

Ответить
@RomanEmpire29
@RomanEmpire29 - 19.07.2021 19:49

great explanation thanks a lot

Ответить
@rithikraj1813
@rithikraj1813 - 27.07.2021 21:37

Why everyone waste 5-10 mins in brute force 🤔🤔

Ответить
@akshatchouhan5199
@akshatchouhan5199 - 02.08.2021 15:46

Can you please provide java code for this algo

Ответить
@AniketSomwanshi-ll7mz
@AniketSomwanshi-ll7mz - 26.09.2021 18:06

Can you tell me how creating the LPS array is O(n) and no quadratic?

Ответить
@girikgarg8
@girikgarg8 - 29.09.2021 00:28

@Tech Dose Can you make a video on Boyer Moore Searching algorithm also? It's there in Love Babbar sheet

Ответить
@mainakmondal5228
@mainakmondal5228 - 13.12.2021 16:20

Very clear explanation...thanks sir...

Ответить
@kanchidoshi6907
@kanchidoshi6907 - 24.03.2022 17:48

Thanks for the video. can you pls explain how would traversal work in case text='aaaaab' and pattern ='aaab'?

Ответить
@ALEEMKHAWAR1
@ALEEMKHAWAR1 - 25.04.2022 13:02

you are just awesome.

Ответить
@kr_ankit123
@kr_ankit123 - 01.06.2022 10:31

Code for the above explanation in C++. Here haystack is text and needle is pattern to be matched. Kindly refer it.
class Solution {
public:
int strStr(string haystack, string needle) {
int n = needle.length();
vector<int>lps(n,0);
int i=0;
int j=1;
while(j<n){
while(i>0 && needle[j]!=needle[i])
i = lps[i-1];

if(needle[i] == needle[j])
i++;

lps[j]= i;
j++;
}
i=0;
j=0;
// for(auto a:lps)cout<<a<<endl;
while(i<haystack.size()){
while(j>0 &&j<n && needle[j]!= haystack[i]){
j = lps[j-1];
}
if(j<n &&needle[j] == haystack[i]){
j++;
}
i++;
if(j==n)return i-n;
}
return -1;
}
};

Ответить
@devraj-2310
@devraj-2310 - 03.10.2022 18:02

I watched 3 videos previously... but this time I got the idea....... thankYou sir...

Ответить
@lambar0
@lambar0 - 02.03.2023 22:08

love the development of intuition ....that is the key

Ответить
@RupamSasmalYt
@RupamSasmalYt - 03.03.2023 17:58

Very easy explanation, Thank u♥

Ответить
@prakhargupta3949
@prakhargupta3949 - 11.04.2023 17:56

thank you

Ответить
@debanjanchakraborty9946
@debanjanchakraborty9946 - 19.04.2023 07:46

The explanation is best in short time

Ответить
@om23999
@om23999 - 25.04.2023 21:04

Best explanation, I have already watched 3 videos but none of it could give me as much clarification as this video did .

Ответить
@WrongDescription
@WrongDescription - 24.06.2023 22:52

Best explanation!!!! Thanks a lot!

Ответить
@agnivashil4130
@agnivashil4130 - 01.07.2023 20:54

still the best explaination found till now....!

Ответить
@amanmishra5409
@amanmishra5409 - 26.08.2023 12:53

tu AA ja MERE close le le thoda TECCHDOSE

Ответить
@amanmishra5409
@amanmishra5409 - 26.08.2023 13:08

THE C++ CODE OF THIS PROBLEM IS HERE
.....
.
.
..
.
..
.
.
..
...
.
.

....
.
.
.
.
..
.
..
..
...
KHUD SE KAR LE SAALE...SAB KUCH TO BATA DIYA

Ответить
@poorbidalal
@poorbidalal - 29.08.2023 15:49

Best One!

Ответить
@yashgajewar9019
@yashgajewar9019 - 05.10.2023 00:15

Great Explanation !!

Ответить
@fraisespasmures9683
@fraisespasmures9683 - 16.10.2023 20:35

Thankksss a lot for this video. I've watched 3 videos trying to understand this algo you're the first one to achieve it with very clear explanations and revelent example. Thanks man <3

Ответить
@sureshdoodler
@sureshdoodler - 18.11.2023 20:32

most underrated channel

Ответить
@ayushshukla2655
@ayushshukla2655 - 04.12.2023 18:56

also explain with code please !

Ответить
@abhinavkumar6344
@abhinavkumar6344 - 05.02.2024 20:15

good explaination, Thank you

Ответить
@John83118
@John83118 - 18.02.2024 01:46

Such an outstanding job! I recently enjoyed a similar book, and it was an absolute masterpiece. "Game Theory and the Pursuit of Algorithmic Fairness" by Jack Frostwell

Ответить
@statusdeveloperss1234
@statusdeveloperss1234 - 29.05.2024 09:44

super bro

Ответить
@shanmukhchandrayama3903
@shanmukhchandrayama3903 - 17.06.2024 07:13

I feel lot of detailing is missed in this explaination. If some one wants a good understanding of kmp algo and how it works, please refere CodeNCode channel. Expected a better and thorough explaination sir.

Ответить
@JayantiChowdhury-x8u
@JayantiChowdhury-x8u - 01.07.2024 23:30

Why we are not moving i back to previous + 1 position?

Ответить
@nanditmaheshwari1363
@nanditmaheshwari1363 - 10.07.2024 07:56

Best video for KMP!!

Ответить
@shivangitiwari2485
@shivangitiwari2485 - 19.08.2024 21:17

hands down.
best video on KMP

Ответить
@prakashpratapsingh7323
@prakashpratapsingh7323 - 20.09.2024 17:33

Great explanation, but I wanna ask whether u were the one in apna college for kmp algorithm. That video has the worst explanation.

Ответить
@EinstienJr
@EinstienJr - 21.09.2024 14:25

KING!

Ответить
@anurag6219
@anurag6219 - 22.09.2024 16:06

Trying to get this algo once more in a coding career of 5 years. will comment again whenever i will try again

Ответить
@adityasikarwar7090
@adityasikarwar7090 - 01.10.2024 08:59

I am trying understand the from last 4 hours ,
I read article at gfg but don't get get whole clarity and also watch many videos on ytube but don't understand complete working, But after watching this video I am completely confident about working of algorithm.
Thanks sir ❤

Ответить
@devmahad
@devmahad - 03.11.2024 20:28

thanks :)

Ответить