Course: Advanced Data Structures and Algorithms
-
High School Method: Multiplying two
$n$ -digit numbers digit-by-digit requires$n^2$ multiplications and$n^2$ additions ($\Theta(n^2)$). -
Kolmogorov's Conjecture: Andrey Kolmogorov conjectured in conferences that
$O(n^2)$ was optimal for integer multiplication. -
Divide and Conquer (Naive) [00:04:37]:
- Split
$A$ into$A_1$ (first$n/2$ bits) and$A_2$ (last$n/2$ bits):$A = A_1 2^{n/2} + A_2$ . $A \cdot B = (A_1 2^{n/2} + A_2)(B_1 2^{n/2} + B_2)$ $A \cdot B = A_1 B_1 2^n + (A_1 B_2 + A_2 B_1) 2^{n/2} + A_2 B_2$ - This requires 4 multiplications of size
$n/2$ . -
Recurrence:
$T(n) = 4T(n/2) + O(n)$ . -
Result: Solving this gives
$T(n) = O(n^2)$ , which fails to improve on the naive method.
- Split
-
The Trick [00:36:25]: Anatoly Karatsuba, a graduate student, realized we could compute the middle term
$(A_1 B_2 + A_2 B_1)$ using only one additional multiplication:- Let
$M_1 = A_1 B_1$ - Let
$M_2 = A_2 B_2$ - Let
$M_3 = (A_1 + A_2)(B_1 + B_2)$ - Then
$(A_1 B_2 + A_2 B_1) = M_3 - M_1 - M_2$ .
- Let
-
New Recurrence [00:39:30]:
$$T(n) = 3T(n/2) + O(n)$$ -
Complexity Analysis [00:46:57]:
- Solving the recurrence leads to
$T(n) \approx 15 \cdot 3^{\log_2 n}$ . - Using the log property
$a^{\log_c b} = b^{\log_c a}$ , we get$n^{\log_2 3}$ . -
$\log_2 3 \approx 1.585$ . -
Final Complexity:
$O(n^{1.59})$ , a significant improvement over$O(n^2)$ .
- Solving the recurrence leads to
-
The Master Form:
$T(n) = a T(n/b) + n^c$ . -
Parameters:
-
$a$ : Number of subproblems. -
$b$ : Factor by which subproblem size is reduced. -
$n^c$ : Combining/Dividing cost.
-
- Teaser: The instructor will derive the general solution (Master Theorem) in the next lecture to avoid manual recurrence solving every time.
-
Closest Pair Problem: Find the two closest points among
$n$ points in a 2D plane. -
Naive Complexity:
$O(n^2)$ by checking all$n(n-1)/2$ pairs. -
Challenge [01:09:22]: Can we do it in less than
$O(n^2)$ ? The instructor encourages students to struggle with this for a few days to appreciate the forthcoming D&C solution ($O(n \log n)$). - Philosophy [01:10:25]: "Only if you wander in the hot sun will you realize the value of the shade." Struggle is necessary to appreciate creative algorithm design.
Key Terms Corrected:
- Kolmograo -> Kolmogorov
- Karashtubah -> Karatsuba
- clips table -> Log Table / Slide Rule
- Lomato -> Lomuto
- DNC -> Divide and Conquer