A square matrix is an invertible matrix exactly when its determinant is nonzero. The preceding recurrence relation therefore gives
Let denote the given tridiagonal matrix and put , including for the empty determinant. The starting values areFor , apply the following elementary row operations in the indicated order, always using the updated rows:The first three rows now beginwith the fourth column omitted if . When , also use . The resulting block upper triangular matrix has a upper triangular matrix with diagonal entries all one in its top left corner, and in its bottom right corner. All elementary row operations preserved the determinant except the single row interchange. ThereforeApplying this recurrence relation to the three starting values proves by mathematical induction thatEquivalently, the sequence is periodic with period six, with values starting at . A compact closed form is .
Divide-and-conquer algorithms suit problems with largely independent, balanced subproblems and an inexpensive combination step. In merge sort, the two halves are independently sorted and merged in linear time. Its recurrence relation is , giving time complexity.
Dynamic programming suits overlapping subproblems with a compact state description. For the coin change problem, let be the minimum number of coins needed to make amount . With positive denominations containing ,Every optimal nonempty answer has a last coin and an optimal answer for ; otherwise replacing the remainder improves it. Filling takes time complexity and space complexity. Repeated amounts are computed just once. This bound is in the numeric amount , not its binary input length.
A greedy algorithm suits problems where one can prove a greedy-choice property. For unweighted interval scheduling, choose an interval with earliest finishing time, discard overlapping intervals, and repeat. Among optimal schedules, replace the first interval by the earliest-finishing one. The replacement finishes no later, so every later interval remains feasible. Applying the same argument to the remaining intervals proves optimality. After sorting by finish time, a single scan suffices.
These examples separate the relevant structural reasons: independent halves, repeated amount states, and an exchange argument certifying each irreversible choice.
An Oberon recursive procedure can implement the defining recurrence relation directly. Its precondition is ; arithmetic is assumed to remain in the representable integer range.
PROCEDURE Fib(n: INTEGER): INTEGER;
VAR result: INTEGER;
BEGIN
IF n <= 2 THEN
result := 1
ELSE
result := Fib(n-1) + Fib(n-2)
END;
RETURN result
END Fib;Correctness follows by strong induction: the two base inputs give , and for the returned sum is . On each recursive branch the positive integer argument strictly decreases, while recursion stops at or . The well-ordering principle therefore proves algorithm termination.The method repeats many subproblems and has exponential time complexity; termination alone does not make it efficient.
First consider powers of four, with a fixed finite base value. For a mathematical induction hypothesis , the recurrence relation givesprovided and also covers the base value.
The allowed integer rounding needs a little more care. Suppose the recurrence relation is applied above fixed base cases, as usual; applying with a ceiling would not define a positive sequence. For either rounding write or . For ,Choose large enough to bound all finitely many positive-index base values below . By strong induction,This argument starts at , so the floor convention's index zero, if used in an earlier base calculation, is absorbed into those fixed initial values. Thus, for either convention with a well-defined finite base,
The printed fractional arguments require a size convention. To make the recurrence relation precise on positive integers, take a bounded base case and use , for . This integer rounding in a divide-and-conquer recurrence gives . The unrounded calculation is the special split fraction .
Prove by strong induction. Put , choose , and choose . The base case follows. The entropy potential for a divide-and-conquer recurrence givesThe last step uses . This closes the inductive hypothesis and proves in Big O notation.
The initial values of the two sequences agree: and . For , use the first-order recurrence relation at and :Therefore satisfies exactly the same derangement recurrence as . By strong induction, equality of the preceding two terms implies equality of the next term. ConsequentlyThe first-order recurrence relation therefore also counts derangements.
We prove the stronger bound for every by strong induction. The initial case is . For , put . Then , so the induction hypothesis and the defining recurrence relation giveThusThe recurrence relation must be read as applying for ; applying it at would invoke outside the printed domain. No value of is needed.
Multiplying the recurrence relation by removes the average:For , subtract the same identity at :Rearranging gives . This also holds at , because the original recurrence relation gives and . Summing the differences therefore yieldsHere is a harmonic number. Since , we have for , also establishing in big theta notation.
Unroll the recurrence relation down to its initial condition:ThusIndeed , so the sharper growth classification is in big theta notation.
Measure the work of producing the entire output list, with constant-cost labels. Count height in levels, so a leaf has height one and . A perfect ternary tree with levels hasvertices. This is the finite geometric series formula, used without a new proof.
The three recursive calls cost . Ordinary
concat = foldr (++) [] copies each immediate child result once, and each result has elements. Consequently the nonrecursive work is , givingUnroll this recurrence relation. At level , the cost is , and there are internal levels, followed by leaves. ThereforeFor this is conventionally written ; in terms of total size it is . The extra height factor comes from copying labels at successive ancestors, even under lazy evaluation when the whole output is demanded. Merely producing its first constructor is a different cost question. If height instead counts edges, the source's height means levels; shifting the index by one leaves the boxed asymptotic bound unchanged. Part (c)'s suffix-passing implementation avoids this repeated copying.For one element, return it as both extrema without a comparison. Otherwise compare consecutive pairs once, put each smaller element in a candidate array and each larger element in a candidate array . If one element is unpaired, put it in both candidate arrays. This simultaneous minimum and maximum construction computes the minimum of and maximum of by balanced divide-and-conquer algorithms: split the candidate array, recursively find the desired extremum in each half, and compare the two returned values. These extremum routines use one comparison per merge and therefore comparisons on candidates.
Every element excluded from is at least its paired element, so a global minimum remains in ; likewise a global maximum remains in . The recursive extremum routines are correct by structural induction. For even , there are pair comparisons and two searches on candidates, givingFor odd , there are pair comparisons and two searches on candidates, givingTogether with , both cases giveFor powers of two, the equivalent direct divide-and-conquer algorithm returns the ordered pair of extrema for each half, then combines the two minima with one comparison and the two maxima with one comparison. Its base cases must include , rather than performing two unnecessary comparisons on a pair. The recurrence relation is for , whence . Arbitrary near-equal splitting without the initial pairing can exceed the desired comparison bound for other values of ; the pairing construction above handles every positive size.
Put . With a nonnegative toll bounded by , the Master theorem gives the upper boundsIf the base cost is and the toll is , these become the usual tight bounds. The printed toll by itself does not imply those lower bounds; for example, the toll could vanish.
For the two requested proofs, let as permitted. Expanding the recurrence relation through levels givesWhen , the ratio is one. The sum has terms, so . With matching positive lower bounds on each level's work, the same expansion gives .
When , the ratio is strictly below one. The geometric series is at most , so the internal work is ; the leaf term is also . A root toll supplies the matching lower bound in the tight version. This proves both requested cases.
There is a small termination qualification in the printed generality: if , the literal base case only at may leave
ceil(n/b) = n at a small integer, for example . The standard rounded Master theorem assumes a sufficiently large fixed base-case cutoff so that recursive sizes decrease. The allowed unrounded powers-of- proof above does not use that problematic rounded step. Also, a literal number of recursive calls is integral, though the algebraic recurrence expansion remains meaningful for positive real .A divide-and-conquer algorithm handles small base cases directly, divides a larger instance into smaller instances of the same problem, solves them recursively, and combines their answers. The savings come from the number and sizes of recursive calls and the combination cost.
For Karatsuba multiplication, split the -bit inputs as , , where and . Compute only three recursive products:Then the Karatsuba three-product identity givesThe absolute differences have at most bits; multiply their magnitudes and restore the sign of . Additions, subtractions and shifts cost bit operations. With constant-size base cases, the recurrence relation is , giving by the Master theorem. The difference-product version avoids an extra carry bit in the recursive operands.
The derivative fixed-point equation is unsuitable as an executable definition: requesting its first coefficient asks for the second coefficient of the same stream, then the third, indefinitely. It is not productive. As an algebraic equation it is also missing the constant coefficient: every scalar multiple of the formal power series exponential, including zero, satisfies it.
expx :: Fractional a => [a]
expx = plus one (integral expx)The initial coefficient is available as
1 + 0; each subsequent coefficient needs only a previously determined coefficient. The recurrence relation is and , so . This proves both uniqueness of the formal solution and productivity of every finite coefficient list prefix.The derivative relations and initial values give , , and . Integrating from zero yields and . Thus use mutually recursive lazy lists:
sinx, cosx :: Fractional a => [a]
sinx = integral cosx
cosx = minus one (integral sinx)Both heads are available immediately, and later coefficients depend on earlier coefficients of the other stream. The resulting formal power series are and . Their zero coefficients and alternating signs follow directly from the coupled recurrence relations, providing a coefficientwise proof without assumptions about analytic convergence.
Merge sort splits the array into two halves, recursively sorts both and merges their sorted outputs. During the merge algorithm, compare the first unconsumed entry of each half, emit the smaller and advance that half; append the remainder when one half ends. The emitted prefix is always sorted and contains exactly the already consumed entries, proving the merge step correct. Induction on input length proves the full sorting algorithm correct.
The recurrence relation is for powers of two, with constant base cost. In the Master theorem, and , matching the merge term. Hence . Floor/ceiling splits give the same bound for arbitrary ; conventional merging uses auxiliary space.
Each physical item may enter neither knapsack or exactly one of them. Let be the largest combined value using the first items with remaining capacity limits . Initialize and computeAn infeasible alternative is omitted. The three alternatives classify the placement of item exhaustively. Every reference uses row , ensuring that no item is placed in both knapsacks. Removing item from an optimum and applying optimal substructure proves the recurrence relation.
The optimum is , with time , conventionally for positive capacities. Two successive layers require space; keep predecessor decisions or recompute them if the actual allocations are wanted. The stipulated uniqueness of values and weights is unnecessary for correctness. The capacity-indexed algorithm is pseudopolynomial.
Use and for . Indeed,The initial value is , so the recurrence relation produces the specified factorial sequence.
Let , the golden ratio. Since , multiplication by gives . Adding this recurrence relation to the one for yieldsThus the extra exponential term changes the initial values, but not the linear recurrence relation.