PYQ Vault
PYQs
Notes
Most Asked
Mocks
Board
Store
Visuals
Play
PYQs
Most Asked
Notes
Mocks
Board
2 questions
Filters
3
Download
· 2
Filtering by:
GATE CS
Algorithms
Dynamic Programming (2)
Clear all
Copy link
GATE CS · 2024 · Set 2 · IISc Bengaluru · Q35
Add
#1
·
Moderate
·
Longest increasing subsequence
Let
A
A
A
be an array containing integer values. The distance of
A
A
A
is defined as the minimum number of elements in
A
A
A
that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array [2, 5, 3, 1, 4, 2, 6] is ___________
Show answer
Report
GATE CS · 2026 · Set 2 · IIT Guwahati · Q39
Add
#2
·
Moderate
·
Table filling order
Consider a table
T
T
T
,
where the elements
T
[
i
]
[
j
]
T[i][j]
T
[
i
]
[
j
]
,
0
≤
i
,
j
≤
n
0 \leq i, j \leq n
0
≤
i
,
j
≤
n
,
represent the cost of the optimal solutions of different subproblems of a problem that is being solved using a dynamic programming algorithm. The recursive formulation to compute the table entries is as follows:
T
[
0
]
[
k
]
=
T
[
k
]
[
0
]
=
1
for
k
=
0
,
1
,
2
,
…
,
n
T[0][k] = T[k][0] = 1 \quad \text{for } k = 0, 1, 2, \ldots, n
T
[
0
]
[
k
]
=
T
[
k
]
[
0
]
=
1
for
k
=
0
,
1
,
2
,
…
,
n
T
[
i
]
[
j
]
=
2
T
[
i
−
1
]
[
j
]
+
3
T
[
i
]
[
j
−
1
]
for
1
≤
i
,
j
≤
n
T[i][j] = 2T[i-1][j] + 3T[i][j-1] \quad \text{for } 1 \leq i, j \leq n
T
[
i
]
[
j
]
=
2
T
[
i
−
1
]
[
j
]
+
3
T
[
i
]
[
j
−
1
]
for
1
≤
i
,
j
≤
n
Consider the following two algorithms to compute entries of
T
T
T
.
Assume that for both the algorithms, for all
0
≤
i
,
j
≤
n
0 \leq i, j \leq n
0
≤
i
,
j
≤
n
,
T
[
i
]
[
j
]
T[i][j]
T
[
i
]
[
j
]
has been initialized to 1. Algorithm B1: For i = 1, 2, ..., n For j = 1, 2, ..., n T[i][j] = 2T[i-1][j] + 3T[i][j-1] Algorithm B2: For s = 2, 3, ..., 2n For i = 1, 2, ..., n For j = 1, 2, ..., n If (i + j == s) T[i][j] = 2T[i-1][j] + 3T[i][j-1] Algorithm
B
k
B_k
B
k
,
k
∈
{
1
,
2
}
k \in \{1, 2\}
k
∈
{
1
,
2
}
is said to be correct if and only if it calculates the correct values of
T
[
i
]
[
j
]
T[i][j]
T
[
i
]
[
j
]
,
for all
0
≤
i
,
j
≤
n
0 \leq i, j \leq n
0
≤
i
,
j
≤
n
,
(as per the recursive formulation) at the end of the execution of the algorithm
B
k
B_k
B
k
.
Which one of the following statements is true?
A
Both algorithms
B
1
B_1
B
1
and
B
2
B_2
B
2
are correct
B
Algorithm
B
1
B_1
B
1
is correct, but algorithm
B
2
B_2
B
2
is incorrect
C
Algorithm
B
2
B_2
B
2
is correct, but algorithm
B
1
B_1
B
1
is incorrect
D
Both algorithms
B
1
B_1
B
1
and
B
2
B_2
B
2
are incorrect
Show solution
Report
AFCAT
SSC CGL
SSC CGL Tier II
SPI
Homi Bhabha Class 9
MH Scholarship Class 4
MH Scholarship Class 7
About
How it works
Get the app
Blog
About
Send feedback
Email us
Terms
Refunds
Privacy
Contact
PYQ Vault
PYQs
Notes
Most Asked
Mocks
Board
Store
Visuals
Play
PYQs
Most Asked
Notes
Mocks
Board