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 6963971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:51:51+00:00 2026-05-27T15:51:51+00:00

So, I started with this: http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Ruby Which works great for really small strings. But,

  • 0

So, I started with this: http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Ruby

Which works great for really small strings. But, my strings can be upwards of 10,000 characters long — and since the Levenshtein Distance is recursive, this causes a stack too deep error in my Ruby on Rails app.

So, is there another, maybe less stack intensive method of finding the similarity between two large strings?

Alternatively, I’d need a way to make the stack have much larger size. (I don’t think this is the right way to solve the problem, though)

  • 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-05-27T15:51:51+00:00Added an answer on May 27, 2026 at 3:51 pm

    Consider a non-recursive version to avoid the excessive call stack overhead. Seth Schroeder has an iterative implementation in Ruby which uses multi-dimensional arrays instead; it appears to be related to the dynamic programming approach for Levenshtein distance (as outlined in the pseudocode for the Wikipedia article). Seth’s ruby code is reproduced below:

    def levenshtein(s1, s2)
      d = {}
      (0..s1.size).each do |row|
        d[[row, 0]] = row
      end
      (0..s2.size).each do |col|
        d[[0, col]] = col
        end
      (1..s1.size).each do |i|
        (1..s2.size).each do |j|
          cost = 0
          if (s1[i-1] != s2[j-1])
            cost = 1
          end
          d[[i, j]] = [d[[i - 1, j]] + 1,
                       d[[i, j - 1]] + 1,
                       d[[i - 1, j - 1]] + cost
                      ].min
        end
      end
      return d[[s1.size, s2.size]]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I installed wxWidgets-2.8.10 following instructions from this page: http://wiki.wxwidgets.org/Compiling_and_getting_started Libraries directory: alex@alex-linux:/usr/local/lib$ ls |
Started looking at the win32 API on this site: http://www.winprog.org/tutorial/start.html I've literally just compiled
EDIT: looking for this: http://diminishing.org/extending-formtastic-with-a-sprinkle-of-jquery (If this works I'll answer my own question) I've
I'm following this example: http://www.codinghorror.com/blog/2005/12/getting-started-with-indexing-service.html However, the conversion to dataset shows empty columns for
So I started reading this book: http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022 On chapter 2 it explains about the
I started this website last year, along with a facebook page. http://www.facebook.com/textbookcentral I just
Since I started this new webshop for a friend to launch, which still in
I have a hard time reading open source file download pages like this http://rubyforge.org/frs/?group_id=167
I have started to use Autofac following this tutorials: http://flexamusements.blogspot.com/2010/09/dependency-injection-part-3-making-our.html Simple class with no
Based on this: http://man7.org/tlpi/code/online/book/procexec/multi_wait.c.html int main(int argc, char *argv[]) { int numDead; /* Number

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.