adplus-dvertising
frame-decoration

Question

What is the value stored in arr[3][3] when the below code is executed?
#include<stdio.h>
#include<string.h>
int get_min(int a, int b)
{
      if(a < b)
        return a;
      return b;
}
int edit_distance(char *s1, char *s2)
{
      int len1,len2,i,j,min;
      len1 = strlen(s1);
      len2 = strlen(s2);
      int arr[len1 + 1][len2 + 1];
      for(i = 0;i <= len1; i++)
        arr[i][0] = i;
      for(i = 0; i <= len2; i++)
         arr[0][i] = i;
      for(i = 1; i <= len1; i++)
      {
           for(j = 1; j <= len2; j++)
           {
                min = get_min(arr[i-1][j],arr[i][j-1]) + 1;
                if(s1[i - 1] == s2[j - 1])
                {
                     if(arr[i-1][j-1] < min)
                       min = arr[i-1][j-1];
                }
                else
                {
                    if(arr[i-1][j-1] + 1 < min)
                     min = arr[i-1][j-1] + 1;
                }
                arr[i][j] = min;
          }
     }
     return arr[len1][len2];
}
int main()
{
      char s1[] = "somestring", s2[] = "anotherthing";
      int ans = edit_distance(s1, s2);
      printf("%d",ans);
      return 0;
}

a.

1

b.

2

c.

3

d.

4

Answer: (c).3

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the value stored in arr[3][3] when the below code is executed?

Similar Questions

Discover Related MCQs

Q. Which of the following is NOT a Catalan number?

Q. Which of the following numbers is the 6th Catalan number?

Q. Which of the following is/are applications of Catalan numbers?

Q. Which of the following methods can be used to find the nth Catalan number?

Q. Which of the following implementations of Catalan numbers has the smallest time complexity?

Q. Which of the following implementations of Catalan numbers has the largest space complexity(Don’t consider the stack space)?

Q. Which of the following methods can be used to solve the assembly line scheduling problem?

Q. What is the time complexity of the brute force algorithm used to solve the assembly line scheduling problem?

Q. In the dynamic programming implementation of the assembly line scheduling problem, how many lookup tables are required?

Q. Given a string, you have to find the minimum number of characters to be inserted in the string so that the string becomes a palindrome. Which of the following methods can be used to solve the problem?

Q. In which of the following cases will the number of insertions to form a palindrome be minimum?

Q. In the worst case, the minimum number of insertions to be made to convert the string into a palindrome is equal to the length of the string.

Q. Consider the string “efge”. What is the minimum number of insertions required to make the string a palindrome?

Q. Consider the string “abbccbba”. What is the minimum number of insertions required to make the string a palindrome?

Q. Which of the following problems can be used to solve the minimum number of insertions to form a palindrome problem?

Q. Given a 2D matrix, find a submatrix that has the maximum sum. Which of the following methods can be used to solve this problem?

Q. In which of the following cases, the maximum sum rectangle is the 2D matrix itself?

Q. In which of the following cases, the maximum sum rectangle can be a 1 x 1 matrix containing the largest element?

Q. Consider a matrix in which all the elements are non-zero(at least one positive and at least one negative element). In this case, the sum of the elements of the maximum sum rectangle cannot be zero.

Q. Consider the 2×3 matrix {{1,2,3},{1,2,3}}. What is the sum of elements of the maximum sum rectangle?