Practice Divide and Conquer in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

Divide and conquer is an algorithmic strategy that splits a problem into smaller subproblems of the same kind, solves those smaller problems, and then combines their solutions into one final answer. It is a structured form of decomposition often paired with recursion.

Break a big hard task into smaller versions of the same task, solve each one, then stitch the answers together.

Showing a random 20 of 50 problems.

Example 1

medium
For merge sort on n=32n=32, total comparisons are about nlogโก2nn \log_2 n. Estimate.

Example 2

medium
Binary search on [1,3,5,7,9,11,13,15,17][1,3,5,7,9,11,13,15,17] for 1313. Trace indices examined (0-indexed).

Example 3

medium
You compute x20x^{20} by repeated squaring. List the steps.

Example 4

challenge
FFT has T(n)=2T(n/2)+O(n)T(n)=2T(n/2)+O(n). State the complexity and one application.

Example 5

medium
Binary search looks for 7 in [1,3,5,7,9,11,13][1,3,5,7,9,11,13] (indices 0-6). Trace the indices examined.

Example 6

easy
A list of 32 elements is repeatedly halved. After how many halvings is the size reduced to 1?

Example 7

hard
Solve T(n)=2T(n/2)+nlogโกnT(n)=2T(n/2)+n\log n with master theorem.

Example 8

medium
A flawed divide-and-conquer routine splits a list of size nn into one piece of size nโˆ’1n-1 and one of size 1. What is its depth and resulting complexity?

Example 9

hard
Quicksort with median-of-three pivot avoids the worst case on sorted inputs. What recurrence does it now satisfy on average?

Example 10

medium
A divide-and-conquer power algorithm computes xnx^n as (xn/2)2(x^{n/2})^2. How many multiplications to compute x16x^{16}?

Example 11

challenge
Compute closed-form for T(n)=3T(n/2)+nT(n)=3T(n/2)+n via master theorem.

Example 12

challenge
You must find min AND max of nn items together. Show that โ‰ˆ3n2โˆ’2\approx \tfrac{3n}{2}-2 comparisons suffice using pairwise divide-and-conquer.

Example 13

easy
A divide-and-conquer algorithm splits into 44 subproblems of size n/4n/4 with O(n)O(n) combine. Write its recurrence T(n)T(n).

Example 14

medium
Solve T(n)=4T(n/2)+nT(n)=4T(n/2)+n via master theorem.

Example 15

medium
Solve the recurrence T(n)=2T(n/2)+O(1)T(n)=2T(n/2)+O(1) with T(1)=1T(1)=1 for n=8n=8 by unrolling, and give the Big-O.

Example 16

hard
Counting inversions in a list uses modified merge sort with T(n)=2T(n/2)+O(n)T(n)=2T(n/2)+O(n). Complexity?

Example 17

medium
Using the recurrence T(n)=2T(n/2)+nT(n)=2T(n/2)+n, compute T(4)T(4) given T(1)=0T(1)=0.

Example 18

hard
Strassen's matrix multiplication has T(n)=7T(n/2)+O(n2)T(n)=7T(n/2)+O(n^2). Compute the complexity.

Example 19

easy
A divide-and-conquer algorithm splits a problem into two halves and does O(n)O(n) work to combine. Write its recurrence T(n)T(n).

Example 20

easy
Binary search halves a sorted list of 6464 items. How many comparisons (worst case) to isolate one item?