Rabin Karp Substring Search Pattern Matching

Поділитися
Вставка
  • Опубліковано 14 січ 2025

КОМЕНТАРІ • 248

  • @chiragjindal6096
    @chiragjindal6096 4 роки тому +31

    Paying 4 LPA college fees just to end up watching your free video lectures.

  • @babajogiji
    @babajogiji 8 років тому +15

    I didn't realize the power of rolling hash calculation unless applied it to longer text and patterns! Your 3-step calc is very good idea.

  • @raghavkhurana7110
    @raghavkhurana7110 8 років тому +41

    You're good. Keep helping us out when our professors won't and god will bless you!

  • @AnythingGoesCodes
    @AnythingGoesCodes 8 років тому +11

    understood perfectly after first example. May Allah reward you greatly for the work that you have done.

  • @carloslaguna7036
    @carloslaguna7036 9 років тому +3

    This is the first time I understand rolling hash functions. Great video! Keep up with the great work!

  • @naveennoel9496
    @naveennoel9496 3 роки тому +1

    The rolling in and out part has been flawlessly explained. 👌 Thanks!

  • @amansinghrajput9445
    @amansinghrajput9445 Рік тому +1

    Sir you very much look like a famous UA-camr (THUGESH)

  • @ankurbmv
    @ankurbmv 8 років тому

    Even from a newbie perspective its easy-to-understand your videos, great initiative, thank you very much.

  • @sidhantakumarpattnaik2962
    @sidhantakumarpattnaik2962 8 років тому +1

    Very nice and so simple explanation .somebody who not belong to software industry will also understand easily . keep posting these videos this really helps us .

  • @reehji
    @reehji 8 років тому +59

    damn, this is 10x easier than trying to read the lemmas and proofs T_T

    • @kumartatsat868
      @kumartatsat868 4 роки тому +4

      videos like these are good for knowing "how" things work. but proofs and lemmas help you to answer "why" this thing works

    • @JTST1234
      @JTST1234 4 роки тому +1

      @@kumartatsat868 yea but you start ask knowing "how" things work then move on to "why" things work

  • @KanagaveluSugumar
    @KanagaveluSugumar 9 років тому +2

    Excellent Tushar! Now got the Rolling hash function :) And it is great that you are explaining about the real time application where it is used and its time complexities. It will also be great if you do explain about where it will fails as well as comparing with other equivalent algorithms which solve those failures at the end of the session.

  • @SonuSonu-tk5pk
    @SonuSonu-tk5pk 7 років тому +22

    ""Hello friends my name is..."
    its amazing

  • @IndianVideoGameCollector
    @IndianVideoGameCollector 7 років тому

    thank you for the crisp explanation, better and 10x note helpful than reading a boring book

  • @sarthaksrivastav3408
    @sarthaksrivastav3408 4 роки тому

    The rolling hash calculation thing was really awesome

  • @kisgatyas
    @kisgatyas 9 років тому +39

    Very good explanation of the topic. Thank you for your effort. :)

  • @henrydeutsch5130
    @henrydeutsch5130 6 місяців тому

    Phenomenal tutorial, very clear. Thanks!

  • @AnmolKumar-ci7qz
    @AnmolKumar-ci7qz 3 роки тому

    Best explanation ever seen..
    Hats off..

  • @letsghoomo
    @letsghoomo 8 років тому

    Really detailed explanation which is understandable for all levels of students..Thank you

  • @DentrifixoRam88
    @DentrifixoRam88 6 років тому

    as always your explanation is one of the best ones I find in youtube, congrats!

  • @zishanoo7
    @zishanoo7 9 років тому

    Videos are really helpful. Keep up the good work Tushar

  • @prashantkiran6869
    @prashantkiran6869 9 років тому

    Very nice explanation.Please keep up the good work!

  • @magadiflo-dev
    @magadiflo-dev 7 років тому

    Thanks for the explanation, made me understand the operation of this algorithm, greetings from Peru.

  • @pratikjain3323
    @pratikjain3323 3 роки тому

    Tushar, you nailed it man!

  • @dineshshah8345
    @dineshshah8345 6 років тому

    Awesome explanation. Easy to understood

  • @bgmibrutal4347
    @bgmibrutal4347 7 років тому

    awesome explanation .... you save my 8 marks ... thank you very much sir !!! 😊

  • @riverland0072
    @riverland0072 8 років тому +26

    I think this is wrong. You are not doing the required modular arithmetic to reduce the false positives. The method will work but this is not the complete algorithm. Someone should prove me wrong on this.

    • @aneeshcrao
      @aneeshcrao 6 років тому +2

      Yeah clearly, it is incomplete.

    • @aneeshcrao
      @aneeshcrao 6 років тому +4

      He has not used to the table size of the hash (the prime number here) anywhere. You will need to find the modulo of the final hash value, otherwise you will get strings which hash to values greater then the prime number, which clearly won't fit in the Hash Table

    • @adhishmalviya2408
      @adhishmalviya2408 4 роки тому

      Even 3 years after your comment, I am still with you.

    • @YashArora721
      @YashArora721 4 роки тому

      Same here..this does not work for large numbers..the has becomes 0 for large numbers . There should be some modulo operation wrt to prime numbers

    • @harshdeepsinghful
      @harshdeepsinghful 3 роки тому

      Yes this is incomplete....

  • @Bakepichai
    @Bakepichai 7 років тому

    Very good explanation Tushar

  • @hjkc6000
    @hjkc6000 4 роки тому

    Your video is always gold.

  • @marialetizialosso9319
    @marialetizialosso9319 7 років тому

    love your videos, they are very clear and useful!

  • @AyudhKumarGupta
    @AyudhKumarGupta 4 роки тому

    Thanks a lot for the simple explanation!

  • @omkarkulkarni9202
    @omkarkulkarni9202 5 років тому

    @Tushar please send us or post your patron link.. i cant keep learning without returning the immense value these lectures are providing! :) Thanks a lot and god bless you

  • @yashwant_317
    @yashwant_317 2 роки тому

    best video on this algortihm

  • @Karansingh-gh4oy
    @Karansingh-gh4oy 7 років тому

    Greatly explained sir👏🏻👍🏻

  • @mrfrozen97-despicable
    @mrfrozen97-despicable 4 роки тому +1

    Why don't u use number of ascii values instead of a prime no.

  • @gold_455
    @gold_455 8 років тому

    This is clean and awesome explaination

  • @rollandgavrilita9940
    @rollandgavrilita9940 8 років тому

    GJ man you are my hero! you saved my exam! Thanks

  • @poojagarg5505
    @poojagarg5505 8 років тому

    Thankew so much your all videos help me alottttt.. You teach very well.. Thanx again sir

  • @vanihemmige
    @vanihemmige 5 років тому

    Very well explained. Thank you very much.

  • @garretmurphy9663
    @garretmurphy9663 7 років тому

    Nice video and explanation! Thank you!

  • @reverseaxe
    @reverseaxe 8 років тому

    This was extremely helpful, thanks!

  • @sagarshah275
    @sagarshah275 9 років тому

    Very nice explanation. Thanks!

  • @lerneninverschiedenenforme7513
    @lerneninverschiedenenforme7513 7 років тому

    Thank you understandable english! Thank you formsharing that knowledge! Helped me a lot!

  • @garretmurphy3493
    @garretmurphy3493 7 років тому

    Thank you for this video, you explained it very well

  • @kreator1545
    @kreator1545 8 років тому

    Thank you so much your videos are great and very helpful .

  • @NaveenTulsi13
    @NaveenTulsi13 6 років тому

    Great explanation - Thank you.

  • @cojocariuvlad28
    @cojocariuvlad28 8 років тому

    Thank you! You do a great job. When will you post the next algorithms?

  • @sushmitagoswami7320
    @sushmitagoswami7320 3 роки тому

    Excellent explanation.

  • @JeroenPol
    @JeroenPol 8 років тому

    Thanks! Very clear explenation!

  • @keziakurien
    @keziakurien 8 років тому

    Really good Explaination!! Good Job :) thanks a ton!!

  • @kalaiandev5356
    @kalaiandev5356 8 років тому +10

    I don't understand why are we using prime numbers here....Why can't we simply add their ASCII values

    • @ramansonipat
      @ramansonipat 8 років тому +30

      Consider values of A=1, B=2, C=3
      If we don't use prime numbers the hash value for ABC and BCA are
      ABC = 1+2+3=6
      BCA = 2+3+1=6
      Hash values are colliding causing the search to be inefficient.Instead if you used prime numbersABC = 1 * 3^0 + 2 * 3^1 + 3 * 3^2 = 1+6+27 = 34 BCA = 2 * 3^0 + 3 * 3^1 + 1 * 3^2 = 2+9+9 = 20Hash values are different and can be differentiated even if they contain same number of characters.

    • @malharjajoo7393
      @malharjajoo7393 8 років тому +1

      Does this mean that there can never be hash collisions ?? Also, how can you prove that ?

    • @Deepakyadav-jr3gk
      @Deepakyadav-jr3gk 7 років тому +3

      No, it does not guarantee that hash will never collide.
      If hash collides then we will check element by element and if it matches then only pattern is find otherwise not.
      This is the worst case if our hash function is not good and hase values colliding each other and indeed checking for each character and pattern is not found.
      o((n-m+1)*m ).

    • @satadhi
      @satadhi 7 років тому +1

      then how do you decide which hash function is better suited ?

    • @geni3595
      @geni3595 5 років тому

      @@satadhi
      Generally multiplying with a large number ensures hashes won't collide but for understanding purpose it's advisable to take a small value number

  • @mrinalverma3010
    @mrinalverma3010 5 років тому

    best explanation sir, thank you so much

  • @ankurmazumder5590
    @ankurmazumder5590 7 років тому +1

    can you plz make a video on aho corasick algorithm? i think its much more important than other multiple string searing algorithm as it takes linear time

  • @samchan1043
    @samchan1043 8 років тому +1

    Very good video,thanks bro

  • @SearchingPeaceInside
    @SearchingPeaceInside 4 роки тому +1

    Hey tushar, as per your algo we need to store mappings a=1,b=2,c=3 and so on. if input text contains 256 ASCII characters, maintaining mapping would be tough, I believe instead taking actual ASCII values of characters in pattern would be helpful. Again you have not told on what basis you have taken prime number(3), this is similar to converting string to base-3 number system. And in case of huge pattern string also if you take prime number as 101(as you told) it will make a huge number might overflow unsigned int boundaries as well. I believe using mod might be good. Also you did not told why 101 would be good, ie synonymous to converting number to base-101 number system. i belive taking smaller prime will lead to larger hash collisions and then lot of comparisons..

  • @NagabhushanBaddi
    @NagabhushanBaddi 9 років тому

    Please make more videos on String algorithms....thanks for the great videos....

  • @ashleycole3054
    @ashleycole3054 9 років тому

    Great Video.Keep on adding videos.

  • @ShellyJaglan
    @ShellyJaglan 8 років тому

    awesome !!! love your videos ...great work !!

  • @pauliewalnuts6734
    @pauliewalnuts6734 7 років тому

    bhai onek bhalo explanation :)

  • @RevonM
    @RevonM 7 років тому

    Thanks for the explanation!

  • @tomchu6100
    @tomchu6100 3 роки тому

    Good job! Thanks for your insights, I just have only one question, if the length of the pattern is getting really long, like more than 20 characters, then the hash value will become intolerable for most types.

  • @KanagaveluSugumar
    @KanagaveluSugumar 9 років тому

    Could you please create a playlist on Searching algorithams? It is difficult to find other searching algo tutorials by you ?

  • @LalitKumar-go1tz
    @LalitKumar-go1tz 7 років тому

    Nice Explanation bro ...

  • @halseywalker5015
    @halseywalker5015 5 місяців тому

    You are the real hero !!!

  • @eequalsmc2829
    @eequalsmc2829 5 років тому

    Could you also provide links for videos that you already made like KMP in description

  • @dipendrasingh3559
    @dipendrasingh3559 4 роки тому

    r u still uploading videos
    sir tushar

  • @bhatwahid5107
    @bhatwahid5107 8 років тому

    Thanks you sir . Nice explanation

  • @jishudohare9141
    @jishudohare9141 7 років тому

    Awesome video but one doubt
    what if we have to find multiple patterns and length of those multiple patterns vary?

  • @TheSagarSai
    @TheSagarSai 9 років тому

    Fantastic video..!! Thanks as always.. learning a lot. :-)

  • @anerdwitdacamera204
    @anerdwitdacamera204 4 роки тому +1

    what if the substring length is like 100, the hash will exceed the integer even long limit

  • @chenxiang4376
    @chenxiang4376 8 років тому

    thanks! look forward more videos!

  • @tusharaherkar1727
    @tusharaherkar1727 6 років тому

    Bro u r doing really grt job... I am preparing fr placements ur videos saved me frm going thru textbooks n all other stuff

  • @roshanpandey5357
    @roshanpandey5357 6 років тому

    Well Explained sir, you are great :P

  • @gsb22
    @gsb22 3 роки тому

    I'm surprised that no one really checked that this algo will break if use value 3. Start with 4 and it works, with 3 it breaks.

  • @neerajchoudhary3709
    @neerajchoudhary3709 2 роки тому

    this channel is quality

  • @abhishek-rathore
    @abhishek-rathore 9 років тому

    "we cannot do anything about it.":P great video buddy :)

  • @siddharthagarwal8662
    @siddharthagarwal8662 9 років тому

    gud 1 tushar.

  • @sheetalmishra2063
    @sheetalmishra2063 8 років тому

    This is great
    thank you😀

  • @aayush5474
    @aayush5474 4 роки тому

    The code will not work for large length of pattern. Overflow condition needs to be addressed

  • @simonvutov7575
    @simonvutov7575 11 місяців тому

    mate youre actually the goat

  • @bustawhero5099
    @bustawhero5099 8 років тому

    I'm a big fan. I love this video. If the pattern is longer than length of 3, what's the best way to adjust the hash calculation?

    • @bustawhero5099
      @bustawhero5099 8 років тому

      Never mind. I believe I will need to continue the addition but increase the exponent. For example if the length is four, I will then add "+ n x 3^3" to the end of the calculation. Thanks.

  • @PaAGadirajuSanjayVarma
    @PaAGadirajuSanjayVarma 4 роки тому

    What do we say to the God of algorithms teaching
    Thank you tushur roy

  • @saadullah1797
    @saadullah1797 7 років тому +1

    how to choose the prime number if the prime number is not given?

  • @高航-o3x
    @高航-o3x 9 років тому

    There is a question, if the text string and the pattern string are consisted of Chinese characters and the two strings are longer a little, the hashcode may overflow so wrong results appear.As we known,Chinese characters have a large number of characters。

    • @高航-o3x
      @高航-o3x 9 років тому

      ***** The String class in Java has a method String.indexOf(), it just use the BF rather than KMP.

  • @endersuu8359
    @endersuu8359 3 роки тому

    It is quite clear, but what if the string to be matched is really long? Hash value will be huge. Is there a way to optimize?

  • @miguelmartins8411
    @miguelmartins8411 8 років тому

    Ty, Keep up the good work!

  • @ankitkhani8246
    @ankitkhani8246 8 років тому

    Thanks Tushar, very good explanation of Rolling hash concept. However, I have a question. Your hash could quickly cross the long int boundary for ascii characters if the pattern is long. Am I right?
    Would you not want to use a modulus operation to keep your hash value in check?

    • @Dipubuet
      @Dipubuet 8 років тому

      "if it goes beyond int or long size it will modulus itself"
      I didn't get that. Would you please like to explain shortly ?

  • @vaibhavchhabra800
    @vaibhavchhabra800 9 років тому +2

    +Tushar Roy
    Can u make a tutorial on Aho Corasick String Matching Algorithm Plz

  • @himanshu1689
    @himanshu1689 7 років тому

    Hello tushar I appreciate your got work and effort.Please help me out if rabin carp can search for exact pattern or not. Suppose i am searching over a text file for the word "the" to calculate the frequency but it count the sub-string with the such as they them their. What logic can be added in the rabin karp so that it can go for exact match.

  • @theakashrai
    @theakashrai 8 років тому

    Good Explanation Thank you

  • @pranavmaiya4386
    @pranavmaiya4386 2 місяці тому

    goated explanation man

  • @kishanmittal431
    @kishanmittal431 4 роки тому

    what if the string to be searched is too big ?
    lets say if the string is of size 10^5 and the string to be matched(present or not) is of size 10^4 then how will u calculate the hash ? pow(3,10^4) is overflowing here , so this algo doesn''t work when the string is too big ?

  • @sauravjha5666
    @sauravjha5666 4 роки тому

    but if we have to calculate hash for a very long pattern then we won't be able to calculate power of 101, what should i do then?

  • @kamal-xd7id
    @kamal-xd7id 6 років тому

    For bigger string, Hashcodes are going very big. Should we not use prime number as modulo also?

  • @cantwaittowatch
    @cantwaittowatch 8 років тому

    Thanks Tushar. If I understand this right - Brute-force time complexity is the same as this approach. So this algo excels on looks ups based on hashbased, and when hash calculation maps to collisions then this algo is no good. So do you think brute-force is better given the time complexities are same?

  • @salmanraza6362
    @salmanraza6362 8 років тому

    I tried hard but couldn't find your video for Brute Force string matching . Could you please give me the link here.
    Have an exam on Sunday. Would really appreciate it.

  • @wenyuewang5842
    @wenyuewang5842 7 років тому

    very helpful ! Thanks

  • @dron466
    @dron466 8 років тому

    Hey Tushar please can you give me hint how I can make changes in your hash function to allow for one or zero mismatch.

  • @pythoniccypress6715
    @pythoniccypress6715 6 років тому

    Code seems not working with large input such as ["aabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaa","baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"].
    Both of them get the same initial hash, which is weird..

  • @hannanathar3627
    @hannanathar3627 Рік тому

    you are not testing at 0th index of string for pattern matching and why didn't you use modulus?

    • @pralaynath447
      @pralaynath447 10 місяців тому

      yes , i also commented this
      "isnt this approach will create overflow problem while calculating HASH ?? if pattern is more than 63 length.that to in best case . if we choose our prime 2. how can we compute 2^64 . looks like this approach has limitation , we should be using MOD also"

  • @tejasdonadkar9094
    @tejasdonadkar9094 3 роки тому +1

    Thank you so much