📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    A DP solution for LCS is producing incorrect lengths.

    Upon inspection, the dp table is being filled, but the values don't match expected outcomes. Which of the following is a common error in the recurrence relation for LCS?
    A Not considering the case where characters text1[i-1] and text2[j-1] are equal. Correct Answer Incorrect Answer
    B Incorrectly taking max(dp[i-1][j], dp[i][j-1]) when characters are equal. Correct Answer Incorrect Answer
    C Initializing dp[0][j] and dp[i][0] with values other than 0. Correct Answer Incorrect Answer
    D Using dp[i][j] = 1 + dp[i][j] when characters match. Correct Answer Incorrect Answer
    E Iterating i and j from 0 instead of 1 for string indices. Correct Answer Incorrect Answer

    Solution

    The correct answer is B

    Practice Next
    ask-question