Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Monte carlo Rabin_Karp Search

Monte carlo Rabin_Karp Search

Scheduled Pinned Locked Moved Algorithms
6 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Angelinna
    wrote on last edited by
    #1

    Where can I find sample codes showing implementation of Monte Carlo rabin_karp search. Thanks

    R 1 Reply Last reply
    0
    • A Angelinna

      Where can I find sample codes showing implementation of Monte Carlo rabin_karp search. Thanks

      R Offline
      R Offline
      Robert C Cartaino
      wrote on last edited by
      #2

      From this website[^]. Algorithm 9.2.8 Monte Carlo Rabin-Karp Search This algorithm searches for occurrences of a pattern p in a text t. It prints out a list of indexes such that with high probability t[i..i +m− 1] = p for every index i on the list.

      Input Parameters: p, t
      Output Parameters: None

      mc_rabin_karp_search(p, t)
      {
      m = p.length
      n = t.length
      q = randomly chosen prime number less than mn2
      r = 2m−1 mod q

        // computation of initial remainders
        f\[0\] = 0
        pfinger = 0
        for j = 0 to m-1 
        {
              f\[0\] = 2 \* f\[0\] + t\[j\] mod q
              pfinger = 2 \* pfinger + p\[j\] mod q
        }
      
        i = 0
        while (i + m ≤ n) 
        {
              if (f\[i\] == pfinger)
                    prinln(“Match at position” + i)
      
              f\[i + 1\] = 2 \* (f\[i\]- r \* t\[i\]) + t\[i + m\] mod q
              i = i + 1
        }
      

      }

      A 1 Reply Last reply
      0
      • R Robert C Cartaino

        From this website[^]. Algorithm 9.2.8 Monte Carlo Rabin-Karp Search This algorithm searches for occurrences of a pattern p in a text t. It prints out a list of indexes such that with high probability t[i..i +m− 1] = p for every index i on the list.

        Input Parameters: p, t
        Output Parameters: None

        mc_rabin_karp_search(p, t)
        {
        m = p.length
        n = t.length
        q = randomly chosen prime number less than mn2
        r = 2m−1 mod q

          // computation of initial remainders
          f\[0\] = 0
          pfinger = 0
          for j = 0 to m-1 
          {
                f\[0\] = 2 \* f\[0\] + t\[j\] mod q
                pfinger = 2 \* pfinger + p\[j\] mod q
          }
        
          i = 0
          while (i + m ≤ n) 
          {
                if (f\[i\] == pfinger)
                      prinln(“Match at position” + i)
        
                f\[i + 1\] = 2 \* (f\[i\]- r \* t\[i\]) + t\[i + m\] mod q
                i = i + 1
          }
        

        }

        A Offline
        A Offline
        Angelinna
        wrote on last edited by
        #3

        Thanks, but am after a working example not just a pseudocode.

        CPalliniC P 2 Replies Last reply
        0
        • A Angelinna

          Thanks, but am after a working example not just a pseudocode.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Angelinna wrote:

          but am after a working example not just a pseudocode

          plz gimme codez (urgent?) :sigh:

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • A Angelinna

            Thanks, but am after a working example not just a pseudocode.

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Angelinna wrote:

            am after a working example not just a pseudocode

            Why can't you take the pseudo code and implement it in what ever language you are programming in?

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

            T 1 Reply Last reply
            0
            • P Paul Conrad

              Angelinna wrote:

              am after a working example not just a pseudocode

              Why can't you take the pseudo code and implement it in what ever language you are programming in?

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

              T Offline
              T Offline
              Tim Craig
              wrote on last edited by
              #6

              Because "she" comes in here and expects guys to fall all over her doing her homework for her. :doh:

              If you don't have the data, you're just another asshole with an opinion.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups