5101 - Design & Analysis of Algo
← 5101 - Design & Analysis of Algo
session: "5101-design-analysis-of-algo/2026-10-03 0000 DAA 03 Oct"
title: "DAA 03 Oct"
date: "2026-10-03 00:00"
duration: "1h 26m"
language: "en"
model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"
parts: 2
transcript_chars: 55368
generated: "2026-11-23T23:50:15+05:30"
This class first recaps the maximum subarray problem and its three solution mechanisms, then covers Strassen's matrix multiplication (reducing complexity from n³ to n^2.81) and the closest pair problem in 1D and 2D as the final divide-and-conquer problem. The second half motivates and introduces recurrence relations — factorial, Fibonacci, merge sort, binary search, and Tower of Hanoi — and presents the three methods for solving them: substitution (guessing), recurrence tree, and the master's theorem. It sits at the transition point where divide-and-conquer algorithms end and formal complexity analysis of recursive algorithms begins.
Three mechanisms: (1) a heuristic variant of brute force where repetitive sets are not used, differing only in their order; (2) dynamic programming leading to a computational complexity of n log n, assuming the maximum sum could lie in the left, right, or cross section; (3) a divide-and-conquer algorithm that finds the maximum sum value in order of n time by preserving the last-stage output of maximum sum and current sum. It matters as the template for divide-and-conquer thinking (left/right/cross) reused by the closest pair problem.
A famous divide-and-conquer algorithm for matrix multiplication that reduces computational complexity from n³ to n^2.81. Though the reduction looks small, at higher sizes the number of calculations is reduced significantly. Its aim is to minimize multiplication operations, compensated by more addition operations, so both exact solution and reduction in multiplications are achieved. It works for 2, 4, 8, 16, 32, 64 order matrices; at the lowest stage a 4×4 matrix can be assumed as a combination of multiple 2×2 matrices (base condition is the 2×2 product).
In a space with n points, identify which two points are closest / at the least distance — the pair of points with the smallest distance between them within a given collection of n points. It finds relevance in applications across domains from computational geometry to pattern recognition and beyond.
Similar to maximum subarray: divide points based on the median; find the distance among points on the left side, among points on the right side, and the cross-section distance; whichever is lower is the result. Iteratively divide down to the one-point (or two-point) level, then combine.
Irrespective of the number of dimensions, the median is always calculated based on the x coordinate. In all books (for 2D, 3D, including Cormen) the closest pair problem is referred with respect to the x coordinate only. (You could use the y coordinate if you change the algorithm accordingly; both would be correct.)
Stop when just two points remain (at least 2 points are needed to estimate a distance). Compute left distance, right distance, and middle/cross distance; whichever is smaller propagates upwards.
Compute dL (minimum distance on left half) and dR (minimum distance on right half); let d = minimum of dL and dR. Then only points within proximity of dimension/length d from the median need to be considered — make a square of d; distances among points in this region will be at most less than 2d. There is no need to calculate all point distances on the left and right.
A mathematical relationship or equation that describes the recursion of a function or a sequence in terms of the previous value. Along with the base condition, an initial condition may be specified to determine the value of the function for the smallest input size where the relation may or may not hold.
All recursions that reduce their value in every iteration and tend towards the base case. If a recursion does not follow this property, the algorithm will never converge.
Base case: the stopping point or terminating point of the recursive algorithm (e.g., single element level in merge sort; set of two points in closest pair). Recursive case: the iterative division of a problem — e.g., in merge sort, every time the same function is called to partition the array into subarrays. Seen in binary search, quick sort, closest pair, maximum subarray.
Also called the guessing method / method of guessing. Guess a solution (e.g., the computational complexity of T(n) = 2T(n/2) + n), then prove the guess correct via induction. The guess comes with experience; "we cannot directly apply."
Draw the tree structure formed by the divide-and-conquer subproblems (big problem → subproblem → sub-subproblem), observe how the algorithm behaves, and declare its computational complexity.
The "famous" and "best" mechanism; a specialized method with a specific set of cases. If the cases are valid, substitute values and get the complexity directly. For T(n) = aT(n/b) + f(n): n is the input size, a is the number of subproblems, n/b is each subproblem's size; require a ≥ 1, b > 1 (if b is not greater than 1 the algorithm will never converge — the problem must be reduced), and f(n) > 0 and asymptotically positive. Procedure: first determine a, b, f(n) from the recurrence, immediately compute n^(log_b a), and compare it with f(n).
In practice we neglect technical details (floor/ceiling, unequal halves) when stating and solving recurrences; otherwise estimating complexity becomes very difficult. There is a hidden assumption here.
Recurrence relations apply only to problems where we make repetitive calls to the same function (iterative division of the problem). All divide-and-conquer problems are recurrence problems; in most cases the division follows a logarithmic order (n, n/2, n/4, n/8, n/16).
When designing an algorithm you must decide the base condition yourself (e.g., merge sort stops when one element remains; in the quick-sort/insertion hybrid, when the array element count is 5, apply insertion sort directly). If a recursion is given explicitly to solve, the base condition and initial conditions are given to you.
Consider the number of inputs, but also analyze how the problem can be solved — in one go or with multiple similar calls (e.g., factorial removes one element and recurses; like a for loop repeating again and again).
8×8 matrix example (Strassen context): Two matrices of order 8×8; one is taken as an identity matrix so the product is easy. An 8×8 matrix can be assumed as multiple 4×4 matrices: A11, A12, A21 are each 4×4 matrices, dividing the product accordingly. All 7 products are computed. Because the matrix is an identity matrix (maximum zeros, only diagonal elements), the multiplication can be performed and the result obtained in a single slot; going purely with Strassen's, the 4×4 blocks would be further divided into 2×2 and results for m1–m7 combined. (The instructor says he will share the PPT for this problem.)
1D closest pair example: Points plotted on a line: −4, −2, 1, 4, 5, 10 (six points, sorted). Median position: n by 2 = 3, so the median is 1. Subsets: {−4, −2, 1} and {4, 5, 10}. Further division: {−4, −2} and {1}; {4, 5} and {10}. Distances: |−4 − (−2)| = 2; distance between −2 and 1 = 3 (instructor first said 2, then corrected to 3); 4 and 5 distance = 1; 5 and 10 distance = 5. Left minimum: −4 and −2 with distance 2. Right minimum: 4 and 5 with distance 1. Cross-section: median was 1, and no point is less than distance 1 from the median, so the result is 4 and 5 with value 1 — the closest pair.
2D closest pair example: Points taken: (1, 2), (3, −4), (−1, 6), (5, 7), (2, 3), (−2, −4). Arranged by x coordinate: (−2, −4), (−1, 6), (1, 2), (3, −4), (5, 7). With 5 points, median position is n by 2 plus 1 = 3, so (1, 2) is the median point. Bifurcation: {(−2, −4), (−1, 6), (1, 2)} and {(3, −4), (5, 7)}; further division holds (1, 2) aside, leaving {(−2, −4), (−1, 6)} and the already-two-point set. Distances computed among these pairs; then DL, DR, and combined DC are obtained and the smaller is the resultant. Sample distance estimation shown: Euclidean with (−2 − (−1))² plus (−4 − 6)² [as spoken; the instructor's spoken formula is garbled — see Flagged for later].
Factorial of 6: 6 × 5 × 4 × 3 × 2 × 1 = 30 × 24 = 720. Via the recurrence: 6 × f(5) → 6 × 5 × f(4) → 6 × 5 × 4 × f(3) → … → 6 × 5 × 4 × 3 × 2 × f(1) → 6 × 5 × 4 × 3 × 2 × 1 (f(0) = 1), again reaching 720.
Fibonacci series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … (each term is the sum of the previous two). The transcript's enumeration is partly garbled (e.g., "28 and 13 is 34", "20, 3, 5, 8") — the intended series is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
Tower of Hanoi with 3 disks: Move sequence described — shift the smaller disk, move the bigger one, then the small one goes here, the medium one goes here, and lastly this comes; original problem used 63 disks.
Substitution example: T(n) = 2T(floor(n/2)) + n, guess n log n, proved via induction as above.
Recurrence tree example: Merge sort tree; n appears at each of log n levels → n log n.
Master's theorem comparison example: n² versus n^2.26 → ε = 0.26, case 1, complexity n^(log_b a).
Q (step 4 of 1D closest pair): What happens in step 4, and what are the "2 to 3 points" that continue?
A: We stop when just two points remain. In each half there are two points; compute the distance among them — call it distance L on the left, distance r on the right, and in the intersection compute distance c; whichever is smaller, declare those two points as the closest and store the result, proceeding similarly upward until the two points with the minimum distance are identified. The base/stopping condition is the pair of two points.
Q (2D slide): Is it correct that after making the median we run the algorithm to identify which points are closest to the median on the left and right?
A: No — it is the points having the least distance, not closest to the median. First identify the two points having dL (minimum distance) on the left, similarly the minimum distance on the right; then take the minimum of these and make a square box of dimension d. Very few points will have distance less than or equal to d; if some point is found, declare it the closest, otherwise d is the closest. The distance between two points in the left half and the distance between two points in the right half are independent of their distance from the median — they can be anywhere. Because it is recursive, the halves have already been further divided by different medians.
Q: Could something like a minimum-subarray algorithm be used to put all points of one left half into a single array?
A: It is similar to maximum sum / minimum sum, but with the little difference of making this square; otherwise it is equivalent to that algorithm.
Q (median for two points): How is the median calculated for two points — it will be mean and median same, so why specifically say median?
A: The instructor responds by giving the 1D example (see Worked examples) to clarify.
Q (median step): Does "check the values and change" mean the median can be any other value?
A: You have to arrange the points in x-coordinate order; median requires sorting first, and only then can median be applied — that is the rule of the algorithm. In design and analysis you are free to make your own variant (e.g., use mean), but then the points would not
One line per segment, [hh:mm:ss] timestamp first.
loading…