Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:11:13+00:00 2026-06-16T05:11:13+00:00

Here is my implementation of the Rabin Karp algorithm. It seems like it works

  • 0

Here is my implementation of the Rabin Karp algorithm.
It seems like it works fine for basically everything.
For example:

rabinKarp “andrew” “drew” = true

rabinKarp “andrew “az” = false

So that is fine, however, for some odd reason when I do this”

rabinKarp “hello” “hi”

it returns true.
It only seems to happen on these 2 words, I haven’t ran into it doing this with any other combination.
Would appreciate any feed back as to why it’s happening.

import Data.Char

hash :: String -> Int
hash [] = -1
hash (x:xs) = (ord x + (hash xs))

rabinKarp :: String -> String -> Bool
rabinKarp [] _ = False
rabinKarp mainString patternString =
    let
     hashPattern = hash patternString
     hashMain = hash (take (length patternString) mainString)
    in if hashPattern == hashMain
    then True
    else rabinKarp (drop 1 mainString) patternString
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:11:16+00:00Added an answer on June 16, 2026 at 5:11 am
    Prelude> fromEnum 'h' + fromEnum 'i'
    209
    Prelude> fromEnum 'e' + fromEnum 'l'
    209
    

    You have a hash collision. The possibility of a hash collision is given for all hash functions, but such a simple one as the sum of the ordinal numbers has quite a lot of collisions.

    When you have matching hashes, you still need to compare the strings to check whether you really have a match or a collision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given: interface ViewableDTO {//methods here} class PersonDTO implements ViewableDTO {//implementation here} This works fine:
I'm looking for an efficient hash function for Rabin-Karp algorithm. Here is my actual
You can see the implementation here . I would like to be able use
Here is my implementation in summary 1) all DAOs implemented using HibernateDAO support/ @Transational
Here's the implementation of java.lang.reflect.Method.equals(Object obj) as of Java 7: /** * Compares this
I'm having some difficulties getting the TabActivity to work. Here's the implementation of the
Here is the code : @implementation Accumulateur // Constructor - (id) init { return
Here is the hashCode() implementation from Java HashTable Class. What if the number of
Here's a Clone() implementation for my class: MyClass^ Clone(){ return gcnew MyClass(this->member1, this->member2); }
Here is my perceptron implementation in ANSI C: #include <stdio.h> #include <stdlib.h> #include <math.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.