5. Divide and Conquer #

Created Mon Jul 29, 2024 at 9:39 PM

#dnc

Main idea #

One of the most powerful techniques for solving problems is to break them down into smaller, more easily solved pieces.

Smaller problems are less overwhelming, and they permit us to focus on details that are lost when we are studying the whole thing.

Steps #

Breaking down problems #

Two important algorithm design paradigms are based on breaking problems down into smaller problems.

Note: Relation to recursion - In DnC, subproblems are of the same type as the parent, so recursion is the natural choice for programming.

When is DnC useful? #

Whenever the merging takes less time than solving the two subproblems, we get an efficient algorithm.

Merge sort is an example, since merging is linear while sorting two halves has a log factor.

Info about DnC #

Decrease-and-conquer method (related) #

In some problems, its possible to make the input smaller (i.e. without splitting into multiple inputs), after doing some (efficient) compute in each step. Since we don’t have multiple inputs, there is no combine step. Code may be purely iterative (tail recursive) here.

Examples: