chapter

    Dynamic Programming Pyqs for Cmi M.sc. and Ph.d. Computer Science

    Solve 0+ Dynamic Programming previous year questions for CMI M.Sc. and Ph.D. Computer Science with answers and detailed solutions. Free sample questions below

    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.

    Explore complete test series, official past papers, and chapter-wise study tools.

    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 PYQs for CMI M.Sc. and Ph.D. Computer Science

    Solve 0+ Dynamic Programming previous year questions for CMI M.Sc. and Ph.D. Computer Science with answers and detailed solutions. Free sample questions below.

    Why recomputing subproblems wastes time

    Intuition

    Why recomputing subproblems wastes time

    Dynamic programming stores each answer the first time it is computed, converting exponential-time recursion into polynomial time when subproblems recur.

    The problem it solves

    A staircase has 6 steps. You can climb 1 or 2 steps at a time. Let be the number of distinct ways to reach step . A naive recursive program to compute makes 15 function calls. But only 6 distinct subproblems exist: through . The subproblem is solved twice, three times, and five times. Each recomputation wastes time proportional to the size of its subtree.

    The idea made exact

    The next time the same subproblem appears, the program reads the stored value in constant time. The 15 recursive calls collapse to 6 computations and 9 table lookups. The exact principle is this: when a problem decomposes into subproblems and the same subproblems recur, cache every answer. This converts exponential-time recursion into polynomial time whenever the number of distinct subproblems is polynomial.

    overlapping subproblems memoization

    The recurrence and why caching gives the right answer

    Derivation

    The recurrence and why caching gives the right answer

    Assumption: a staircase has steps, and each move climbs 1 or 2 steps. Let be the number of distinct ways to reach step .

    steps moves of 1 or 2
    1. Any valid sequence of moves ending at step ends with either a 1-step from step or a 2-step from step .exhaustive cases for the last move
    2. These two cases are disjoint because the last move is either 1 step or 2 steps, never both.mutually exclusive final actions
    3. The number of ways ending with a 1-step equals , because the prefix is any valid way to reach step .bijection between prefixes and full paths
    4. The number of ways ending with a 2-step equals , by the same reasoning.bijection for the 2-step case
    5. Since the cases are disjoint and exhaustive, for .sum rule of counting
    6. Each is a well-defined integer, so computing it once and storing the answer is safe.deterministic subproblems
    7. Every future lookup returns the same value, and the total work becomes instead of exponential.linear number of distinct states

    This decomposition is an instance of Bellman's principle: the solution to a problem is built from solutions to its subproblems.

    Result

    Valid for , with base cases and .

    Check

    For , . Direct enumeration gives , , . Three ways. Matches.

    More previous year questions (pyqs) in this unit