Karp-Rabin String Matching Algorithm | Substring Search Pattern

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

КОМЕНТАРІ • 60

  • @KunalKushwaha
    @KunalKushwaha  5 місяців тому +2

    DSA + interview preparation playlist: ua-cam.com/play/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ.html

  • @poorpanda9033
    @poorpanda9033 Рік тому +49

    If anyone is new to this bootcamp! Let me tell you it's amazing I've completed almost every single videos so far. By the end of the playlist you'll have so much confidence to tackle DSA questions by your own.
    Just make sure you're following the notes + assignments & Tips that kunal gives !!
    Some tips that I always remember when i approach a problem (kunal has mentioned it)
    - Don't memorize, understand the problem / logic
    - Hard Question is easy for those who have studied, Easy Question is hard for those who haven't
    - The function will return from where it was called !! ( Recursion )

    • @_Dream_Dive_
      @_Dream_Dive_ 7 місяців тому +3

      That last thing is the most important

  • @raunakmadan3128
    @raunakmadan3128 5 днів тому

    Why is this bootcamp is unique?
    It teaches you the thought process of how kunal solves these questions and how you can also get the intuition and approach these problems. Its not just a course where the teacher is just solving and solving questions, rather it helps you build the thought process.

  • @nagelithirumalanaidu3505
    @nagelithirumalanaidu3505 Місяць тому +2

    where is graph series kunal sir

  • @G0host-07
    @G0host-07 10 днів тому

    Wow, Kunal! Your DSA playlist is absolutely phenomenal. The way you've explained each topic with such clarity and depth is truly commendable. This playlist is hands down one of the best resources for learning DSA on UA-cam. I've been following it for the past two months, and it has been incredibly helpful! However, I noticed that dynamic programming and graphs are yet to be covered. Could you please consider adding these topics? Completing them would make this course the ultimate DSA resource on UA-cam. Thank you so much for your hard work and dedication🙌🤝!

  • @komalchauhan7535
    @komalchauhan7535 16 днів тому +1

    Amazing 👏

  • @adolfocarrillo248
    @adolfocarrillo248 Рік тому +4

    Kunal that updateHash method is kind of clever ha!! nice technique!!! Thanks for sharing your knowledge!!!!

  • @DeepakBarajati
    @DeepakBarajati 28 днів тому +1

    please complete Dsa series with graph and DP

  • @believe_it2380
    @believe_it2380 Рік тому +3

    These videos are so great, i am also done with each and every video, and just looking forward for notification of new Videos, .... It would be very grateful of Mr. Kunal if he could be more frequent in uploading videos, ❤❤ i don't have much patience for your videos

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

    Best course i suggested many friends ❤❤❤❤

  • @tusharkumar2290
    @tusharkumar2290 Рік тому +11

    String has a function called contains( " "). It has Log n complexity :) , Rabin karp can be said as more algorithmic approach whereas contains can be classified as general apporach

    • @New_Movie_Watch
      @New_Movie_Watch 4 місяці тому +1

      Ya your right ✅ I'm also thinking we can use contain function to why so use this

    • @01_cseaiml_aaravraj96
      @01_cseaiml_aaravraj96 4 місяці тому

      Yes but it will give Boolean answer but we need the index

  • @shadowmonarch1432
    @shadowmonarch1432 Рік тому +3

    At 2:20 the example ur explaining is sliding window technique with a TC of O(26*N)(for this problem) = O(N)
    By the way Big Fan bruh❤️

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

      Ninnu ekkado chusa bhayya

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

      Yes he said its O(n*n) which is wrong

  • @ravitejachandana6199
    @ravitejachandana6199 Місяць тому

    Thanks for the very each and intuitive explanation

  • @simalinaaz5640
    @simalinaaz5640 Рік тому +3

    Second video on same day❤

  • @lakshitjain6923
    @lakshitjain6923 Рік тому +4

    Sigma uploaded 2 videos at 3 am

  • @jk-sm6qr
    @jk-sm6qr 10 місяців тому

    Thanks Kunal!!

  • @nikhilnirwal2110
    @nikhilnirwal2110 Місяць тому

    bruh you're helping me top the subject in my college i didn't take a single class of💀 tho you are great tbh, may god bless you and yk what? my senior said she will go on a date with me if i top in my class☠☠ so i had the motivation and your resources, thanks for that tho. Stay Healthy lol ASAP

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

    Love from Jashore University of science and technology ,Bangladesh Sir❤. I am from non cs, following you to be a selftaught programmer.

  • @elco7956
    @elco7956 Рік тому +4

    I don't really understand the updateHash function

    • @anchalsharma0843
      @anchalsharma0843 3 місяці тому +11

      Hey, I know it's too old comment, but for anyone still confused about this , here you go
      Let's say you have a string window "ABC" ,
      so hash(ABC) = (ascii value of A) * PRIME ^ 0 + (ascii value of B) * PRIME ^ 1 +(ascii value of C) * PRIME ^ 2
      Now if we want to get rid of "A" and add "D" to our window, i.e slide our window to "BCD" , we need to update the hash as well,
      We can do that by removing contribution of "A" from our current hash and add contribution of "D" to our hash. How do we do that?
      hash(BCD) = [ hash("ABC") - Contribution of "A" ] + Contribution of "D"
      Contribution of "D" = (ascii value of D) * PRIME^2
      So, hash(BCD) becomes, [ hash("ABC") - Contribution of "A" ] + (ascii value of D) * PRIME^2
      And now, coming to the contribution of "A" -> Notice that A's value was simply (ascii value of A) since PRIME^0 is always 1
      So we can remove the ascii value of A
      i.e hash(BCD) becomes, [ hash("ABC") - (ascii value of A) ] + (ascii value of D) * PRIME^2
      Pay attention to term [ hash("ABC") - (ascii value of A) ] in above equation, its value is now
      [ hash("ABC") - (ascii value of A) ] = (ascii value of B) * PRIME ^ 1 +(ascii value of C) * PRIME ^ 2
      Notice the powers/exponents of PRIME. they start from 1, but we need them to start from 0 since this window is a new one, and every new window should have its hash
      calculated in same manner as we did while calculating hash(ABC), SO we need to adjust these powers. How to do that ? Well simple maths: Divide by the PRIME once
      .This would bring every PRIME's power in each term down by 1
      So
      [ hash("ABC") - (ascii value of A) ] / PRIME = (ascii value of B) * PRIME ^ 0 +(ascii value of C) * PRIME ^ 1
      SO our complete formula becomes;
      hash(BCD) = [ hash("ABC") - (ascii value of A) ] / PRIME + (ascii value of D) * PRIME^2

    • @anchalsharma0843
      @anchalsharma0843 3 місяці тому +1

      Which is what Kunal has done in his code.
      Hope that helps

  • @theseriousguy2136
    @theseriousguy2136 11 місяців тому +3

    I guess the CalculateHash function will get to the limit of mathematical computations. suppose str.length() is around 1000
    It would need to calcu;ate 101^1000 and that is out of bounds of long storage, and I guess pow() too couldn't cacluate it.

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

    Inspirational ❤❤❤

  • @floatingpoint7629
    @floatingpoint7629 8 днів тому

    no explanation on how to choose prime, why using Math.pow and why dividing old hash

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

    Would this work using something non-prime?

  • @ShivamKendre-fc3su
    @ShivamKendre-fc3su 6 місяців тому

    Great video

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

    Thanks, sir!!

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

    GOAT for a Reason....👍

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

    Wah ek sath

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

    what if we need to count that how many times b string contains a

    • @sufiserious798
      @sufiserious798 7 місяців тому +1

      Just use a counter variable, and in the condition where all characters match, increase counter by 1.
      At the end when the loop ends either return or print the value of counter.

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

    Cant we just use b.contains(a)?

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

      That also uses an algorithm similar to this one .

  • @ALIHAMZAAKRAM-oe2su
    @ALIHAMZAAKRAM-oe2su Рік тому +2

    I like to say Rabin-karp is it okay

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

    Can anyone pls explain why we divide by prime in order to get new hash

    • @aveshsingh491
      @aveshsingh491 11 місяців тому +1

      since we were multiplying with prime in order to calculate the hash with that character and now since we want to remove that character from our window therefore we need to not just subtract that character but as well divide the new hash with the prime.

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

      @@aveshsingh491
      tq so much

  • @NavneetKumar-lg3nv
    @NavneetKumar-lg3nv 7 місяців тому

    not able to understand line no 13

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

    🙏👍

  • @ArpitKhandelwal-w7r
    @ArpitKhandelwal-w7r 10 місяців тому

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

    Bro actually it takes n-pattern length times iterated and in each iteration it takes two iterations of length of pattern for generating hashcodes and also checking for same characters or not, if hash is matched
    Finally it also take O(nxm ) time ❤
    Tell me if im wrong☺️
    But krunal playlist is awesome🧡🧡🧡

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

    👉 Resources
    - Join Replit: join.replit.com/kunal-kushwaha
    - Lecture code: replit.com/@KunalsReplit/KarpRabin-Hashmaps

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

    Hey kunal can you give a refferal to me

    • @KunalKushwaha
      @KunalKushwaha  Рік тому +5

      no

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

      @@KunalKushwaha ok but please make a video for how to apply for Google

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

      ​@@KunalKushwaha40lpa fraud will refer? LOL
      made fools out of lakhs of people and that devops course has gone extinct
      just uploads promotion videos of tools these days.. free free ke chakkar me big scam of trust... fraudster kunal

    • @KaizokuOuNaruto
      @KaizokuOuNaruto Рік тому +7

      ​@@KunalKushwahaYou wont reply to or atleast complete your bootcamp
      but youll show arrogance for someone asking you a referral politely.. karma hits back fraudster... played games with trust,viral controversies,hype.. and the end result is zero..

    • @gojosatoru988
      @gojosatoru988 Рік тому +13

      ​@@KaizokuOuNarutowhat karma bro, if you don't like him don't watch his videos.
      Previously these types of detailed courses were paid, a kind man started it for free while managing his own work, and you're calling him fraud!!!!!
      Cheap mentality 😞