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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:34:38+00:00 2026-05-30T15:34:38+00:00

I am trying to understand the algorithm from the famous ‘diff’ paper here ,

  • 0

I am trying to understand the algorithm from the famous ‘diff’ paper here, running on characters in the two command-line arguments. However, my code does not produce the results I expect. I’ve written the algorithm to match their variables to the extent possible:

$ ./diff abbcabba cbabac #Hmm.. I think it should be 5
SES: 10  
$ ./diff abcdefg abcdefg #0! Great!
SES: 0
$ ./diff abcXefg abcYefg # 2 seems reasonable
SES: 2
$ ./diff abcXefg abcefg # clearly wrong
SES: 7

Here is my code (Sorry about the wall of code):

    a = argv[1];
    b = argv[2];
    alen = strlen(a);
    blen = strlen(b);
    tlen = alen + blen;
    maxd = tlen;

    vp = (int *)calloc(2 * maxd + 1, sizeof(int));

    // How I'm thinking about pointer arithmetic:
    // vp in [0, 2*maxd + 1) == [0, 2*maxd]
    // v  in [-maxd, maxd + 1) == [-maxd, maxd]
    v = vp + maxd;
    v[1] = 0;
    for (D = 0; D <= maxd; D++) {
            for (k = -D; k <= D; k += 2) {
                    if (k == -D || (k != D && v[k-1] < v[k+1])) {
                            x = v[k + 1];
                    } else {
                            x = v[k - 1] + 1;
                    }
                    y = x - k;
                    while (x < alen && y < blen && a[x] == b[x]) {
                            x++;
                            y++;
                    }
                    v[k] = x;
                    if (x >= alen && y >= blen) {
                            printf("SES: %d\n", D);
                            goto out;
                    }
            }
    }
    printf("Nothing found. SES > %d\n", maxd);

Any idea where the flaw is here? I’ve been finding it incredibly hard to search online for this problem…

  • 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-30T15:34:40+00:00Added an answer on May 30, 2026 at 3:34 pm

    It seems that the problem is in this line:

    while (x < alen && y < blen && a[x] == b[x]) {
    

    Here b[x] should be b[y], which gives:

    while (x < alen && y < blen && a[x] == b[y]) {
    

    With this change the results for your examples are 6, 0, 2 and 1. This seems to be accurate.

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

Sidebar

Related Questions

I'm trying to understand the unification algorithm described in SICP here In particular, in
I'm trying to understand the algorithm described here , but the explanation really isn't
I have been trying to understand this algorithm for past two hours, but can't
for the past four days I am trying to understand the dijkstra's algorithm. But
I am trying to implement my own Thinning Algorithm in Matlab to understand the
I'm trying to implement block sorting. This is from the Burrows Wheeler paper .
I am trying to understand the FFT algorithm and so far I think that
I am trying to understand Double-Array Trie implementation from http://linux.thai.net/~thep/datrie/datrie.html But I do not
I'm trying to understand the algorithm for a Depth-Limited-Search on wikipedia, and I'm trying
I'm trying to write quicksort and understand the algorithm. I understand the 3 basic

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.