Knuth-Morris-Pratt (KMP) Pattern Matching Substring Search - First Occurrence Of Substring

Sdílet
Vložit
  • čas přidán 3. 01. 2019
  • Free 5-Day Mini-Course: backtobackswe.com
    Try Our Full Platform: backtobackswe.com/pricing
    📹 Intuitive Video Explanations
    🏃 Run Code As You Learn
    💾 Save Progress
    ❓New Unseen Questions
    🔎 Get All Solutions
    Question: Given a string s and a pattern p, determine if the pattern exists in the string. Return the index of where the first occurrence starts.
    Further Explanation From Tuschar Roy: • Knuth-Morris-Pratt(KMP...
    The Brute Force
    The naive approach to solving this is looking in s for the first character in p.
    If a match is found we begin a search from that index, call it i (for intersect).
    We compare the 2nd character of p with index i + 1 of s
    We compare the 3rd character of p with index i + 2 of s
    ...and so on until we have matched to all of p without either having overrun s or having found a mismatch between characters being compared.
    We can then return i as our answer.
    It doesn’t work well in cases where we see many matching characters followed by a mismatching character.
    Complexities:
    Time: O( len(s) * len(p) )
    In a simple worst case we can have
    s = "aaaaaab"
    p = "aaab"
    The problem is that for each first character match we have the potential to naively go into a search on a string that would never yield a correct answer repeatedly.
    Other Algorithms
    There are three linear time string matching algorithms: KMP (nuth-Morris-Pratt), Boyer-Moore, and Rabin-Karp.
    Of these, Rabin-Karp is by far the simplest to understand and implement
    Analysis
    The time complexity of the KMP algorithm is O(len(s) + len(p)) "linear" in the worst case.
    The key behind KMP is that it takes advantage of the succesful character checks during an unsuccessful pattern comparison subroutine.
    We may have a series of many comparisons that succeed and then even if one fails at the end, we should not repeat the comparison work done since we already saw that a series matched.
    What we will do is very similar to the naive algorithm, it is just that we save comparisons by tracking the longest propert prefixes of pattern that are also suffixes.
    The key is that everytime we have a mismatch we try our best to prevent going backwards in s and repeating comparisons.
    Algorithm Steps
    We will preprocess the pattern string and create an array that indicates the longest proper prefix which is also suffix at each point in the pattern string.
    A proper prefix does not include the original string.
    For example, prefixes of “ABC” are “”, “A”, “AB” and “ABC”. Proper prefixes are “”, “A” and “AB”.
    For example, suffixes of "ABC" are, "", "C", "BC", and "ABC". Proper prefixes are "", "C", and "BC".
    Why do we care about these??
    We know all characters behind our mismatch character match.
    If we can find the length of the longest prefix that matches a suffix to that point, we can skip len(prefix) comparisons at the beginning.
    The key reason we care about the prefix to suffix is because we want to "teleport" back to as early in the string to the point that we still know that there is a match.
    Our goal is to minimize going backwards in our search string.
    Complexities:
    Time: O( len(p) + len(s) )
    We spend len(p) time to build the prefix-suffix table and we spend len(s) time for the traversal on average.
    Space: O( len(p) )
    Our prefix-suffix table is going to be the length of the pattern string.
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    HackerRank: / @hackerrankofficial
    Tuschar Roy: / tusharroy2525
    GeeksForGeeks: / @geeksforgeeksvideos
    Jarvis Johnson: / vsympathyv
    Success In Tech: / @successintech
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    This question is number 7.13 in "Elements of Programming Interviews" by Adnan Aziz (they do Rabin-Karp but same problem, different algorithm)
  • Věda a technologie

Komentáře • 556

  • @BackToBackSWE
    @BackToBackSWE  Před 5 lety +66

    Table of Contents: (I'm literally screaming. I'm sorry. I want to redo this video to make it better.)
    Introducing The Creators The KMP Algorithm* 0:00 - 0:15
    Problem Introduction With The Naive Approach 0:15 - 2:30
    Why The Naive Approach Is Not Good 2:30 - 2:45
    Walkthrough How The Algorithm Works 2:45 - 8:14
    Building The Suffix-Proper-Prefix Table 8:14 - 12:34
    Using The Suffix-Proper-Prefix Table In Traversal Walkthrough 12:34 - 15:08
    Time & Space For The Table Build Step 15:08 - 15:51
    Time & Space For The Traversal Step 15:51 - 16:08
    Overall Time & Space 16:08 - 16:25
    Summarizing Our Learnings 16:25 - 16:40
    Wrap Up (Begging For More Subs) 16:40 - 17:05
    *All 3 of the creators published the final paper together.

    • @iamjimfan
      @iamjimfan Před 4 lety +2

      That's good enough, I was looking for info on distributed substring searching of very large string. It gives me nice refresh on the basics.

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +2

      great

    • @piyushyadav9006
      @piyushyadav9006 Před 3 lety +1

      11:50 was the tricky part as we use KMP logic again in building the table itself.

    • @utkarshbhatnagar768
      @utkarshbhatnagar768 Před 2 lety +1

      it is the best explanation I found on youtube of KMP algo, no need to redo it

    • @jaivignesh2302
      @jaivignesh2302 Před 2 lety

      Hey ., this is great ,,, greater than geeks for geeks really !!!

  • @ahmedsyed76
    @ahmedsyed76 Před 3 lety +262

    An algorithm invented by 3 people and they expect us to come up with this in 45 min. Makes sense

    • @salmanbehen4384
      @salmanbehen4384 Před 3 lety +38

      Fun fact: Dijkstra came up with his algorithm within 20 minutes while having a walk.

    • @_rmw
      @_rmw Před 3 lety +74

      Leetcode "easy"

    • @StudyWithRishiP
      @StudyWithRishiP Před 3 lety +49

      @@salmanbehen4384 Fun Fact : Dijkastra was thinking about this for a long time.

    • @user-oy4kf5wr8l
      @user-oy4kf5wr8l Před 3 lety +6

      those algo interview questions are the most meaningless things ever.. system design is kind of interesting...but algo..jesus

    • @coolmangame4141
      @coolmangame4141 Před 3 lety +1

      well its popular so its good to know it

  • @dimejifaluyi1759
    @dimejifaluyi1759 Před 5 lety +169

    BRO STOP YELLING AT ME I ALREADY SUBBED I KNOW YOU'RE GOOD

  • @user-oz7mq8gh8n
    @user-oz7mq8gh8n Před 3 lety +25

    You're the best explainer of algorithms I've ever seen. The extra very visible colored text on the screen while you're explaining also makes a huge difference.

  • @shinra9714
    @shinra9714 Před 4 lety +75

    I never knew I needed this kind of teaching which makes me feel like im scolded in order to understand why a box is incremented.

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +6

      lmao, sorry, old video, forgive me

    • @kiranteja6392
      @kiranteja6392 Před 4 lety +7

      @@BackToBackSWE Thats actually helped me to understand easily.Best way to teach is to stress key point to understand that concept

  • @GPT-X938
    @GPT-X938 Před 4 lety +11

    I had a hard time understanding KMP but you broke it down so well and I get it now. This goes for all the videos I've watch from you, thank you!

  • @lamihh
    @lamihh Před 4 lety +23

    Thanks to you I'm one less algoritm away towards achieving my dream. So thanks for the good work and keep it up ;))

  • @anandchowdhury9262
    @anandchowdhury9262 Před 4 lety +13

    The only one to explain the "THE TRICKY PART WHICH SO MANY OTHERS SO CONVENIENTLY SKIP"

  • @sanskrititomar183
    @sanskrititomar183 Před 4 lety +7

    Your explanations are amazing! This is the first time I fully understand the kmp algorithm. Thanks a lot! Keep up the good work ;)

  • @fredwooten14
    @fredwooten14 Před 5 lety +164

    Calm down a bit you good.

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety +2

      hahahahahahahaha, thanks

    • @peeyar2000
      @peeyar2000 Před 5 lety +8

      @@BackToBackSWE ...Yes.. please slow down.. That will help the audience to process what you are saying.

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety +3

      @@peeyar2000 ok

    • @jonathanfoster5106
      @jonathanfoster5106 Před 4 lety +31

      @@BackToBackSWE 100% disagree with this comment. your cadence and charisma is half the reason this is all working so well. currently watching through EVERY video on this channel. It's literally the best resource I've ever found on this stuff.

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety

      @@jonathanfoster5106 hahahahaha ay, wassup, local to this topic they are right and their comments are attesting to the explanation's weakness and incomplete nature. Globally what you observe are correct.

  • @uHnodnarB
    @uHnodnarB Před 3 lety

    I'm doing leetcode looking for jobs right now, and this was really helpful! I actually understood how the algorithm works for once, instead of the video just showing the algorithm working. Thanks!

  • @rahulsaxena5015
    @rahulsaxena5015 Před 4 lety +8

    Now that's a cool explanation of a seemingly difficult concept. The thing is you cannot watch this video without some sort of preparation. You have to understand the limitations of the naive approach and then think of a logical method/alternative to overcome that. Only after that, when you watch the video and implement the algo, would it become clear to you...
    Good job with the video, guys!!

  • @LennethValky19
    @LennethValky19 Před 4 lety +1

    I love the way you reply literally every single comment in this channel, this shows how much you like what you're doing. And indeed we can see it in your eyes while explaining! Thanks so much for bringing content with such quality and love! I don't usually write comments on CZcams but this channel made me stop for some few minutes to write this.

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +3

      I don't like what I'm doing, 70% of the time I hate it. I am just dedicated to whatever I start, it must end successfully at any cost.

    • @LennethValky19
      @LennethValky19 Před 4 lety +1

      @@BackToBackSWE Hahaha really you don't like it? I was 100% sure you loved it because you put so much energy into explaining the algorithms to us.
      I guess I was wrong then...

  • @akaraze749
    @akaraze749 Před 3 lety +1

    I trust This dude's Teaching skills with my career, He's so CLEAR, To the Point and explains in Simple Language that no CZcams Channel Does that. Absolutely Loved it.

  • @ghabrielmielli5858
    @ghabrielmielli5858 Před 3 lety +1

    thank you for this content, it helped me a ton!! I loved how hyped you were explaining this algorithm, great job!

  • @nickkiermaier667
    @nickkiermaier667 Před 4 lety +2

    Good lord glad I found you! This is the best explanation I've found! Thank you! Will be following. Don't slow down your enthusiasm makes it fun.

  • @vinnerzucc1154
    @vinnerzucc1154 Před 4 lety +3

    Wow, I applaud your dedication to try and reply to all the comments mate! Good stuff and honestly I should've discovered this channel before!

  • @pulkitjain9599
    @pulkitjain9599 Před 5 lety +2

    After reading a bit on Internet and then coming to your video. I got it straight into my head. Really well explained but people really need to have some background before watching such algorithms to just grasp it at one go.
    Thanks man

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety

      Oh yeah, this video is old and made in an "ok" fashion

  • @hussainalramadan7517
    @hussainalramadan7517 Před 2 lety +1

    Thank you from my heart.
    I was about to give up on this algorithm, until I found this video, I appreciate this work so much.

  • @nono-ip2fv
    @nono-ip2fv Před 4 lety +38

    I really like your passion and felt very involved during the video
    So far it’s the most approachable KMP video I’ve seen.
    I vote for keeping the speed and voice as is, they allow the video to stand out in a good way

  • @kvnr49
    @kvnr49 Před 4 lety +1

    Like your style of explaining. One of the videos that kept my attention through the end and not bore me to lose focus. Thanks!!

  • @basu.arijit
    @basu.arijit Před 4 lety +3

    This is the first time I understood KMP algorithm. Thanks a lot!

  • @supratiksadhu
    @supratiksadhu Před 4 lety +1

    Dude, thanks. That's the most elaborative explanation I came across. Good work!

  • @khushdevpandit5865
    @khushdevpandit5865 Před 2 lety +1

    Thanks, man!
    This is the Best ever explanation on CZcams. I was stuck on this algorithm for hours

  • @denys3211
    @denys3211 Před 5 lety +1

    Great video! Very well explained, as usual. Thank you.

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety

      haha this vid is decent..old thought too...I wanted to redo it but I never did

  • @mdotub71
    @mdotub71 Před 3 lety +2

    Hey dude, thanks for the great vids. I do not know how and why, but somehow your logical explanation of the stuff just rocks compared to many many others. Pls keep doing the good stuff, bro.

    • @BackToBackSWE
      @BackToBackSWE  Před 3 lety

      cuz im average intellect and decided to do all this

  • @bryanparis7779
    @bryanparis7779 Před 2 lety +1

    after lots of videos about Knuth-Morris-Pratt algorithm i just understood how it works...when we have dismatch we just go one step behind and we look at the value of that step and thats it!this is where the i goes(index)..pfff at last!THANKSSSSSSS.LOVE YOU BOY

    • @BackToBackSWE
      @BackToBackSWE  Před 2 lety

      hahaha! try this 5 day free mini course for some good content backtobackswe.com/

    • @bryanparis7779
      @bryanparis7779 Před 2 lety +1

      @@BackToBackSWE im on my way to this...many thanks from a Greek postgraduate in Maths and Statistics.

  • @PheezxCoding
    @PheezxCoding Před 2 lety

    Amazing content. I've been going through your videos and they are so helpful!

  • @varunrao2135
    @varunrao2135 Před 4 lety +1

    This is amazing. SO clear. Explain every single part of it.

  • @TheJackpotgamer
    @TheJackpotgamer Před 4 lety +1

    I got confused on the topic quite a bit, but this video explains it real clearly, thanks man, this is greatly appreciated

  • @pablocom
    @pablocom Před 3 lety +1

    Man you are great, all your explanations are deep and clear, thanks for your videos 🙌🙌

  • @jalanshmunshi7061
    @jalanshmunshi7061 Před 4 lety +1

    Awesome explanation! Don't worry, the way you're explaining is not screaming. It is rather the enthusiasm with which you explain a problem and I have seen that enthusiasm in almost every video of yours.
    Looking forward to more of your explanations. Kudos to you!

  • @TonyGognitti
    @TonyGognitti Před 2 lety +2

    Brilliant explanation - certainly one of the best for the KMP algorithm. I like how you focus on the intuition behind the algorithm, as opposed to the traditional textbook approach. Have you considered writing a book on algorithms?

  • @Prashantkumar-pn6qq
    @Prashantkumar-pn6qq Před 4 lety +1

    Amazing Amazing explanation buddy! Could not find many on CZcams explaining as clearly. Thanks.

  • @ShivamShukla-uz9xs
    @ShivamShukla-uz9xs Před 4 lety +2

    Really a superb explanation underlined and outlined all components of the algorithm in a very strategic way. The best thing about your videos is the energy you impart over the explanations about the tricky part or sth unintuitive. Thanks.

  • @priyanshusingh2454
    @priyanshusingh2454 Před 3 lety +1

    The best explanation all over the internet. Hats off to you sir!

  • @h-arshit
    @h-arshit Před 5 lety +1

    Finally got something worth watching... thanks buddy

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety

      hahahahaha ok, thx, I want to redo this but yeah

  • @insidecode
    @insidecode Před 4 lety +2

    Very nice video! it's also interesting to know that we can consider the time complexity as O(n), because if we add an early exit condition for when p is longer than s (where we directly return -1), then we can affirm that m cannot be greater than n, so in the worst case, m would be equal to n, which gives 2n, and by removing the constant, we get a time complexity of O(n)

  • @tanmaymalhotra4450
    @tanmaymalhotra4450 Před 3 lety

    people commenting "stop yelling" and all I see is the passion with which you are trying to teach us in the simplest way possible. I came here after watching 2-3 vids but your video cleared all my doubts. Thank you for making this video.

  • @anshu7715
    @anshu7715 Před 3 lety

    if there is any topic i am searching on utube nd u have a video on it. i just simply watch it first, and then continue my research(that most of the time is not even needed, as u clear all the related concepts). thanks

  • @sarthakbhatia7888
    @sarthakbhatia7888 Před 3 lety +2

    Honestly..This is the best explanation out there on youtube....Thanks:)

  • @pei-yaochang3234
    @pei-yaochang3234 Před 5 lety +2

    Awesome! What a concise explanation.

  • @LN_1214
    @LN_1214 Před 11 měsíci

    Greatly explained, i saw a couple other videos but yours made me really understand it

  • @deepakbhoria4172
    @deepakbhoria4172 Před 3 lety +3

    Didn't understand this during college... but you sir made me understand this within minutes... Great explanation :)

  • @satyadeeproat2012
    @satyadeeproat2012 Před 4 lety

    Whenever I don't understand an algorithm, I come to this page. Dude shout at me like my high school track and field coach, but it definitely gets in my head

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +1

      great to hear - hahahaha, fuck interviews I hate this. No one was going to go and do this and teach in an academic manner that makes sense. We still haven't lived up to the mission/vision I set out with...it's why I get mad...99% of those who understand something won't go teach it, let alone give up their free time and do it for the internet and teach it well.
      rant

  • @subham-raj
    @subham-raj Před 4 lety +3

    Your explanations are *dope*

  • @avirajbevli7268
    @avirajbevli7268 Před 3 lety

    I like how you personally react to almost all comments. Keep up the good work bro :)

  • @KhanjanShukla
    @KhanjanShukla Před 3 lety +2

    Thanks a lot. Really helped in understanding clearly !

  • @shivajunna
    @shivajunna Před 4 lety +1

    Thank you, bro, for the brief explanation. I have one question for string pattern matching in a different approach. What does it make the two-pointer technique (sliding widow technique) slower than this Algorithm?

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +1

      I'm not sure, I don't remember this too much

  • @Amir_86
    @Amir_86 Před 4 lety +1

    Really like the way you explained! thanks man!

  • @FabioMontefuscolo
    @FabioMontefuscolo Před 5 lety +1

    Congratulations, awesome explanation!

  • @ketan_sahu
    @ketan_sahu Před 4 lety +4

    It would really be helpful if you also make videos on some mathematical topics like Number Theory, Combinatorics, Modular Arithmetics, and whichever are important for competitive programming. There are very limited videos on the internet available on these topics and most of them are not well explained. Thanking you in advance 💙

    • @BackToBackSWE
      @BackToBackSWE  Před 4 lety +3

      I would but our focus is on interviews and helping people around that vs competitive programming. I would but we have to pursue our core mission.

  • @abhisheksharma1031
    @abhisheksharma1031 Před 3 lety

    This was awesome man! Finally I understood the algo!

  • @sergten
    @sergten Před 3 lety +7

    It would be nice to elaborate at 11:55 why "i" becomes the value of P[i-1] and not rolls all the way to zero.

    • @arnabpoddar6236
      @arnabpoddar6236 Před 3 lety +1

      It is a little tricky but I will try, we want to minimize the number of times we roll back to 0. So if there is a miss match,we check if we there is a suffix which is also a prefix in the string we have checked till now, if it is there then we make value of i point at the end of the suffix, which is stored in P[i-1] And if it is not there we directly make i=0. Hope that helps :)

  • @josephwang2234
    @josephwang2234 Před 3 lety

    OMG, this video is soooo great!!! love it

  • @AlienT7
    @AlienT7 Před 4 lety +1

    Good video!! Look a few other before this one. This is the first one make me understand.

  • @sunilsarode4295
    @sunilsarode4295 Před 4 lety +39

    watched at speed 0.75....:)

  • @vipulkrishna19
    @vipulkrishna19 Před 4 lety +3

    best Explanation so far on Internet

  • @StudyWithRishiP
    @StudyWithRishiP Před 3 lety

    Only thing I am not able to understand is when making prefix-suffix array, if i and j mismatches why do we make i=arr[i-1]; what diff does it make?

  • @chih-yulin4309
    @chih-yulin4309 Před 4 lety +1

    It is very helpful than the other long KMP articles.

  • @arnabmukherjee5840
    @arnabmukherjee5840 Před 4 lety +1

    Bro one of the best explanations. I will check all your content. Keep it up

  • @WhisperII
    @WhisperII Před 2 lety

    Yay I think I understand it at last, thanks man!

  • @sandyhan4829
    @sandyhan4829 Před 3 lety +1

    Watched several KMP videos and it is the first one that made me understand

  • @anubhavsinghal9218
    @anubhavsinghal9218 Před 4 lety +3

    Thanks for the video, it really helped me a lot.

  • @saumyachauhan2381
    @saumyachauhan2381 Před 3 lety +1

    Was really having trouble understanding this algo..This helped a lot :-)

  • @madhukeshkumar9783
    @madhukeshkumar9783 Před 4 lety +1

    you are really fantastic bro, I watched your videos on dynamic programming, they were just awesome and this is also like "Bawaal".

  • @minakshikudalkar557
    @minakshikudalkar557 Před 4 lety +1

    Love your channel!!

  • @arvindg927
    @arvindg927 Před 4 lety +1

    i feel yours channel vedios have one solid content for every topic i search
    every doubt is getting cleared one single veido ..wow thank u soo much bro

  • @eunjeongchoi5074
    @eunjeongchoi5074 Před 3 lety

    Finally got it!!! Thank you so much!!

  • @ShabnamKhan-cj4zc
    @ShabnamKhan-cj4zc Před 4 lety +1

    Thank you so much such a crystal clear explanation with example..

  • @nikunjsondawale9403
    @nikunjsondawale9403 Před 2 lety

    it was a great help. Thanks man

  • @user-en3em9yn4n
    @user-en3em9yn4n Před 4 lety +1

    what a marvelous explanation thanks! :)

  • @pranjalshrivstava6519
    @pranjalshrivstava6519 Před 3 lety

    This is the "BEST" explanation of KMP that ever existed!

  • @guowanqi9004
    @guowanqi9004 Před 5 lety +21

    Hey buddy, I still don't get it :(

    • @BackToBackSWE
      @BackToBackSWE  Před 5 lety +4

      This video is ok, one of my first ones, I will redo it one day. Can be made much clearer.

    • @575saisri4
      @575saisri4 Před 4 lety +1

      watch it again bcz i did and it worked.

  • @StudyWithRishiP
    @StudyWithRishiP Před 3 lety +4

    Non-indians felt you were yelling, I felt exactly like my classroom :) (Sad-Music in background)

  • @VishalKumar-kr9me
    @VishalKumar-kr9me Před 4 lety +2

    Ohhh I didn't know that you were teaching so fast as compared to your latest videos. I think that was excitement😁😁. But you were fantastic same as you are now

  • @DarshanModh
    @DarshanModh Před 3 lety

    Can I use KMP pattern matching algorithm in leetcode question implement strstr() ? I tried to write KMP algo and leetcode is giving me acceptance with 6ms, but if I use brute-force approach you explained (match first character of pattern and text, if match move forward till end of pattern), leetcode is giving me 0ms. Theoretically, KMP should be faster than the later approach. right?

  • @take3r462
    @take3r462 Před 4 lety +1

    Great Explanation, thanks!

  • @shabeebrp3225
    @shabeebrp3225 Před 4 lety +1

    amazing explanation, keep the good work going

  • @kodplanet
    @kodplanet Před 2 měsíci

    What if we never face a suffix == prefix , what is the time complexity in this case? Is KMP still preferable to Rolling-Hash ?

  • @VipinKumar-us1sr
    @VipinKumar-us1sr Před 2 lety

    You are becoming my first choice for learning any new algorithm. Keep uploading👍 Hats off👏

    • @BackToBackSWE
      @BackToBackSWE  Před 2 lety +1

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

  • @ashwinikumar3721
    @ashwinikumar3721 Před 4 lety +1

    Finally .... best video to undersand kmp algo clearly

  • @theodoraroseti6429
    @theodoraroseti6429 Před 2 měsíci

    Finally, I understand this one! Thank you, you're a hero.

  • @shivamkumarsingh667
    @shivamkumarsingh667 Před 2 lety

    Great Video,KMP is now crystal clear to me .Thanks !!!
    Love from India♥

  • @harshithanagarajan6410
    @harshithanagarajan6410 Před 4 lety +1

    I cannot thank you enough for this

  • @helenjiayuyi2847
    @helenjiayuyi2847 Před 3 lety +1

    Great explanation, thank you!

  • @ShubhamKumar-rt8nb
    @ShubhamKumar-rt8nb Před 4 lety +1

    you always make me understand even the hardest algorithm

  • @Official-tk3nc
    @Official-tk3nc Před 4 lety +1

    This is the underrated youtube channel on programming

  • @inanisv2580
    @inanisv2580 Před 5 lety +1

    GREAT!Really helpful :)

  • @RodionKryuchkov
    @RodionKryuchkov Před 3 lety

    Thanks man, very good explanation!

  • @sultanahmed9694
    @sultanahmed9694 Před 3 lety

    You are very confident and good explanation, thanks!

  • @jeffreyslominsky1275
    @jeffreyslominsky1275 Před 3 lety

    I've seen 1-indexed pi tables and 0 indexed pi tables, does it matter which one you use? Also, if the pattern (substring) you are trying to find doesn't have any repeating characters this algo would be as bad as the brute force approach right?

  • @excerptionexcerption3924

    Perfect explanation. Thank you so much!

    • @BackToBackSWE
      @BackToBackSWE  Před 2 lety

      Thank you, glad you liked it 😀
      Do check out backtobackswe.com/platform/content
      and please recommend us to your family and friends 😀

  • @georgeyarr3475
    @georgeyarr3475 Před rokem

    Hi, what is the point in making an entry in the border table for the last character in the substring? As there cant be a mismatch that requires its use? Once you get to that point in the substring you'll either find a match and the algorithm terminates, or you find a mismatch and look at the border of the table[0...7]

  • @ishaangupta6572
    @ishaangupta6572 Před 4 lety +1

    Really nice explanation !!! :D

  • @lnmma7917
    @lnmma7917 Před 4 lety +1

    best explanation so far. thanks a lot

  • @joshuanorris3776
    @joshuanorris3776 Před 2 měsíci

    Thank you so much for this! Great video!

  • @parikshitr.rajpara5187
    @parikshitr.rajpara5187 Před 3 lety +1

    best explanation! Loved it!

  • @teemu828
    @teemu828 Před 4 lety +21

    No it was the perfect pace! Good way to keep people engaged in the explanation :)

  • @ameyjain3462
    @ameyjain3462 Před 3 lety

    When creating the table if on a match we are incrementing i then what if you again find a `d` in string `dsgwadsdsg` - the table should be 0 000012123 right so how will third 'd' gets its length as 1 if we have incremented 'i' already.