Course: Advanced Data Structures and Algorithms
The instructor reviews the foundational blocks of algorithm knowledge:
- Computational Problem: Framed In a mathematical model with objects and operations.
- Specification: Defined by the Input-Output Relation.
- Constructive Solution: A process consisting of explicitly computable steps.
- Broad Definition of Computation [00:03:58]: It's not just "number crunching." Computation is any mathematical manipulation of objects within a defined model.
Inspired by the villain's challenge to Bruce Willis in Die Hard with a Vengeance:
-
The Problem: Three jugs with water (
$A, B, C$ ). - Operation: Pour water from a larger bucket to a smaller one to double the smaller one's content.
- Goal: Empty one bucket.
-
State Space: Represented as a triplet of integers
$(10, 7, 4)$ . -
Transitions [00:06:59]:
- From
$(10, 7, 4)$ to$(3, 14, 4)$ (pouring from 10 to 7). - From
$(10, 7, 4)$ to$(6, 7, 8)$ (pouring from 10 to 4). - From
$(10, 7, 4)$ to$(10, 3, 8)$ (pouring from 7 to 4).
- From
-
The Challenge: Finding a generic procedure for enormous inputs (e.g.,
$91, 2168, \dots$ ) rather than ad-hoc visual solutions for small numbers. This is the essence of algorithmic thinking.
Input size addresses the problem of scale. It isn't always a single number (
- Sorting: Regulated by the number of items.
-
Matrix Multiplication (
$A \times B = C$ ) [00:14:41]:- Input:
$P \times Q$ matrix and$Q \times R$ matrix. - Size Parameters:
$P, Q, R$ . - Total physical items:
$PQ + QR = Q(P + R)$ . However, using$P, Q, R$ as separate parameters is more meaningful. -
Square Matrix:
$n \times n$ . Complexity is$O(n^3)$ because each of the$n^2$ elements in$C$ requires$n$ multiplications.
- Input:
-
Graphs [00:18:58]: Defined by two parameters: vertices (
$V$ ) and edges ($E$ ). Sparse graphs have few edges; dense graphs have many. - GCD [00:20:02]: A subtle case where the number of inputs is always "2," but the scale depends on the magnitude or bit-length of the numbers.
- Time Complexity: Measured by Instruction Count (Inherent property).
- Macroanalysis [00:13:19]: Focusing only on dominant/costly operations (e.g., multiplications) to simplify analysis.
-
Worst Case Complexity
$T(n)$ : The maximum instruction count over all possible inputs of size$n$ . This is the primary figure of merit for comparing algorithm$A_1$ ($f(n)$) and$A_2$ ($g(n)$).
When exact functions are hard to find, we use approximations to describe behavior as
-
Definition:
$f(n)$ is$O(g(n))$ if$f(n) \le c \cdot g(n)$ for some constant$c > 0$ and all$n \ge n_0$ . -
Meaning:
$g(n)$ is an upper bound. -
The "Loose Bound" Problem [00:29:20]: Mathematically,
$7n^2 + 10$ is$O(n^2)$ , but it is also$O(n^4)$ . While true,$O(n^4)$ is a "wild" or loose bound that doesn't help judge quality.
-
Definition:
$f(n)$ is$\Theta(g(n))$ if$c_1 \cdot g(n) \le f(n) \le c_2 \cdot g(n)$ . -
Meaning: A tight bound.
$f(n)$ is squeezed between two constant multiples of$g(n)$ . -
Example [00:34:02]:
$7n^2 + 10n + 9$ is$\Theta(n^2)$ because we can find constants (e.g.,$c_1=3, c_2=26$ ) such that it stays within the "band."
Growth rate determines which function overtakes another as
-
The Overtaking Point [00:54:57]:
-
Algorithm
$A_1$ :$100n^2$ . -
Algorithm
$A_2$ :$\frac{1}{1000}n^3$ . -
Small
$n$ :$A_2$ appears faster (it has a smaller constant). -
Threshold: At
$n \approx 10^5$ ,$A_1$ (lower growth rate) becomes significantly faster than$A_2$ .
-
Algorithm
- Philosophy: We always prefer the algorithm with the lower growth rate, regardless of constants, as it behaves better for "Big Data."
In increasing order of growth rate (asymptotically slower to faster):
-
$\log n$ (Logarithmic) -
$n$ (Linear) -
$n \log n$ (Linearithmic) -
$n^2$ (Quadratic) -
$n^3$ (Cubic) -
$2^n$ (Exponential) -
$n^n$ (Super-Exponential)
The instructor uses the Hunting Cub Analogy:
- A tiger cub doesn't go to a "hunting course"; it observes its elders. Similarly, students study "great algorithms" (Merge Sort, Dijkstra, etc.) to build a mental model for creative problem-solving.
- Once familiar with these "clever solutions," students can innovate by relating new problems to known patterns.
- High innovation in algorithms can be patented and marketed [01:47:21].
Preview for Next Week: Incremental and Decremental Design strategies.
Key Terms Corrected:
- Bruce Wilis -> Bruce Willis (Die Hard)
- 3 jugs -> The Three Jugs Problem
- PQ plus QR -> Matrix Dimensions (
$PQ + QR$ ) - Macro analysis -> Macroanalysis
- Big Oh -> Big O Notation
- Theta ->
$\Theta$ Notation - growing like 10 cube -> Cubic Growth
- incrementle design -> Incremental Design
- decrementle design -> Decremental Design