chapter
    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 , where the elements , , 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:



    Consider the following two algorithms to compute entries of . Assume that for both the algorithms, for all , has been initialized to .

    Algorithm : For
        For
            

    Algorithm : For
        For
            For
                If
                    

    Algorithm , is said to be correct if and only if it calculates the correct values of , for all , (as per the recursive formulation) at the end of the execution of the algorithm .

    Which one of the following statements is true?
    Question 2
    2024 Slot Set2 PYQ

    Let be an array containing integer values. The distance of is defined as the minimum number of elements in that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array is ___________

    Question 3
    2021 Slot Set2 PYQ
    In a directed acyclic graph with a source vertex , 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 other than , the quality-score of is defined to be the maximum among the quality-scores of all the paths from to . The quality-score of is assumed to be 1.

    s a b c d e f g t 9 1 1 9 1 1 1 9 1 9 1 9
    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 to be the maximum amount earned by cutting a rod of length meters into one or more pieces of integer length and selling them. For , let denote the selling price of a rod whose length is meters. Consider the array of prices:


    Which of the following statements is/are correct about ?
    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.

    Why MastersUp

    Personalised first. High quality throughout.

    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_Set2 MCQ
    Consider a table , where the elements , , 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:



    Consider the following two algorithms to compute entries of . Assume that for both the algorithms, for all , has been initialized to .

    Algorithm : For
        For
            

    Algorithm : For
        For
            For
                If
                    

    Algorithm , is said to be correct if and only if it calculates the correct values of , for all , (as per the recursive formulation) at the end of the execution of the algorithm .

    Which one of the following statements is true?
    1. A.

      Both algorithms and are correct

    2. B.

      Algorithm is correct, but algorithm is incorrect

    3. C.

      Algorithm is correct, but algorithm is incorrect

    4. D.

      Both algorithms and are incorrect

    Question 2 · Algorithms · 2024_Set2 NAT

    Let be an array containing integer values. The distance of is defined as the minimum number of elements in that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array is ___________

    Question 3 · Algorithms · 2021_Set2 NAT
    In a directed acyclic graph with a source vertex , 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 other than , the quality-score of is defined to be the maximum among the quality-scores of all the paths from to . The quality-score of is assumed to be 1.

    s a b c d e f g t 9 1 1 9 1 1 1 9 1 9 1 9
    The sum of the quality-scores of all the vertices in the graph shown above is __________.
    Question 4 · Algorithms · 2021_Set2 MCQ
    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?
    1. A.

      21

    2. B.

      23

    3. C.

      25

    4. D.

      30

    Question 5 · Algorithms · 2021_Set1 MSQ
    Define to be the maximum amount earned by cutting a rod of length meters into one or more pieces of integer length and selling them. For , let denote the selling price of a rod whose length is meters. Consider the array of prices:


    Which of the following statements is/are correct about ?
    1. A.

    2. B.

    3. C.

      is achieved by three different solutions.

    4. D.

      cannot be achieved by a solution consisting of three pieces.

    More previous year questions (pyqs) in this unit