ProgrammingHardTCS NQT · Accenture
The edit distance (Levenshtein, insert/delete/replace each cost 1) between "kitten" and "sitting" is computed by the standard table. What is printed?
The edit distance (Levenshtein, insert/delete/replace each cost 1) between "kitten" and "sitting" is computed by the standard table. What is printed?
dp[i][0] = i; dp[0][j] = j dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + (0 if same else 1)) Print dp[m][n]
- A. 3
- B. 5
- C. 2
- D. 4
Correct answer: A. 3
Turning kitten into sitting needs three operations: replace k with s, replace e with i, and insert g. Charging 2 for a replacement gives 5, the length difference is 2, and the longest common subsequence length is 4.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The string " hello world " is split by the Python-style rule that runs of spaces are treated as one separator and empty pieces are…
- The longest common subsequence (LCS) of "ABCBDAB" and "BDCABA" is computed by the standard table. The procedure below prints its length…
- The number of non-empty substrings of "abcd" (substrings are contiguous pieces, counted by position) is computed by the procedure below…
- The procedure below counts the uppercase letters in the sentence "Hello World From AI". What is printed? count = 0 for each character c if…
- Strings are compared by dictionary order. The procedure below counts how many of ["apple", "mango", "kiwi", "banana", "mangoes"] are…
- A message of digits is decoded by mapping 1 to A, 2 to B, ..., 26 to Z, where a digit string may be split into one- or two-digit groups…