Sources & reconstruction notes
- Lecture 2 (Püschel): Unit-cost RAM model, asymptotic analysis and O-notation, Karatsuba multiplication, motivation for maximum subarray sum.
- Lecture 3 (first hour): O-notation recap and “abuse of notation”, the Maximum-Subarray-Sum problem, Algorithms 1 () and 2 (), start of divide and conquer.
- No script chapter was provided for this week, so there is no script numbering to follow. Section numbers below are my own.
- Missing material:
- In Lecture 2, the part right after the break is garbled (only fragments like “nochmal ableiten … 6n … also gilt. Allgemein”). §3.4 reconstructs it as the standard polynomial-vs-exponential l’Hôpital example. ⚠ Reconstruction.
- In Lecture 3, the entire second hour is missing. The recording contains only noise (“Thank you” captions) after the three cases of divide and conquer were stated. §3.8 completes the divide-and-conquer algorithm the standard way. ⚠ Reconstruction: check it against Püschel’s handwritten notes on Moodle.
- The stock-price example array (8 values) cannot be recovered from the transcript. Only the optimum, 29, is certain. §4 uses my own example arrays instead.
1. Executive Overview & Core Objectives
Week 1 counted elementary operations exactly. This week makes such counts machine-independent. The unit-cost random-access model (Unit-Cost-RAM-Modell) defines what an operation is. Asymptotic analysis (asymptotische Laufzeitanalyse) with O-notation (O-Notation) removes the constant factors that differ between machines and keeps only the growth (Wachstum). Two algorithms then show this in action. Karatsuba’s algorithm multiplies -digit numbers with digit multiplications instead of , through divide and conquer and a recurrence. For the Maximum Subarray Sum problem, removing repeated computation takes the naive algorithm down to , and divide and conquer is introduced as the next design idea.
Learning objectives. After this week you should be able to:
- Describe the unit-cost RAM model and explain why model runtime and real runtime differ only by a constant factor.
- State the course’s definition of precisely, including the role of the domain and the codomain .
- Prove or disprove with an explicit constant , with the quotient criterion, or with limits and l’Hôpital.
- Simplify O-expressions: drop constants and lower-order terms, and ignore logarithm bases.
- Explain the “abuse of notation” , and what (“same order”) expresses.
- Derive Karatsuba’s identity, set up the recurrence , solve it by telescoping, and convert to .
- Define the Maximum Subarray Sum problem, analyse the naive algorithm with matching upper and lower bounds (), and give the improved algorithm.
- Turn nested loops into sums, and check index ranges with the “plug in the boundary” trick.
- Name the three cases of the divide-and-conquer approach to maximum subarray sum.
2. Core Concepts & Formal Definitions
2.1 The problem: what is “runtime”?
The runtime of an implemented algorithm depends on:
- the input (Eingabe): different inputs of the same size can take different time;
- the computer: speeds have changed enormously over the last 40+ years;
- the implementation: programming language (Python, C, Rust), compiler, and how cleverly it is written.
Yet results from algorithm analysis stay valid for decades. That needs an abstraction (Abstraktion) that satisfies two conditions:
- it removes machine and implementation details, and
- it still says something informative (“algorithm A is good, B is bad” would be too coarse).
The two ingredients are (A) the computation model (Berechnungsmodell), the unit-cost RAM model, and (B) asymptotic runtime analysis (asymptotische Laufzeitanalyse).
2.2 The unit-cost random-access model
Definition (Unit-cost random-access model / Unit-Cost-RAM-Modell)
A computer consists of a memory (Speicher) and a processor (Prozessor).
- Memory: a linear list of memory cells (Speicherzellen). Each cell is either empty or contains a number.
- Random access (beliebiger Zugriff): the processor can access any cell, and every access costs the same.
- Processor: executes elementary operations (elementare Operationen):
- reading and writing data (memory access),
- arithmetic: ,
- comparisons: ,
- and some more.
- Unit cost: every elementary operation costs 1.
- Runtime in the model (Laufzeit) := the number of elementary operations executed.
Real machines are more complicated (memory hierarchy, caches). According to the lecture this “changes nothing essential” for this course’s analyses.
Key observation (model vs. reality)
Model runtime (a count such as ) and measured program runtime (seconds) differ essentially by a constant factor. Each real operation takes between some minimum and some maximum time, e.g. 1–3 ns for an addition. Then
Faster computers only change this constant. The growth of the operation count never changes. (Quantum computers are explicitly excluded.)
Principle (universal runtime analysis)
- Count elementary operations in the model.
- Ignore constant factors: and operations are “the same”.
- Consider only growth, i.e. the fastest-growing term.
Examples: → only matters (quadratic). → only matters (linear).
Abbreviations Püschel uses on the board: Ops = operations, Algo = algorithm, Mult = multiplication, Bsp = Beispiel (example).
2.3 O-notation
Definition (O-notation, course version)
Let be the set of possible input sizes (mögliche Eingabegrößen), typically . Let be the strictly positive reals (). For define
Equivalent formulations:
In words: is the set of all functions that grow at most quadratically.
Remarks on the definition:
- is a set of functions. Grouping all functions with at most the same growth into one set is exactly what produces the abstraction.
- The constant is existentially quantified. That is how constant factors disappear: they get absorbed into .
- Why instead of ? Some functions are not defined, or not positive, at small , so we let the domain start later.
- is negative for and at . Choose .
- : at it is (undefined), at it is . Start at .
- In star search (week 1) the input sizes started at .
- The starting point is irrelevant for asymptotics. Only growth for large matters. If the beginning is a problem, start later.
- Other courses and books use variants, e.g. "". Püschel says these are essentially all equivalent. Here is built into the domain .
Definition (Abuse of notation / Missbrauch der Notation), Lecture 3
Instead of the course often writes
Strictly, "" between a function and a set is undefined. It is a convenient, intuitive convention (“by abuse of notation”), and mathematicians do it too. Many textbooks write instead.
Preview: ("same order"), formally introduced on the next exercise sheet
If both and , then has exactly the growth of :
We say and have the same order (gleiche Ordnung). Example: and give .
2.4 Tools for working with O
Lemma (constant factors)
For every constant : .
Proof sketch: if , then ; conversely, if , then . (Not proved in the lecture.)
Lemma (limit criterion), connecting O-notation to exercise sheets 0/1
Let .
- If , then grows asymptotically faster than , and .
- If (a finite limit exists), then .
Exam Trap: the limit criterion is sufficient, not necessary
The limit does not have to exist for . Example: and . Then has no limit, but it is bounded by , so with . If the limit does not exist, go back to the definition (show is bounded).
Lemma (l'Hôpital's rule, school version)
If (or both ), and are differentiable with for large , then
provided the right-hand limit exists. To differentiate, treat as a real variable .
Lemma (logarithm bases are irrelevant)
For bases :
So logarithms to different bases differ only by the constant factor , which gives . From now on we write only , with no base.
⚠ Transcript garble: the formula was transcribed as "". That has the wrong base in the second factor. The correct factor is , as above.
Lemma (useful power identity, used for Karatsuba)
For , :
Proof: take of both sides. Left: . Right: . These are equal, and is injective.
2.5 O-notation for simplification
In practice O-notation is used to simplify. One never writes the left-hand forms below:
| Never write | Write instead | Reason |
|---|---|---|
| drop the constant and the slower term | ||
| and grow slower than | ||
| the base only contributes a constant | ||
| dominant term only |
These are equal as sets, which is why the simplified form is allowed.
The most common classes in this course:
Between them sit e.g. (between and ). Note that contains , , : everything that grows at most quadratically.
Why logarithms appear so often
Many algorithms repeatedly halve the problem. Halving until only 1 is left takes about steps, so logarithms show up in many cost analyses.
2.6 Integer multiplication
Problem (multiplication of integers / Multiplikation ganzer Zahlen)
Given: two -digit integers. Find: their product.
Elementary operation: a digit multiplication (Ziffernmultiplikation), i.e. one single-digit × single-digit product. Additions and shifts by powers of 10 are not counted here.
Motivation: hardware multiplies only integers of bounded size. Arbitrarily long integers need an algorithm.
2.7 Maximum Subarray Sum
Problem (Maximum Subarray Sum / maximale Teilsumme)
Given: (positive and negative).
Subarray sums (Teilsummen): for ,
(; for the sum is the single number .)
Find: the maximum subarray sum
The is the empty subarray: if all , the best action is to do nothing, so .
Elementary operation: addition.
Motivation (stock prices / Aktienkurs): is the daily change of a share’s price. With a time machine, which buy and sell days maximise profit? Buying at the start of day and selling at the end of day gives profit . With 8 numbers you can solve it by inspection. In the lecture the optimum was 29, and the audience needed several attempts: 7, 23, 28, then extending the holding period gave 29. With numbers, inspection is hopeless. One heuristic from the lecture: buying just before a negative change never makes sense.
Definition (Pseudocode)
Pseudocode uses programming constructs (loops, assignments) without being a real programming language. Its exact form can vary.
Definition (Divide and conquer / Teile und herrsche)
A recursive design principle (Entwurfsprinzip):
- Divide: split the problem into subproblems (often two halves).
- Conquer: solve the subproblems recursively.
- Combine: assemble the overall solution from the partial solutions.
This only works if the subproblem solutions are related to the overall solution. It can always be tried as an approach; sometimes it works, sometimes not.
3. Step-by-Step Derivations & Mathematical Proofs
3.1 Example A: vs.
Let and on .
- ? Yes. Choose : for all . (Any works.)
- ? Yes. Choose : for all .
So , an instance of the constant-factor lemma.
⚠ Discrepancy: in the recording the constant for "" was given as “ein Viertel” (). That is wrong: is false. The correct choice is (or larger). is the smallest valid constant for the other direction, , which is probably where the mix-up came from.
3.2 Example B: is ?
No. Quotient criterion:
The quotient is unbounded, so there is no constant with for all . The small constant does not help, because constants never beat growth.
⚠ Transcript: the quotient was first written incorrectly (”… nein, falsch”) and corrected to .
Exam Trap: wrong argument from a common superset
A student argued “both are in , so one is in O of the other”. Wrong. Being in a common larger class says nothing about mutual containment. Every polynomial lies in , but that does not make all polynomials of each other. Also: but . ” grows not faster than ” does not mean ” grows faster than ”; they may grow equally fast.
3.3 Example C: for every
Even for tiny (e.g. ), the logarithm is eventually dominated. Both numerator and denominator tend to , so l’Hôpital applies:
where the last step uses . The limit is finite, so by the limit criterion . Since , the same holds for every with .
⚠ Transcript: the derivative of was transcribed as “a hoch n minus 1”. It is .
Why not substitute ? A student suggested . Püschel cautioned that such substitutions “can cause problems” with O-notation, because the domain changes from integers to the values . The direct l’Hôpital route is cleaner.
3.4 Example D: polynomials vs. exponentials (⚠ reconstruction)
The fragment after the break (“nochmal ableiten … … also gilt. Allgemein …”) fits the standard example "" (or ), shown by applying l’Hôpital three times:
General statement: for every constant and every . Apply l’Hôpital times: each step lowers the power by one, while keeps its form. Every polynomial grows slower than every exponential.
3.5 Karatsuba’s identity
School method on . Name the digits , (first number) and , (second number):
- ,
- , shifted by one position,
- , shifted by one position,
- , shifted by two positions.
Sum: . 4 digit multiplications. In general, two -digit numbers need digit multiplications.
What the school method computes. The numbers are and , and the shifts are the powers of 10:
Karatsuba’s version:
Only 3 distinct multiplications occur: , , . Each of and is computed once and written twice. Subtractions are cheap and not counted.
Proof that the two agree (Püschel: “10th-grade school mathematics”). Expand the middle product:
So the bracket multiplied by in (Karatsuba) is
The cancels against , and against . Hence (Karatsuba) (School).
Check on the example: , , :
Three multiplications instead of four.
3.6 Generalisation to digits
The cancellation does not depend on the number . It works with any base, in particular . Let be -digit numbers ( even). Split each in the middle:
where are the left (high) halves and the right (low) halves, each with digits. (Just like .) Then
The same cancellations happen as before: against , and against .
Key algorithmic consequence
Two -digit numbers can be multiplied with three multiplications of -digit numbers, namely , , , plus additions, subtractions and shifts (multiplying by just appends zeros). Each of the three products is again computed recursively in the same way. This is divide and conquer.
Details:
- Odd : pad with a leading zero. This does not change the analysis.
- and can be negative, with absolute value . They are still (signed) -digit numbers. The lecture did not discuss signs; an implementation handles them separately.
- Additions are not counted in the lecture’s analysis, where only digit multiplications matter. Each level also does digit additions. One can show this does not change the final bound, but that was not part of the lecture.
3.7 Analysis of Karatsuba: recurrence, telescoping, closed form
Simplifying assumption: , so we can keep halving down to 1 digit. Otherwise pad with zeros up to the next power of two, which changes nothing asymptotically. The course often makes such assumptions: edge cases matter for a correct implementation but not for understanding the analysis.
Let be the number of digit multiplications Karatsuba uses for two -digit numbers.
- Base case: two 1-digit numbers need one digit multiplication, so .
- Recurrence: three recursive multiplications of -digit numbers:
Telescoping (substitute the recurrence into itself):
Pattern: denominator goes with factor . We reach the base case when , i.e. :
Proof by induction (the guess is only a conjecture until proved). Claim: for all .
- IA (): . ✓
- IS (): . ✓
Expressing it in . With and the power identity :
Comparison for :
| Method | Digit multiplications | |
|---|---|---|
| School method | ||
| Karatsuba |
There is no bad constant in front, so the algorithm is also fast in practice. It is .
Why 3 instead of 4 matters so much
Naive divide and conquer with the school formula needs 4 half-size products: gives , so no gain at all. Saving one multiplication per level compounds over levels: . See Self-Assessment Q4.
History (from the lecture). Until about 1960, was believed optimal. At a seminar, the famous mathematician Kolmogorov presented ideas for proving this lower bound. A 23-year-old student in the audience, Karatsuba, sent him a faster method about three weeks later, and Kolmogorov was “shocked”. Kolmogorov wrote up the paper himself and submitted it with Karatsuba as author. It appeared in 1962; Karatsuba learned he had a publication only when it came out. (Background beyond the lecture: the 1962 paper lists A. Karatsuba and Yu. Ofman as authors.)
Geht es besser? Yes. Once people saw that improvement was possible, they paid attention to the problem. There are algorithms with (with sizable constants), and with , whose constants are so enormous that they are not practically relevant. (Names, not given in the lecture: Schönhage–Strassen, 1971; Harvey–van der Hoeven, 2019.)
3.8 Maximum Subarray Sum: Algorithm 1 (naive, try everything)
Idea: compute all and remember the best. There is no algorithmic idea in it: just try everything. “Try everything” is often an algorithm, and often not the best one.
MaxSubarray1(a_1, ..., a_n):
best := 0 // empty subarray
for i := 1 to n: // all start points
for j := i to n: // all end points (end >= start)
S := a_i + a_{i+1} + ... + a_j // computed from scratch
if S > best: best := S
return bestUnrolled inner loop for a fixed :
Off-by-one check ("plug in the boundary")
Is the last count , or ? Plug in : then is a single number, so additions. Only gives at , so is correct.
Cost for a fixed :
(Gauss’s formula for the first natural numbers: middle-of-the-night knowledge. “If you have to ask an AI tool for this, something has gone wrong.”)
Sandwich bounds to make the summation easy. We want squares:
Left: we decreased the factor to . Right: we increased to . Estimating early is legitimate because the final O-statement is a bound anyway. But do not overdo it: bounding by would be too crude.
Upper bound. Let be the total number of additions. Loops become sums (“for to ” becomes ):
Write the sum out: gives , gives , …, gives . So it is the sum of the first squares (formula from the exercise sheet):
This is clearly cubic, so directly. In slow motion: and for , so
Is the upper bound tight? is also true but useless (“too generous”). Maybe the true growth is only quadratic and the estimate was sloppy? To rule that out we need a lower bound.
Lower bound:
This differs from the upper bound by exactly the term (times ). With the formula for :
Use (for ) and (for ):
Hence , i.e. .
⚠ Transcript garble: the second estimate was transcribed as ” minus 1 halb ist auch größer gleich 1 halbe”. The intended estimate is .
Conclusion:
The naive algorithm is exactly cubic, no better. (Exact value, for checking: ; see Self-Assessment Q5.)
Practical meaning: gives additions, about 0.1 s on a smartphone. : “Ende der Fahnenstange”, no result in reasonable time.
Two practical tips from the lecture
- Loops become sums. Nested loops become nested sums; then evaluate them.
- When stuck on a sum, write it out. The pattern (e.g. “sum of the first squares”) becomes visible. With practice you can manipulate sums directly.
Exam Trap: which bound for O?
For an O-statement (worst-case upper bound) use the upper estimate. Lower bounds alone are trivially easy and useless (“runtime ”). Lower bounds matter only to show that an upper bound is tight (giving ).
3.9 Maximum Subarray Sum: Algorithm 2 (no repeated computation)
Observation (student): computes , and computes again. The same addition is done multiple times.
Idea: no repeated computation (keine Mehrfachberechnungen). Each sum extends the previous one by one element:
MaxSubarray2(a_1, ..., a_n):
best := 0
for i := 1 to n:
S := a_i // S_{i,i}: 0 additions
if S > best: best := S
for j := i+1 to n:
S := S + a_j // S_{i,j} = S_{i,j-1} + a_j: 1 addition
if S > best: best := S
return bestOps per : , i.e. additions in total (boundary check: gives ✓).
We saved a whole polynomial order: .
Memory (Speicher), a student question
“Don’t we now have to store all the values?” No. One variable is overwritten in each step, plus the best value so far, so the extra memory is . In general the remark is valid: besides operations, algorithms are also judged by memory usage and data movement. These are sometimes analysed, but rarely in this course.
Püschel’s comment: Algorithm 2 needs no algorithms course; a bit of thinking suffices. There is no real design principle behind it. Since quadratic growth is still too slow for many practical problems, we ask again: Geht es besser?
3.10 Maximum Subarray Sum: divide and conquer
Covered in the lecture. Split into a left half ( elements) and a right half ( elements). The optimal subarray falls into exactly one of three cases:
- Case 1, entirely left: the recursive solution on the left half gives the answer.
- Case 2, entirely right: the recursive solution on the right half gives the answer.
- Case 3, across the middle (“über die Mitte”): the “unpleasant” case. Solving left and right separately does not find it.
If only cases 1 and 2 existed, we would solve both halves and take the better one. Case 3 needs extra thought.
⚠ The recording ends here. Everything below is a reconstruction of the standard continuation, not lecture content. Compare with the handwritten notes.
Handling case 3 (standard). A subarray crossing the middle is a suffix of the left half plus a prefix of the right half, and the two parts can be optimised independently:
Both maxima can be computed incrementally, as in Algorithm 2 (extend by one element per step), with about additions each, so about in total.
MaxSubarrayDC(a_l, ..., a_r): // reconstruction
if l == r: return max(0, a_l)
m := floor((l + r) / 2)
L := MaxSubarrayDC(a_l, ..., a_m) // Case 1
R := MaxSubarrayDC(a_{m+1}, ..., a_r) // Case 2
// Case 3: best suffix of left half + best prefix of right half
S := 0; bestSuf := 0
for i := m downto l: S := S + a_i; bestSuf := max(bestSuf, S)
S := 0; bestPre := 0
for j := m+1 to r: S := S + a_j; bestPre := max(bestPre, S)
return max(L, R, bestSuf + bestPre)Allowing empty suffixes and prefixes (value 0) is consistent with .
Analysis (reconstruction). Let and = number of additions. , and . Telescoping:
Induction check of : IA: ✓. IS: ✓.
So the divide-and-conquer algorithm runs in , better than .
4. Worked Examples & Applications
Example: proving from the definition
Show on .
We need with for all . Since : . So works. (Note for , so maps into as required.)
Example: choosing the domain
takes the values at , which are not in . Take . Then , and e.g. with .
Example: Maximum Subarray Sum by hand
.
- Algorithm 2, row : , , , , . Best in this row: 6.
- Other rows never exceed 6 (e.g. row : ).
- Answer: .
- Divide and conquer view: halves and , split after . Best left: . Best right: . Crossing: best suffix of the left half (via ), best prefix of the right half , total . The optimum is in case 3: neither half alone finds it.
Example: all negative
: every , so (empty subarray: don’t buy).
Exam Trap: constants do not rescue growth
and . Constant factors are always irrelevant for membership in O-classes; only the growth rate matters.
Exam Trap: exponents inside exponentials are not constants
holds for constant factors. It does not hold for changes in an exponent: , since . But . Likewise, a log base is a constant factor, so it is irrelevant, but and are very different.
Exam Trap: l'Hôpital conditions
Only apply l’Hôpital to or (with differentiability). Check this every time you apply it.
Exam Trap: "Algorithm 2 needs n² memory"
It doesn’t: one running sum and one best value suffice. Distinguish operation count from memory.
5. Intuition & Conceptual Bridges
Intuition: O as "at most this growth class"
Think of as a bucket: everything that, up to a constant, stays below forever. Constants are “machine speed” (irrelevant), lower-order terms are “noise” (irrelevant for large ), and growth is “the algorithm” (decisive). On any computer of the last 50 years, a algorithm eventually beats a algorithm, for large enough .
Intuition: why Karatsuba works
The school method needs the cross term , which seems to need two products. Karatsuba gets it indirectly: , and are needed anyway. One product plus “free” additions replace one multiplication. Done recursively, the saving multiplies over levels: instead of .
Intuition: three levels of algorithm improvement (maximum subarray sum)
- Try everything (Algorithm 1): correct but wasteful, .
- Remove redundancy (Algorithm 2): reuse previous sums, . “Common sense”, no design principle.
- Design principle (divide and conquer): split the problem, handle the interaction case (crossing the middle) cleverly, (reconstructed).
Each step asks “Geht es besser?”, the course’s central question.
Connections:
- Week 1: elementary operations, worst-case analysis, recurrences, telescoping plus induction. Karatsuba’s is the first recurrence where the argument halves instead of decreasing by 1, which gives powers and logarithms instead of sums. Week 1 already used the “linear vs. quadratic” language (star search vs. ); now it is formal.
- Exercise sheets 0/1: limits, “grows faster than”, l’Hôpital, . These are exactly the tools for O-notation.
- Forward: (and probably ) formally on the next exercise sheet. Divide-and-conquer recurrences of the form will appear repeatedly (e.g. sorting such as merge sort). Whether maximum subarray sum can be solved even faster than is the natural next “Geht es besser?” (probably the next lecture).
6. Summary & Self-Assessment Questions
Cheat Table
| Topic | Key fact |
|---|---|
| RAM model | linear memory of cells, random access at equal cost, unit cost per elementary op |
| Model vs. reality | differ by a constant factor; machines change only the constant |
| Equivalent | bounded, i.e. grows asymptotically not faster than |
| Limit criterion | means ; finite limit means |
| Notation | means (abuse of notation) |
| and : same order | |
| Constants | for |
| Log bases | , so write just |
| Log vs. power | for every |
| Power vs. exponential | for every and |
| Power identity | |
| Sum of squares | |
| School multiplication | digit multiplications |
| Karatsuba identity | |
| Karatsuba cost | , , so |
| Max subarray, Algo 1 | all from scratch: , with |
| Max subarray, Algo 2 | : , extra memory |
| Divide and conquer | cases: left, right, crossing (suffix + prefix); (reconstructed) |
| Off-by-one check | plug in the boundary (e.g. must give 0 additions) |
Self-Assessment Questions
Question 1. Using only the definition, prove on . Give an explicit constant . Then decide, with justification: (a) ? (b) ? (c) ?
Solution to Question 1
Main part. For : and . Hence
so works. (The function is positive, so it maps into .)(a) Yes. by l’Hôpital: (here ). The limit is finite, so .
(b) Yes. with .
(c) No. , so the quotient is unbounded. A change in the exponent is not a constant factor.
Question 2. Compute with Karatsuba’s method, using exactly three digit multiplications. Show each intermediate value and verify the result.
Solution to Question 2
Digits: , (for 46); , (for 73).
Combine: :
Check: ✓.
Note that and are negative here; their product is still a single small multiplication.
Question 3. Solve , for by telescoping, prove the result by induction, and express it as a power of . Why does hold but ?
Solution to Question 3
Telescoping: . With : .
Induction on , claim : IA: . IS: .
As a power of : , so , using .
Comparison: , so the quotient is bounded and . Conversely , so . Karatsuba is asymptotically strictly better than the school method.
Question 4. Suppose you split -digit numbers in half but use the school identity recursively, with four products of -digit numbers. Set up and solve the recurrence. What does this show about Karatsuba’s trick?
Solution to Question 4
Recurrence: , . Telescoping: .
So divide and conquer alone gains nothing: it reproduces the school method’s . The entire improvement comes from reducing the number of subproblems from 4 to 3. In general, with gives . The exponent depends on the number of subproblems , so saving even one subproblem changes the polynomial order.
Question 5. For Algorithm 1 of the Maximum Subarray Sum, compute the exact number of additions in closed form and confirm it lies between and (e.g. for ). Then state the number of additions of Algorithm 2 for and explain where the savings come from.
Solution to Question 5
Substitute (as runs from to , runs from down to ):
Factor out :Check : . Direct count: : ; : ; : ; : . Total ✓.
Bounds: ✓. Asymptotically , which indeed lies between and .Algorithm 2, : additions (rows: ). The saving: Algorithm 1 recomputes every prefix from scratch for each , costing additions. Algorithm 2 reuses and adds only , costing 1 addition. Per start point the cost drops from to , and overall from to .