Dynamic Programming, Greedy Algorithms and Optimization PYQs for GATE CS
Solve 5+ Dynamic Programming, Greedy Algorithms and Optimization previous year questions for GATE CS with answers and detailed solutions. Free sample question
Try a question
Answer it here to see how it works. Nothing is recorded until you sign in.
Question 1
2026 Slot Set2 PYQ
Consider a table T, where the elements T[i][j], 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]=1for k=0,1,2,…,n T[i][j]=2T[i−1][j]+3T[i][j−1]for 1≤i,j≤n Consider the following two algorithms to compute entries of T. Assume that for both the algorithms, for all 0≤i,j≤n, 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 Bk, k∈{1,2} is said to be correct if and only if it calculates the correct values of T[i][j], for all 0≤i,j≤n, (as per the recursive formulation) at the end of the execution of the algorithm Bk.
Which one of the following statements is true?
Question 2
2024 Slot Set2 PYQ
Let A be an array containing integer values. The distance of A is defined as the minimum number of elements in 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 ___________
Question 3
2021 Slot Set2 PYQ
In a directed acyclic graph with a source vertex s, the quality-score of a directed path is defined to be the product of the weights of the edges on the path. Further, for a vertex v other than s, the quality-score of v is defined to be the maximum among the quality-scores of all the paths from s to v. The quality-score of s is assumed to be 1.
The sum of the quality-scores of all the vertices in the graph shown above is __________.
Question 4
2021 Slot Set2 PYQ
Consider the string abbccddeee. Each letter in the string must be assigned a binary code satisfying the following properties:
1. For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter. 2. For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is assigned a code whose length is at most the length of the code assigned to the other letter.
Among the set of all binary code assignments which satisfy the above two properties, what is the minimum length of the encoded string?
Question 5
2021 Slot Set1 PYQ
Define Rn to be the maximum amount earned by cutting a rod of length n meters into one or more pieces of integer length and selling them. For i>0, let p[i] denote the selling price of a rod whose length is i meters. Consider the array of prices:
p[1]=1,p[2]=5,p[3]=8,p[4]=9,p[5]=10,p[6]=17,p[7]=18 Which of the following statements is/are correct about R7?
Free preview ends here
Login to view the complete previous-year questions and solutions
Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.
Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.
Built around you, not around a syllabus PDF
Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.
Revision that hits your weak spots
We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.
Questions calibrated to the real exam
Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.
Notes written for recall, not for volume
Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.
One place for everything
Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.
Honest progress
No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.
Unlock the whole course
Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.
Dynamic Programming, Greedy Algorithms and Optimization PYQs for GATE CS
Solve 5+ Dynamic Programming, Greedy Algorithms and Optimization previous year questions for GATE CS with answers and detailed solutions. Free sample questions below.
Chapter Roadmap: Counting and Combinatorics
Chapter Roadmap
Counting & Combinatorics
School Level Mathematics · Data Science
1
Selection Intuition
Understand when order does not matter.
You are here
2
Core Tool: The Choose Formula
Count unordered groups without listing them.
3
Exam Methods
Apply the formula to multiple groups, categories, and conditions.
4
Constraints & Traps
Handle "at least", "at most", fixed items, and overcounting.
5
Exam Readiness
Final checklist to choose the correct method quickly.
By the end: You will count unordered selections from distinct groups, apply multiplication and addition rules correctly, and solve constrained selection problems confidently.
What is a Combination?
Concept · Level 1
What is a Combination?
In counting problems, most questions ask you to either arrange objects or select objects.
Selection
Only who or what is in the group matters.
Arrangement
Both the members and their order matter.
The Swap Test
Ask: "If I swap two chosen items, does the outcome change?" No → Combination | Yes → Arrangement
Example
Selecting 3 questions out of 5 to answer on a paper: choosing questions 1, 2, 3 is the same as choosing 3, 2, 1. The set of attempted questions is unchanged. This is a combination.
Dynamic Programming, Greedy Algorithms and Optimization: Solved Questions with Step-by-Step Explanations (5 Problems)
Question 1 · Algorithms · 2026_Set2MCQ
Consider a table T, where the elements T[i][j], 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]=1for k=0,1,2,…,n T[i][j]=2T[i−1][j]+3T[i][j−1]for 1≤i,j≤n Consider the following two algorithms to compute entries of T. Assume that for both the algorithms, for all 0≤i,j≤n, 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 Bk, k∈{1,2} is said to be correct if and only if it calculates the correct values of T[i][j], for all 0≤i,j≤n, (as per the recursive formulation) at the end of the execution of the algorithm Bk.
Which one of the following statements is true?
A.
Both algorithms B1 and B2 are correct
B.
Algorithm B1 is correct, but algorithm B2 is incorrect
C.
Algorithm B2 is correct, but algorithm B1 is incorrect
D.
Both algorithms B1 and B2 are incorrect
Question 2 · Algorithms · 2024_Set2NAT
Let A be an array containing integer values. The distance of A is defined as the minimum number of elements in 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 ___________
Question 3 · Algorithms · 2021_Set2NAT
In a directed acyclic graph with a source vertex s, the quality-score of a directed path is defined to be the product of the weights of the edges on the path. Further, for a vertex v other than s, the quality-score of v is defined to be the maximum among the quality-scores of all the paths from s to v. The quality-score of s is assumed to be 1.
The sum of the quality-scores of all the vertices in the graph shown above is __________.
Question 4 · Algorithms · 2021_Set2MCQ
Consider the string abbccddeee. Each letter in the string must be assigned a binary code satisfying the following properties:
1. For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter. 2. For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is assigned a code whose length is at most the length of the code assigned to the other letter.
Among the set of all binary code assignments which satisfy the above two properties, what is the minimum length of the encoded string?
A.
21
B.
23
C.
25
D.
30
Question 5 · Algorithms · 2021_Set1MSQ
Define Rn to be the maximum amount earned by cutting a rod of length n meters into one or more pieces of integer length and selling them. For i>0, let p[i] denote the selling price of a rod whose length is i meters. Consider the array of prices:
p[1]=1,p[2]=5,p[3]=8,p[4]=9,p[5]=10,p[6]=17,p[7]=18 Which of the following statements is/are correct about R7?
A.
R7=18
B.
R7=19
C.
R7 is achieved by three different solutions.
D.
R7 cannot be achieved by a solution consisting of three pieces.