Question
Consider the following Python code for calculating the length of the LCS: def lcs_length(text1, text2): m = len(text1) n = len(text2) dp = [[0] * (n + 1) for _ in range(m + 1)] for i in range(1, m + 1): for j in range(1, n + 1): if text1[i - 1] == text2[j - 1]: dp[i][j] = 1 + dp[i - 1][j - 1] else: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) return dp[m][n] # Assume text1 = "AGGTAB" and text2 = "GXTXAYB" # And the dp table has been partially filled as follows (only relevant cells shown): # "" G X T X A Y B # "" 0 0 0 0 0 0 0 0 # A 0 0 0 0 0 1 1 1 # G 0 1 1 1 1 1 1 1 # G 0 1 1 1 1 1 1 1 # T 0 1 1 2 2 2 2 2 # A 0 1 1 2 2 3 3 3 # B 0 1 1 2 2 3 3 4 <-- This is dp[6][7] What will be the value of dp[4][4] (LCS of "AGGT" and "GXTX") when text1 = "AGGTAB" and text2 = "GXTXAYB" are processed by the lcs_length function?
More Data Structure Questions
- What is the primary purpose of a B+ Tree in a database management system?
- Which of the following correctly describes the primary difference between Cross-Site Request Forgery (CSRF) and Cross-Site Scripting (XSS)?
- A hash table of size 7 uses h(k) = k mod 7 with linear probing for collision resolution. Keys 10, 3, 17, and 5 are inserted in that order. At which index d...
- A hash table using separate chaining has 10 slots and stores 15 elements, uniformly distributed across the slots. What is the average number of comparisons...
- Which cloud service model allows developers to deploy their applications without managing the underlying infrastructure?
- For Dijkstra’s algorithm on a graph with non-negative weights, which data structure yields the best time complexity for dense graphs?
- The keys 45, 20, 60, 10, 30, 55, 70, 25 are inserted in this order into an initially empty Binary Search Tree. What is the postorder traversal of the resul...
- Which tree traversal gives nodes in non-decreasing order for a BST?
- Which of the following is a primary feature of Mobile Computing?
- Using the Master Theorem, what is the time complexity of the recurrence T(n) = 2T(n/2) + n·log n?
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
- 200 Questions with Detailed Solutions
- Section-wise Coverage (GA, English, Quant & Reasoning)