chapter

    Divide and Conquer Notes for Cmi M.sc. and Ph.d. Computer Science

    Divide and Conquer notes for CMI M.Sc. and Ph.D. Computer Science: 31 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice

    Divide and Conquer notes

    The three steps of divide and conquer

    Intuition

    The three steps of divide and conquer

    A divide-and-conquer algorithm cuts a problem into smaller copies, solves each, and glues the answers together.

    The problem it solves

    You have a large problem. You cut it into smaller copies of the same problem, solve each small copy, and glue the answers together. A divide-and-conquer algorithm on input of size performs three steps. First, divide the input into subproblems, each of size at most for some constant . Second, recursively solve each subproblem. Third, combine the solutions into one answer using at most additional work.

    The idea made exact

    The triple determines the recurrence and hence the running time. Running example: sum of numbers. Divide the array into two halves of size . Recurse on each half. Combine by adding the two partial sums, which is one addition, so . Here , . The analogy of cutting a cake stops being valid here. A cake cut into pieces stays cut. In D&C, the subproblems are solved independently and their answers are merged, which can create new work.

    independent subproblems proportional shrinkage

    Writing the recurrence from the algorithm

    Derivation

    Writing the recurrence from the algorithm

    The triple captures the exact cost structure of any divide and conquer algorithm.

    is a power of base case size 1 takes
    1. Identify the input size .parameter that shrinks
    2. Count , the number of recursive calls.branching factor
    3. Identify , the factor by which each subproblem shrinks.size becomes
    4. Measure , the cost to divide plus combine.work outside recursive calls
    5. Write for , with .recurrence equation

    CHECK: for sum of numbers, , , . So . Expand once: . After levels, . This matches the linear scan, confirming that D&C on sum gives no speedup.

    Result
    Check

    Sum of numbers: . Recurrence solves to , matching the linear scan.

    When divide and conquer beats brute force

    Derivation

    When divide and conquer beats brute force

    Splitting only saves time when the combine step is cheaper than redoing the work.

    Master Theorem cases critical exponent

    Case 1: grows slower than . The leaves of the recursion tree dominate. . Example: sum has , , , . So . No speedup over a linear scan.

    Case 2: grows like . Every level of the recursion tree contributes equally. . Example: merge sort has , , . So , a speedup over the brute-force sort.

    Case 3: grows faster than . The root of the recursion tree dominates. , provided is at most a constant fraction of . The exact condition for speedup: the recurrence must solve to something strictly smaller than the brute-force bound.

    Result
    Check

    For merge sort, matches , yielding . For sum, is smaller than , yielding .

    28 more cards in this chapter

    Free preview ends here

    Login to view the complete notes

    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.

    Divide and Conquer Notes for CMI M.Sc. and Ph.D. Computer Science

    Divide and Conquer notes for CMI M.Sc. and Ph.D. Computer Science: 31 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.

    The three steps of divide and conquer

    Intuition

    The three steps of divide and conquer

    A divide-and-conquer algorithm cuts a problem into smaller copies, solves each, and glues the answers together.

    The problem it solves

    You have a large problem. You cut it into smaller copies of the same problem, solve each small copy, and glue the answers together. A divide-and-conquer algorithm on input of size performs three steps. First, divide the input into subproblems, each of size at most for some constant . Second, recursively solve each subproblem. Third, combine the solutions into one answer using at most additional work.

    The idea made exact

    The triple determines the recurrence and hence the running time. Running example: sum of numbers. Divide the array into two halves of size . Recurse on each half. Combine by adding the two partial sums, which is one addition, so . Here , . The analogy of cutting a cake stops being valid here. A cake cut into pieces stays cut. In D&C, the subproblems are solved independently and their answers are merged, which can create new work.

    independent subproblems proportional shrinkage

    Writing the recurrence from the algorithm

    Derivation

    Writing the recurrence from the algorithm

    The triple captures the exact cost structure of any divide and conquer algorithm.

    is a power of base case size 1 takes
    1. Identify the input size .parameter that shrinks
    2. Count , the number of recursive calls.branching factor
    3. Identify , the factor by which each subproblem shrinks.size becomes
    4. Measure , the cost to divide plus combine.work outside recursive calls
    5. Write for , with .recurrence equation

    CHECK: for sum of numbers, , , . So . Expand once: . After levels, . This matches the linear scan, confirming that D&C on sum gives no speedup.

    Result
    Check

    Sum of numbers: . Recurrence solves to , matching the linear scan.

    When divide and conquer beats brute force

    Derivation

    When divide and conquer beats brute force

    Splitting only saves time when the combine step is cheaper than redoing the work.

    Master Theorem cases critical exponent

    Case 1: grows slower than . The leaves of the recursion tree dominate. . Example: sum has , , , . So . No speedup over a linear scan.

    Case 2: grows like . Every level of the recursion tree contributes equally. . Example: merge sort has , , . So , a speedup over the brute-force sort.

    Case 3: grows faster than . The root of the recursion tree dominates. , provided is at most a constant fraction of . The exact condition for speedup: the recurrence must solve to something strictly smaller than the brute-force bound.

    Result
    Check

    For merge sort, matches , yielding . For sum, is smaller than , yielding .

    Recursion without real division

    Wrong belief

    Recursion without real division

    Any recursive algorithm is divide and conquer.

    Why it feels right

    D&C is recursive, so recursion looks like D&C.

    Smallest counterexample

    Factorial, , with . This is recursion, but the subproblem size is , not for any constant . The recurrence is , which solves to . There is no division into smaller subproblems of proportional size. The algorithm just peels off one element at a time.

    Counter rule

    D&C requires subproblems of size at most for some constant . Recursion with subproblem size is iteration in disguise, sometimes called decrease-and-conquer.

    How it shows up in options

    The exam describes a recursive algorithm and asks for its paradigm. Options include divide and conquer, decrease and conquer, and dynamic programming. Choosing D&C just because it is recursive is wrong.

    More notes in this unit