1. The longest common substring of two words w 1 ..w n and v 1 ...v m is the longest word that appears from left to right (in not necessarily consecutive positions) in the two strings. For ex- ample, ALGEBRA and GEOMETRY have longest common substring GER. Here’s a recursive algorithm that finds the length of the longest common substring: LCS(w 1 ...w n , v 1 ..v m ). (a) IF n = 0 return 0 (b) IF m = 0 return 0 (c) IF w 1 = v 1 return 1 + LCS(w 2 ..w n , v 2 ..v m ) (d) Return max(LCS(w 2 ..w n , v 1 ..v m ), LCS(w 1 ..w n , v 2 ..v m ) Write a recurrence for R(n, m), the number of base case calls (with one or the other string being empty) of the recursive algorithm when w 1 ..w n and v 1 ..v m have no common elements. Then show that the solution to the recurrence is (m+n) . (10 points) Solution import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; /** Class LongestCommonSubstring **/ public class LongestCommonSubstring { /** function lcs **/ public String lcs(String str1, String str2) { int l1 = str1.length(); int l2 = str2.length(); int[][] arr = new int[l1 + 1][l2 + 1]; int len = 0, pos = -1; for (int x = 1; x < l1 + 1; x++) { for (int y = 1; y < l2 + 1; y++) { if (str1.charAt(x - 1) == str2.charAt(y - 1)) { arr[x][y] = arr[x - 1][y - 1] + 1; if (arr[x][y] > len) { len = arr[x][y]; pos = x; } } else arr[x][y] = 0; } } return str1.substring(pos - len, pos); } /** Main Function **/ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println(\"Longest Common Substring Algorithm Test\ \"); System.out.println(\"\ Enter string 1\"); String str1 = br.readLine(); System.out.println(\"\ Enter string 2\"); String str2 = br.readLine(); LongestCommonSubstring obj = new LongestCommonSubstring(); String result = obj.lcs(str1, str2); System.out.println(\"\ Longest Common Substring : \"+ result); } } .