Consider the following two sequences :

X = < B, C, D, C, A, B, C >

and Y = < C, A, D, B, C, B >

The length of longest common subsequence of X and Y is :

This question was previously asked in
UGC NET Computer Science (Paper 3) Nov 2017 Official Paper
View all UGC NET Papers >
  1. 5
  2. 3
  3. 4
  4. 2

Answer (Detailed Solution Below)

Option 3 : 4
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
10.8 K Users
50 Questions 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

Concept:

If there is match, A[i, j] = A[i – 1, j  – 1] + 1

If not match: max(A[i – 1, j], A[i, j – 1])

CALCULATION

Let M =  length of X and N = length of Y

int dp[N+1][M+1]

Table of longest common subsequence:

 

X →

B

C

D

C

A

B

C

Y

0

0

0

0

0

0

0

0

C

0

0

1

1

1

1

1

1

A

0

0

1

1

1

2

2

2

D

0

0

1

2

2

2

2

2

B

0

1

1

2

2

2

3

3

C 0 1 2 2 3 3 3 3

B

0

1

2

2

3

3

4

4

 

The length of longest common subsequence of X and Y = A[N][M] = 4

Latest UGC NET Updates

Last updated on Jun 12, 2025

-> The UGC NET June 2025 exam will be conducted from 25th to 29th June 2025.

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

More Dynamic Programming Questions

More Algorithm Design Techniques Questions

Get Free Access Now
Hot Links: teen patti yes all teen patti game yono teen patti teen patti master 2024 teen patti game