# Lecture 23: Integrate structures, algorithms, and evidence ## Select structures and algorithms for integrated problems **Instructor:** [Dr. Debasish Pattanayak](https://drdebmath.github.io)
## The required operation determines the candidate structures | Application | Structure | Algorithmic idea | |---|---|---| | process decimal digits stably | buckets | radix passes | | transform every tree node | binary tree | recursive traversal | | multiply matrix blocks | matrices | recursive decomposition | | vary legal behavior by piece | hierarchy | dynamic dispatch |
## Block recursion reduces matrix multiplication to smaller compatible products Split each matrix into four blocks, recursively multiply compatible block pairs, and add partial results. The base case multiplies a sufficiently small block directly. A practical implementation must also handle dimensions that are not powers of two.
## Stable buckets let radix sort process one digit at a time For non-negative decimal integers: 1. distribute by the current digit; 2. collect buckets without changing equal-digit order; 3. move to the next digit. The queue-like bucket structure supplies stable collection order.
## Tree inversion swaps each node’s children recursively ~~~cpp Node* invert(Node* root) { if (root == nullptr) return nullptr; Node* left = invert(root->left); Node* right = invert(root->right); root->left = right; root->right = left; return root; } ~~~
## A shared Piece interface lets each chess type choose its move A base
Piece
promises legal-move generation.
Rook
,
Bishop
, and
Knight
implement different movement rules. The board owns pieces; the caller asks through the common interface.
## A capstone needs state, invariants, ownership, stopping rules, and adversarial tests Before implementation, identify: - state and invariant; - ownership and lifetime; - required operations; - base case or stopping condition; - normal, boundary, and invalid tests; - expected time and space growth.
## A capstone is justified by its representation, algorithm, invariant, and evidence - Represent state with a structure whose operations match the problem. - Apply algorithms through those operations. - Preserve bounds, invariants, ownership, and progress. - Use the dependency graph to revisit the earliest uncertain prerequisite.