Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider two strings A = "qpqrr" and ... Start Learning for Free
Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.
  • a)
    33
  • b)
    23
  • c)
    43
  • d)
    34
Correct answer is option 'D'. Can you explain this answer?
Verified Answer
Consider two strings A = "qpqrr" and B = "pqprqrp". Le...
//The LCS is of length 4. There are 3 LCS of length 4 "qprr", "pqrr" and qpqr A subsequence is a sequence that can be derived from another sequence by selecting zero or more elements from it, without changing the order of the remaining elements. Subsequence need not be contiguous. Since the length of given strings A = “qpqrr” and B = “pqprqrp” are very small, we don’t need to build a 5x7 matrix and solve it using dynamic programming. Rather we can solve it manually just by brute force. We will first check whether there exist a subsequence  of length 5 since min_length(A,B) = 5. Since there is no subsequence , we will now check for length 4. “qprr”, “pqrr” and “qpqr” are common in both strings. X = 4 and Y = 3 X + 10Y = 34 
View all questions of this test
Most Upvoted Answer
Consider two strings A = "qpqrr" and B = "pqprqrp". Le...
The problem asks us to find the length of the longest common subsequence (not necessarily contiguous) between two given strings A and B, and the number of such longest common subsequences. Let's break down the problem step by step.

Finding the Longest Common Subsequence (LCS):
- The longest common subsequence problem can be solved using dynamic programming.
- We can define a 2D array dp with dimensions (m+1) x (n+1), where m is the length of string A and n is the length of string B.
- dp[i][j] represents the length of the LCS between the first i characters of string A and the first j characters of string B.
- We can fill in the dp array using the following recurrence relation:
- If A[i-1] == B[j-1], then dp[i][j] = dp[i-1][j-1] + 1.
- Otherwise, dp[i][j] = max(dp[i-1][j], dp[i][j-1]).
- The LCS length will be stored in dp[m][n].

Finding the Number of LCS:
- Once we have calculated the LCS length, we can find the number of LCS by modifying our dynamic programming approach.
- We define another 2D array count with the same dimensions as dp.
- count[i][j] represents the number of LCS between the first i characters of string A and the first j characters of string B.
- We can fill in the count array using the following recurrence relation:
- If A[i-1] == B[j-1], then count[i][j] = count[i-1][j-1].
- Otherwise, if dp[i-1][j] > dp[i][j-1], then count[i][j] = count[i-1][j].
- Otherwise, if dp[i-1][j] < dp[i][j-1],="" then="" count[i][j]="" />
- Otherwise, dp[i-1][j] == dp[i][j-1], so count[i][j] = count[i-1][j] + count[i][j-1].
- The number of LCS will be stored in count[m][n].

Calculating x and 10y:
- In this case, string A is "qpqrr" and string B is "pqprqrp".
- Using the dynamic programming approach described above, we can calculate dp and count.
- The LCS length is stored in dp[5][7], which is 4.
- The number of LCS is stored in count[5][7], which is 6.
- Therefore, x = 4 and y = 6.
- The value of x * 10y = 4 * 10^6 = 4,000,000.
- Thus, the correct answer is option D: 34.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Question Description
Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer?.
Solutions for Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A and B and let y be the number of such longest common subsequences between A and B. Then x + 10y = ___.a)33b)23c)43d)34Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev