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

  • Home
  • SEARCH
  • 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 8225587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:27:49+00:00 2026-06-07T15:27:49+00:00

I have a homework assignment in which I need to compute the edit distance

  • 0

I have a homework assignment in which I need to compute the edit distance between two strings. I got the initial function to work but I’ve been having trouble with this part

Now add the cutoff into the edit distance. This shouldn’t change what result are produced, but will drastically speed up the performance.

Here’s my original function:

static unsigned int compute_edit_distance(const char *const a,
                                      const char *const b)
{
    if (strcmp(a, b) == 0) return 0;
    if (a[0] == '\0') return strlen(b);
    if (b[0] == '\0') return strlen(a);

    unsigned int remove_from_a =
        compute_edit_distance(a + 1, b) + 1;
    unsigned int remove_from_b =
        compute_edit_distance(a, b + 1) + 1;

    unsigned int remove_from_both =
        compute_edit_distance(a + 1, b + 1);
    if (tolower(a[0]) != tolower(b[0])) ++remove_from_both;

    return get_min(get_min(remove_from_a, remove_from_b),
               remove_from_both);
}

I’ve tried a few things, but none of them work. My latest change is this

if (depth == MAX_EDIT_DISTANCE_DEPTH)
{
    size_t a_length = strlen(a);
    size_t b_length = strlen(b);
    size_t max_length = (a_length > b_length) ? a_length : b_length;
    return MAX_EDIT_DISTANCE_DEPTH + max_length;
}

with a new function signature

static unsigned int compute_edit_distance(const char *const a,
                                      const char *const b, unsigned int depth)

but that doesn’t work either.

Can I get a hint on how to do this right? Thanks!

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

    The easiest way is to pass in the “depth remaining” as a parameter. That is, the first call gets passed the cut-off depth, and all the recursive calls get passed a smaller number, which you determine by the type of edit made.

    The fundamental idea is that in your first solution, the depth is calculated after the branch is explored recursively. That is, the calls are all made down the branch, then the numbers added together on the way back up the branch.

    You can still do this to calculate the depth, but to prevent the branch from going too far, you pass in a running total of the editing budget you have already used in the calls on the way down the branch, or equivalently the editing budget that remains.

    You’ll need some trick to pass back a number from the failing branch to make sure the number will be rejected. For example return a number that you know will be too large, then check the result at the end. E.g., return MAX_DEPTH + 1, or similar.

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

Sidebar

Related Questions

I have a homework assignment where I need to take input from a file
Hi I have a homework assignment where I need to implement an intersection of
I have a homework assignment which asks to have the user input a date
Note: This is a homework assignment. I have two classes, one inherits from the
Have a homework assignment in which I'm supposed to create a vector of pointers
For a homework assignment I wrote some scala code in which I have the
A recent homework assignment I have received asks us to take expressions which could
I have a homework assignment to write a multi-threaded sudoku solver, which finds all
I have a homework assignment where I'm supposed to find the cheapest airfares between
This was a homework assignment problem which I know I have incorrectly answered. I

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.