Memoization arithmetic and stack costs 2026-10-13
Under constant-cost lookup and integer addition, Memoized Fibonacci evaluation has time complexity in Big O notation, retaining values. A hash table needs its own lookup-cost assumptions; an array indexed by avoids hash collisions in this example. Memoization removes repeated bodies, but also pays for keys, lookups and retained answers. A workload without reuse can pay those costs without saving evaluations.
The call stack remains. Left-first recursion descends through arguments before returning, giving simultaneously active frames for . Therefore the auxiliary space complexity includes frames as well as table entries in the constant-size-value model. An iterative bottom-up dynamic programming calculation removes these recursive frames; retaining only the two previous Fibonacci numbers suffices when only the final value is wanted, but discards the table useful for later requests.
Exact Fibonacci numbers do not remain constant-size values. For , the recurrence relation gives , so the representation of as a binary number has order bits. With ordinary addition costing order bit operations on such operands, the additions cost order bit operations in total. Retaining all values also requires order bits of value storage, before keys and frame overhead. The linear bound counts additions under its stated cost model; it is not a linear bound on exact integer arithmetic in bits.[ref]
Lecture 15: Recursive Algorithms (6.006 Spring 2020) by Massachusetts Institute of Technology, 6.006 course staff. MIT 6.006 Spring 2020, Lecture 15: Recursive Algorithms, printed p. 3, final three bullets: growing Fibonacci bit lengths and addition cost
Interpret as the bits of a binary number, with most significant. Construct a propositional formula saying that this number is strictly less than . This gives a quadratic-size formula with prescribed model count.
For , write . For each with , define the conjunctionThe empty prefix for is omitted. Let . A Boolean valuation satisfies exactly when its first difference from the binary representation of is at position , changing a one of to a zero. All later bits are unrestricted. Hence these cases are disjoint and cover exactly the numbers .
Alternatively, counting the disjoint cases directly givesEach has length , including its logical connectives and parentheses; the total length is at most a constant multiple of . The endpoints are and . If constants are unavailable and , use and instead. Assignments are counted over all specified variables, including any absent from the formula. For , the constants describe the two possible counts, zero and one. Thus the construction covers , including the endpoint zero despite the source's word “positive”.
A quadratic-size formula with prescribed model count accepts the eleven four-bit numbers below : three disjoint prefix cases contribute , and satisfying assignments
. Details. Repeated integer division by two generates the binary digits from least significant to most significant. Reverse the accumulated characters once, and treat zero separately.
def binaryCon(n: Int): String = {
require(n >= 0, "n must be nonnegative")
if (n == 0) return "0"
var remaining = n
val digits = new StringBuilder
while (remaining > 0) {
digits.append(if (remaining % 2 == 0) '0' else '1')
remaining /= 2
}
digits.reverse.toString
}Zero produces
"0"; positive inputs produce a binary number without leading zeros. No library routine performs the number-to-base conversion. Appending to the builder and reversing once gives linear work in the number of binary digits and uses that much output storage.For each , a propositional formula over specified variables can have exactly satisfying assignments and length . For , interpret a Boolean valuation as the binary number and test whether it is less than .
For every position with , use a conjunction asserting that all earlier bits equal and , leaving later bits unrestricted. Take the disjunction of these terms. Each satisfying assignment has a unique first differing position, so the terms are disjoint, and their counts sum to . Their combined length is . Use logical falsity and logical truth at the two endpoints. The count is over all variables, including those absent from an individual term or from the whole formula.
Typical-set indexing example 2026-10-14
The typical sequence theorem turns a probability concentration into a coding construction. Assign one binary number index to each weakly typical sequence, plus a reserved index for every word outside the set. The decoder recovers every typical word exactly; the reserved index has one predetermined output. The block code usesbits and has reconstruction-error probability at most .
For this example and , needs 34 bits but permits error up to about . At , 570 bits suffice and the error bound is about . These are existence calculations for an explicitly enumerated collection, rather than claims about an efficient practical encoder. The reduction comes from protecting the whole high-probability collection, rather than just its single most likely member.
