Lecture 11
More divide and conquer (integer multiplication & median finding)
CSE 421 Autumn 2026
1
Previously…
2
Divide and conquer runtimes
The master theorem
3
Note: . The latter is exactly the number of leaves!
Matrix multiplication
Matrix multiplication decomposes into smaller matrix multiplications!�
4
Divide and conquer algorithm idea:
Divide: Decompose into 8 matrix multiplications of matrices�
Conquer: “Merge” by performing 4 matrix additions of matrices
Runtime:
Each one takes
Each one takes
Strassen’s divide and conquer (1968)
There is a way to decompose into 7 multiplications and 18 additions …
5
Previously: we were directly multiplying, and then adding:
- Volker Strassen (90 years old!) about his algorithm
“It is really very simple. I was surprised that nobody had found it before.”
Strassen’s divide and conquer (1968)
6
Wikipedia article for Strassen’s algorithm
2
Today
7
More Divide and Conquer:
Integer multiplication
Input: Two -bit binary numbers
Output: Their product (a -bit binary number)
8
Gradeschool multiplication algorithm takes time
Note: this is not in the word-RAM model. Instead, it’s counting the number of binary operations
Karatsuba’s algorithm
9
4 smaller multiplications
Similarly as in Strassen’s algorithm, �decompose each number into parts�(here two halves: most and least significant digits)
We can add numbers in time. And also multiply by (why?)
Karatsuba’s algorithm
10
4 smaller multiplications
Similarly as in Strassen’s algorithm, �decompose each number into parts�(here two halves: most and least significant digits)
Karatsuba’s algorithm
11
Can we do it with just 3 multiplications?
Karatsuba’s algorithm
12
Can we do it with just 3 multiplications?
Yes!
Karatsuba’s algorithm
13
Can we do it with just 3 multiplications?
Yes!
Karatsuba’s algorithm
14
Can we do it with just 3 multiplications?
Yes!
Improving integer multiplication
15
Multiplication
16
Median finding
Input: Input list for odd.
Output: The median element i.e. when .
17
Can do it in time using sorting + selecting the middle element.
Is achievable?
Seems impossible…
… but we’ve seen other seemingly impossible things in this course
Median finding
18
Let’s try to design a divide and conquer algorithm.
What would the recurrence relation have to look like to have ?
Two natural possibilities:
Possibility 1:
Possibility 2:
Leaf-heavy computation
The challenge would be to split the input into two halves with compute.�And to “merge” the solutions to the two subproblems together also in compute
With time, we can make a constant number of passes through the input .�After a constant number of passes, we need to find one sublist of size which must contain the median. Then, recurse.
Most compute in largest conquer step
“Selection” finding
It will help us to consider a generalization of the median finding problem, called “Selection” finding.
Input: pair .
Output: The -th element when .
19
Median finding is just Selection finding for .
Selection finding
Find the 6th element
20
The idea:
Inspired by the Quicksort “pivot” approach:
?
The good news: only one branch!
But is our instance size shrinking fast enough?
Depends on how lucky/unlucky we are with the pivot..
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Selection finding with pivot (examples)
Find the 6th element
21
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Selection finding with pivot (examples)
Find the 6th element
22
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
Selection finding with pivot (examples)
Find the 6th element
23
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
Selection finding with pivot (examples)
Find the 6th element
24
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
3
3
3
3
0
1
1
2
0
1
2
2
2
7
4
4
8
6
6
5
Where is the 6th element?
Randomly select a pivot
In , since
length 9
length 4
length 7
Recurse on this set
Selection finding with pivot (examples)
Find the 6th element
25
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Selection finding with pivot (examples)
Find the 6th element
26
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
Selection finding with pivot (examples)
Find the 6th element
27
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
Selection finding with pivot (examples)
Find the 6th element
28
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
length 2
length 3
length 15
Where is the 6th element?
In , since
Recurse on this set
Selection finding with pivot (examples)
Find the 6th element
29
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Selection finding with pivot (examples)
Find the 6th element
30
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
Selection finding with pivot (examples)
Find the 6th element
31
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
Selection finding with pivot (examples)
Find the 6th element
32
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
Randomly select a pivot
0
0
1
1
1
2
2
2
2
7
3
3
3
3
4
4
8
6
6
5
length 5
length 4
length 11
Where is the 6th element?
In , since and
In fact, in this case, the 6th element is exactly the pivot! So we just output it right away.
Selection finding
Randomized algorithm :
33
Note that the original -th element will now be the -th!
Runtime analysis
34
Runtime analysis
35
Runtime analysis
Expected runtime analysis:
36
Runtime analysis
Expected runtime analysis:
Total expected runtime: .
37