Lecture 42: KMP Algorithm || Longest Prefix Suffix

  Рет қаралды 51,964

Coder Army

Coder Army

Күн бұрын

Пікірлер: 206
@CoderArmy9
@CoderArmy9 Жыл бұрын
Concept Chamka ki nahi? Before Jumping to the solution, ek baar 15-20 minute baith ke, khud solve karne ki koshish karna, it will become easy for you. at 1:00:53 pre =2, so it must be at index 2 not at 4, just small correction at last
@akashkewat1219
@akashkewat1219 Жыл бұрын
Yes bhaiya , concepts shined like a diamond💎
@kartik5134
@kartik5134 Жыл бұрын
chamak gaya bhaiya
@NajmGameplay
@NajmGameplay Жыл бұрын
you are the one bro
@AayushDubey_007
@AayushDubey_007 Жыл бұрын
Chamka 🤩
@sauravrajpoot6518
@sauravrajpoot6518 Жыл бұрын
Yess 🎉
@manish_kumar_iitg
@manish_kumar_iitg 6 ай бұрын
4:45 Brute Force Approach :- int n = s.length(); int maxLen = 0; // Iterate over the length of the prefix and suffix for (int len = 1; len < n; ++len) { string prefix; for(int i = 0; i< len; i++){ prefix.push_back(s[i]); } string suffix; for(int i = n-len; i < n; i++){ suffix.push_back(s[i]); } if (prefix == suffix) { maxLen = len; } } return maxLen;
@abhinandantiwari9944
@abhinandantiwari9944 3 ай бұрын
@manpatel9157
@manpatel9157 11 ай бұрын
Bhaiya mza hi aa gaya... I've seen 4-5 videos for this topic, but unable to understand. Lekin jab aapka video dekha to sab chamak gaya...🤩🙏
@manoharmanu9240
@manoharmanu9240 11 ай бұрын
The way you picked up the right examples to explain the tricky part is commendable. Great going brother👏👏
@divyanshsharma673
@divyanshsharma673 Жыл бұрын
I couldn't understand this algorithm at first when I watched, but after some time, when I'm back again... its fixed in my head. Thank you sir !
@priyaanshusoni
@priyaanshusoni Ай бұрын
The best & most underrated DSA course on KZbin far better than Paid courses out there in the market ! THANK YOU
@nownow1025
@nownow1025 10 ай бұрын
you are very hardworking bhaiya. can be seen clearly from your intial submissions.Thank you for teaching us.grateful to u
@varunprajapati5838
@varunprajapati5838 9 күн бұрын
shukriya mere bhai. Mushkil tha concept, behadh asaan bana diya bhai tumne. Bhhout shukriya😊😊🙏🙏
@kodurisaivishnu4916
@kodurisaivishnu4916 2 ай бұрын
one and only the best Explanation on youtube...
@prajitbanerjee8226
@prajitbanerjee8226 5 ай бұрын
Your understanding is crystal clear thats why you are able to explain this flawlessly..hats off to your dedication!!!
@GaneshBhutekar-nu1gd
@GaneshBhutekar-nu1gd 3 ай бұрын
lecture is 1 hour, but I spent 4 hours. Then I cleared the concept of LPS. Thank you, sir.
@alijuttjut8380
@alijuttjut8380 2 ай бұрын
but i spent 7hrs with notes
@prabinaswain3267
@prabinaswain3267 11 ай бұрын
After seeing a lot video of KMT , This video gives crystal clear concept how and why we are able to reduce the Time complexity of finding prefix=suffix
@MO-fg2cm
@MO-fg2cm Жыл бұрын
9:10 space complexity is O(2N) same as O(N)
@rishabhshenoy3258
@rishabhshenoy3258 7 ай бұрын
But bro string ka array so o N2 na??
@joydeep-halder
@joydeep-halder 12 күн бұрын
7:30 Time complexity to get all prefixes or suffixes will be O(n) instead of O(n^2) bhaiya. To compare all the strings it will take O(n * n). So, at the end, overall time complexity is O(n^2)
@saketjaiswalSJ
@saketjaiswalSJ 8 ай бұрын
bhai bahut baar dekha loop mein samjh aaa gya explanation god level bhai really god level
@Playlist-y1f
@Playlist-y1f 21 күн бұрын
Wohoo!!!!!! amazing explanation.
@ayushsinha1696
@ayushsinha1696 12 күн бұрын
Crazy video. Had to try a lot of examples to understand it clearly. thanks for the awesome explaination
@Roman_Baloch
@Roman_Baloch 24 күн бұрын
Ak dum chamak gya . Love your teaching method . LOVE FROM PAKISTAN
@nitinkumar5974
@nitinkumar5974 Ай бұрын
God level explanation...understood everything!
@nitinkumar5974
@nitinkumar5974 Ай бұрын
have subscribed you, next level explanation. This is a single precious video on whole youtube for KMP right now when I am watching this. Worth watching this 1 hour long video. had watched it at 1.5x speed.
@janaSdj
@janaSdj 2 ай бұрын
Finally understand LPS after wasting so many times in other garbage videos. Thank you bro...
@engineershb
@engineershb Ай бұрын
best bhai best kmal ho qsm sy
@pranavarora724
@pranavarora724 Ай бұрын
Was struggling how to build prefix table Best video so far on building prefix table and KMP algo
@riyaraj5720
@riyaraj5720 5 ай бұрын
Awesome explanation sir! So much better than any paid course. Thank you thank you thank you!!!
@i_am_groot3787
@i_am_groot3787 23 күн бұрын
best video on yt .. best explaination
@MohitG7701
@MohitG7701 3 ай бұрын
very good explanation of such a complex logic. Nowhere find this kind of explanation. Thanks for making this video. 🙏
@neerajchopra2758
@neerajchopra2758 Жыл бұрын
no one beat rohit sir 🔥
@_abhi2003_
@_abhi2003_ 7 ай бұрын
Literally one of the best lecture bhaiya...aLWAYS get motivated by seeing u
@pankajkashyap2892
@pankajkashyap2892 6 ай бұрын
chamka diya bhaiya best dsa course in history ever for logic building
@apurvapat3524
@apurvapat3524 Ай бұрын
Best Explanation i have ever seen. Hats off
@vivekpaliwal1876
@vivekpaliwal1876 Ай бұрын
Time liya but ache se smjha diya..also every line of code is understood thanks
@Niki_0011
@Niki_0011 7 ай бұрын
I don't know why college teachers don't teach these questions in this way. You are great, Bhaiya. Love from Uttarakhand ❤️
@vikassinghbisht7305
@vikassinghbisht7305 11 ай бұрын
Pahadi always rocks ❤
@AkshitChaudhary-vx8iw
@AkshitChaudhary-vx8iw Ай бұрын
Mst padhaya hai. hard transform to Easy : )
@BhaveshJaiswal_o7
@BhaveshJaiswal_o7 4 ай бұрын
really a great teacher ,means leagend god level bhai
@Devil-ze9kc
@Devil-ze9kc 6 ай бұрын
Maja aa gya bhai ... Seriously enjoyed the way you revealed the suspense of LPS wala technique
@himanshukumar97
@himanshukumar97 4 ай бұрын
Best explanation ❤ KMP done ✅
@rajendertanwar1881
@rajendertanwar1881 5 ай бұрын
Best explanation ❤ after watching whole video, i assure you (viewers) that you're at right place ✅️
@davidsharma9662
@davidsharma9662 10 ай бұрын
Bro you just nailed it!🔥
@prakashnandan7337
@prakashnandan7337 11 ай бұрын
at 1:00:53 pre ==2, so it must be at index 2 not at 4
@CoderArmy9
@CoderArmy9 11 ай бұрын
right, thanks
@PrashantKumar-gy1qs
@PrashantKumar-gy1qs Жыл бұрын
Hats off to you sir your content is best.
@rocketgamerzz.7577
@rocketgamerzz.7577 Ай бұрын
Brute force ko hum O(N) mein bhi toh kr sakte hain ? agr ek temp string le lein and saare prefixk nikalne k liye iterate over the string , temp mein push_back a character and push_back temp into a vector of string every time , saare prefix aa gaye ,and similary O(n) mien saare suffix nikal sakte hain and then at the end bas saare saare same index waale sting in in pre array and suff array ko compare krna hai ,which is O(n^2).
@atifmalik8012
@atifmalik8012 2 ай бұрын
4:53 //Brute force approach //pass all the test cases but time complexity is O(n²) class Solution { public: int lps(string str) { if(str.size()==1) return 0; int start=0,end=1; while(end
@yashsawalkar646
@yashsawalkar646 3 ай бұрын
Understood all. For the viewers you have to give it a brief thought and dry run it in mid so that it becomes intuitive
@musaifbangi8705
@musaifbangi8705 Ай бұрын
People who read "string matching" from cormen book would know how easy is kmp algorithm 😅
@mydiary6023
@mydiary6023 3 ай бұрын
sir nice explanation aikdum aaram se samajh aaya
@Pixelofficialmohit
@Pixelofficialmohit 24 күн бұрын
Next level content ❤
@Aman_Panchal27
@Aman_Panchal27 11 ай бұрын
Easy to understand than other tutorials and blogs also.
@vidyansh3813
@vidyansh3813 2 ай бұрын
bhaiya at 30:42 why 3 aise toh piche jo hmne 5 th index pe 0 likha vahan toh 2 likh skte the \
@musaifbangi8705
@musaifbangi8705 24 күн бұрын
Kmp is use for string matching that is to find a string s1 is part of s2 or not
@manikgoyal8026
@manikgoyal8026 11 ай бұрын
thank you bhaiya, after struggling too much for kmp, today I got the clarity
@sarojkumar-wb7tk
@sarojkumar-wb7tk 7 ай бұрын
best explanation 🤩
@AmanKesari-d6e
@AmanKesari-d6e 2 ай бұрын
Too good bhaiya.
@vanshikasoni6950
@vanshikasoni6950 6 ай бұрын
Space Complexity of brute force is O(2N) ~ O(N)
@tusharnanda3885
@tusharnanda3885 Жыл бұрын
at 1:01:11 it should be index = 2 ???
@fachoyt9686
@fachoyt9686 Жыл бұрын
Yes.
@joydeep-halder
@joydeep-halder Жыл бұрын
9:05 Space complexity will be O(n^2) because every element of prefix or suffix array will have kind of n length.
@subhojit627
@subhojit627 Жыл бұрын
I think the space complexity will be O(n)
@Sony_47
@Sony_47 Жыл бұрын
i am also think its o(n), because in space n+n = n.
@joydeep-halder
@joydeep-halder Жыл бұрын
My thought process behind O(n²) is that, for suffix, the string length will be like 1,2,3,4...n-1 and for prefix also it will be array of strings of length 1,2,3,4..n-1 So basically if we join two arrays string as compliment like from array1 we take string of length 1, and from array2 we take string n-1. Then from array1 we take 2, and from array2 n-2 and like so. Thus both array will compliment each other and will create an array of n strings and each string will have n length. So it will become basically O(n²)
@NajmGameplay
@NajmGameplay Жыл бұрын
u r gae@@joydeep-halder
@Algorithmswithsubham
@Algorithmswithsubham Жыл бұрын
2n? hoga kya
@karankumar3983
@karankumar3983 Жыл бұрын
24:39 to 27:05 49:22 to 54:30 conclusion of whole LPS concept
@sarveshpawaskar5363
@sarveshpawaskar5363 3 ай бұрын
Thank you Rohit sir/bhaiyya.....❤
@motivationalmajakkhel
@motivationalmajakkhel 5 ай бұрын
Hello bhaiya, brute force approach to check for longest prefix and suffix int maxi = 0; int first = 0, last = s.size()-1; string one=""; string two=""; while(first0){ one+=s[first]; two=s[last]+two; if(one == two){ maxi = one.size(); } first++; last--; }
@abhinavparashar1934
@abhinavparashar1934 6 ай бұрын
Corrected code of Longest prefix suffix Method : Longest prefix suffix Code start from here #include #include using namespace std; int main() { string s; cout
@killflag9850
@killflag9850 Ай бұрын
Starting mee meri bhat ke char hoo gayi yar 😂
@musaifbangi8705
@musaifbangi8705 24 күн бұрын
1:00:30 the index is 2 not 4
@MaheshPatil-of1zy
@MaheshPatil-of1zy 3 ай бұрын
Imagine If One Can Discover KMP in the interview itself to solve, Just GOD LEVEL🥶🥶🥶
@janaSdj
@janaSdj 2 ай бұрын
Not possible
@janaSdj
@janaSdj 2 ай бұрын
Too hard to figure it out....
@fachoyt9686
@fachoyt9686 Жыл бұрын
Great Lecture.
@isroindia9648
@isroindia9648 2 ай бұрын
My code for brute force approach at 4:40 text = "ABCDEABCD" #prefix array list1=[] for i in range(len(text)-1): if len(list1)==0: list1.append(text[i]) else: res=list1[i-1]+text[i] list1.append(res) for i in list1: print(i) #suffix array list2=[] j=len(text)-1 while j>0: if len(list2)==0: list2.append(text[j]) else: res=text[j]+list2[-1] list2.append(res) j-=1 for i in list2: print(i) # calculating longest prefix suffix max_length=0 for prefix in list1: if prefix in list2: length=len(prefix) max_length=max(max_length,length) print(max_length)
@snehaprasad8
@snehaprasad8 3 ай бұрын
GREAT EXPLANATION🤩
@Priceful_peace
@Priceful_peace 2 ай бұрын
Time complexity O(2n-2) for brute force ?
@akhileshbhagat6721
@akhileshbhagat6721 Жыл бұрын
hardest hardest kh kr asani se samjha dia wah
@saitanush9453
@saitanush9453 6 ай бұрын
Tq bhaiya, aaj kuch naya seekha😄😄
@priyanshasharma4443
@priyanshasharma4443 3 ай бұрын
you made this topic easy thanks
@SamirKumarRakshit-c4z
@SamirKumarRakshit-c4z 4 ай бұрын
Brute force in python: word = "ABGHCABGH" prefix = [] ans = "" for i in range(8): ans += word[i] prefix.append(ans) suffix = [] anss = "" for i in range(1, 9): anss = word[-i]+anss suffix.append(anss) for index in range(len(prefix)): if(prefix[index] == suffix[index]): print (prefix[index])
@rishabhshenoy3258
@rishabhshenoy3258 7 ай бұрын
9:11 On2 hogi kyunki ham string ka array banayege jo string is a type of array , so 2d array jesa kaam hoga
@heetpatel3037
@heetpatel3037 10 ай бұрын
Aapki jitni tarif kare utni kam hai ❤
@myyoutubeisthis
@myyoutubeisthis 7 ай бұрын
Thank you sur for this amazing explanation
@nitinduke
@nitinduke Жыл бұрын
bhot ache se samjh aagya bhaiya
@JitCodeHub.
@JitCodeHub. 10 ай бұрын
KMP Stands For????????????????
@Vaibhavvashishtha123
@Vaibhavvashishtha123 9 ай бұрын
Knuth morris pratt
@shrivvlogs6045
@shrivvlogs6045 Жыл бұрын
Love u bhiya ❤️
@AlphaJava-q6j
@AlphaJava-q6j Жыл бұрын
Sach me bhaiya tussi great ho 🎉🎉❤❤❤ kal ke DAA ke exam me fod ke aunga🎉❤
@pratik.784
@pratik.784 Жыл бұрын
bhot badhiya samjhaya
@shivnathsinghgaur5972
@shivnathsinghgaur5972 9 сағат бұрын
HA G Bhiya Chamka . Thank you
@piyushsinghdtu456
@piyushsinghdtu456 5 ай бұрын
thanks sir
@akashkewat1219
@akashkewat1219 Жыл бұрын
Done todays lecture thank Bhaiya😊
@kaushalshinde8
@kaushalshinde8 11 ай бұрын
best explaination..
@YashSaini007
@YashSaini007 Жыл бұрын
Bhaiya Radhe Radhe 🙏
@khushisingh-hb9kq
@khushisingh-hb9kq Жыл бұрын
Great explanation
@joydeep-halder
@joydeep-halder Жыл бұрын
Good morning bhaiya ❤❤
@heetpatel3037
@heetpatel3037 10 ай бұрын
Chamka bhaiya chamka 👍🏻
@vipulkumar1830
@vipulkumar1830 11 ай бұрын
chamak gya bhaiya ek dam
@bharatmehta30
@bharatmehta30 Жыл бұрын
Thanks bhaiya. chamak gya
@ankushladani496
@ankushladani496 Жыл бұрын
Thanks Bhaiya...❤🎉
@Sony_47
@Sony_47 Жыл бұрын
bhaiya i think , 52:00 me D me LPS ki value 2 hogi . ky mai galat hu?
@Ajeetkumar-uo4hf
@Ajeetkumar-uo4hf Жыл бұрын
Rohit bhai median of two sorted array (Binary Search) wala question pe video bana do . Avi tak 10 video dekh chuka hu youtube par but samjh nhi aa rha hai pls expain🙏
@rashisahu8511
@rashisahu8511 Жыл бұрын
Amazing explanation
@AMITKUMAR-ds4hp
@AMITKUMAR-ds4hp Жыл бұрын
Good morning boss ❤
@joydeep-halder
@joydeep-halder Жыл бұрын
Bhaiya mai exact algorithm nhi bana paya, lekin mai soch rha tha ki humlog is fact ko use ker sakte hai kya ki mid se start kare dhundna. then vo initial search space thora kam ho jayega. 🤔🤔
@mdreion
@mdreion 3 ай бұрын
Best❤️💚
@ankushladani496
@ankushladani496 Жыл бұрын
Done Bhaiya... Day 58/180 ✅
@omprakashnahak3074
@omprakashnahak3074 6 ай бұрын
best KMP algorithm video ❤
@Aryan-wl7mc
@Aryan-wl7mc Жыл бұрын
Is this last video on strings?
@VikasKumar-th7ml
@VikasKumar-th7ml Жыл бұрын
no probably 1 or 2 lecture aur honge
@sakshinadankar3782
@sakshinadankar3782 11 ай бұрын
Thank u😊
@lyricalboy9281
@lyricalboy9281 Жыл бұрын
bhaiya concept bhi chamka aur code bhi #180dayscodingchallenege #coderArmy
Lecture 43: String Matching || KMP Algorithm
49:02
Coder Army
Рет қаралды 34 М.
Lecture 18: Time and Space Complexity From Zero To Advance
1:21:04
Coder Army
Рет қаралды 122 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
9.1 Knuth-Morris-Pratt KMP String Matching Algorithm
18:56
Abdul Bari
Рет қаралды 1,8 МЛН
How to Remember Everything You Read
26:12
Justin Sung
Рет қаралды 3 МЛН
Kmp (knuth-Morris-Pratt) pattern matching algorithm
11:36
LEARN DS FAST
Рет қаралды 6 М.
Learn Coding & Get a Job (in 2025) 🔥
16:54
CodeWithHarry
Рет қаралды 712 М.
Knuth-Morris-Pratt KMP String Matching Algorithm | Search Pattern | GFG POTD
1:05:36
Lecture 41: Sliding Window Protocol on Strings
1:19:34
Coder Army
Рет қаралды 43 М.
Kunth - Morris - Pratt String Matching Algorithm in Hindi with Solved Examples
13:16
Easy Engineering Classes
Рет қаралды 176 М.
Knuth-Morris-Pratt(KMP) Pattern Matching(Substring search)
12:50
Tushar Roy - Coding Made Simple
Рет қаралды 1,1 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН