Merge sort Created 2026-10-13 Updated 2026-10-18
Merge sort is a divide-and-conquer algorithm that sorts a finite array by splitting it into contiguous halves, sorting each half using recursion, and combining the two sorted arrays with the merge algorithm. An empty or one-entry array is returned immediately. For length , put the first entries on the left and the remaining on the right; the brackets are the floor function and ceiling function. Always choose the left head on equal keys to obtain stable sorting. This is the split, sort, combine structure taught in the MIT lecture notes.[ref]
Lecture 3: Insertion sort, merge sort. 6.006 Introduction to Algorithms, Fall 2011 by Massachusetts Institute of Technology, 6.006 course staff; MIT 6.006 (2011), lecture 3: merge sort
Take the concrete input arrayThe tags identify the entries originally at indices and , counting from zero. Both keys are ; the tags are never compared. Reading downward in the figure follows the splits, then the returned sorted arrays. Arrows show dependencies; the level layout groups independent calls rather than giving their chronological execution order.
The first two halves are and . Their pairs split into one-entry base cases. Applying the merge algorithm gives the following fully worked return levels; each number in the last column counts only comparisons between two available heads.
| Returning level | Resulting sorted arrays | Head comparisons |
|---|---|---|
| Pairs | , , , | |
| Halves | , | |
| Whole array |
In the left-half merge algorithm, the head pairs are , and ; it takes , then appends . In the final merge algorithm, the head pairs are , , , , , and . It takes , then appends . Thus this precise version makes head comparisons and, ignoring identity tags, returns .
The elegance of merge sort is that it creates exactly the structure its next step needs: two smaller sorted arrays make the larger ordering inexpensive. Once the whole array is sorted, equal keys are adjacent and binary search can serve repeated queries. Stable sorting also retains information that the keys alone do not express. If the left-half merge algorithm instead takes the right head on the tie, it returns ; the keys are sorted but stable sorting has failed.
For time complexity, assume each key comparison, entry access and entry copy has constant cost. The merge algorithm processes entries in time. In Big O notation, the resulting recurrence relation isFor , the balanced levels contain entries each and there are returning levels. Each costs , so the worst-case time complexity is . For arbitrary , there are at most returning levels, each processing at most entries, giving the same bound. The worst-case number of head comparisons is also . Here is the base-two logarithm. The MIT notes give this level-by-level analysis for merge sort.[ref]
https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/6d1ae5278d02bbecb5c4428928b24194_MIT6_006S20_lec3.pdf. MIT 6.006 (2020), lecture 3, page 5: merge sort analysis
The conventional array implementation uses a reusable buffer of entries for the merge algorithm, together with pending calls for recursion. Its auxiliary space complexity is therefore , beyond the original array. This bound describes that implementation. A linked list permits a merge algorithm that reconnects existing nodes; its storage accounting differs from copying array entries into a buffer.
For a short algorithm correctness outline, the empty and one-entry base cases are sorted. Assuming recursion correctly sorts both shorter halves, the merge algorithm returns all their entries in order. Equal keys within a half keep their relative order by the same argument applied to the smaller call; across halves, every left entry originally preceded every right entry, so taking left first preserves stable sorting. Both half-lengths decrease for , establishing termination.
Let and suppose the recurrence relation is defined with no zero iterates. An eventually constant sign would make satisfy on a tail. Thus , although positivity of requires throughout that tail. This contradiction proves infinitely many sign changes. The nonzero assumption matters because a zero iterate makes the next step undefined.
Newton iteration for a square root 2026-10-24
For and , the displayed recurrence relation stays positive and satisfiesAfter the first step, , so . The bounded monotone sequence theorem gives a limit of a sequence ; the inequality makes positive, and passage to the limit of a sequence in the recurrence relation gives . This proves existence of the positive square root without assuming it in the construction. Once is known, the exact error identity explains the eventual quadratic convergence.
North-east lattice path recurrence 2026-10-18
For positive integers , the north-east lattice path recurrence isThe boundaries have only straight north-east lattice paths. The origin counts the zero-step north-east lattice path once.[ref]
Discrete Mathematics: An Open Introduction (3rd edition) by Oscar Levin. §1.2, Lattice Paths: split by the final horizontal or vertical step
Proof outline. A north-east lattice path ending at has a final step either from or from . Deleting that step gives a shorter north-east lattice path; appending it reverses the operation. The two classes are disjoint and exhaust all possibilities, so the rule of sum adds their counts. At , the arrivals from contribute , while those from contribute : altogether .
Set if either integer coordinate is negative. Then the same recurrence relation applies on the nonnegative axes away from : one predecessor contributes one, and the other contributes zero. Initialize separately; applying the recurrence relation there would incorrectly give zero.
Computing the grid once in increasing order of is dynamic programming: every entry uses two earlier entries. If a specified point is forbidden, set its count to zero, then continue the same recurrence relation at allowed points. This counts north-east lattice paths avoiding the forbidden points, provided the origin and endpoint are allowed. The last-step argument remains valid because appending a step to an allowed endpoint cannot visit any new intermediate integer lattice point.
Optimal substructure 2026-10-14
Optimal substructure means that the relevant parts of an optimal solution solve their own subproblems optimally. For a 0-1 knapsack problem, removing a chosen item leaves an optimal selection among the other allowed items at the reduced capacity. For sequential mathematical optimization, this becomes the dynamic programming principle: after fixing the next decision and resulting dynamic programming state, use an optimal continuation. Optimal substructure justifies the recurrence relation; overlap between subproblems explains why storing a value function can save work.
Overlapping subproblems 2026-10-13
Overlapping subproblems occur when several parts of a calculation request the same smaller problem. Memoization can share its answer if the memoization key identifies that problem completely. For the Fibonacci numbers, both and require . In dynamic programming, the dynamic programming state plays the corresponding role of identifying a reusable continuation. Overlap explains potential savings; the recurrence relation and its base cases still need to be correct.
Pascal's rule Created 2026-10-13 Updated 2026-10-18
For an integer and any integer , Pascal's rule holds with the convention outside . The boundary values are , including . Initialize row zero separately: the recurrence relation does not require binomial coefficients with top index .[ref]
Discrete Mathematics: An Open Introduction (3rd edition) by Oscar Levin. §1.2, Recurrence relation for binomial coefficients and Pascal's Triangle: edge values and the two-parent rule
Proof by a marked element. Count the -element subsets of , marking the element as special. Those omitting are exactly the -element subsets of . From those containing , delete to obtain the -element subsets of that same smaller set; adjoining reverses this operation. The rule of sum adds these two disjoint counts. The proof includes and because the impossible class contributes zero.
For an original worked instance, choose three labels from and mark . Omitting it gives selections. Including it leaves two labels to choose from the other six, giving . Therefore . Under the bijection with north-east lattice paths to , membership of position seven says whether the final step is north: the marked-element split becomes the last-step split.
This makes Pascal's rule useful beyond an algebraic identity. A counting problem may have an obvious yes-or-no decision even when its factorial formula is obscure; splitting at that decision exposes a recurrence relation. When the smaller counts are shared between many cases, dynamic programming reuses them. The beauty of Pascal's triangle is that one local addition rule simultaneously organizes subsets, binary strings, north-east lattice paths, and the binomial theorem.
Past exam of the differential equations 2 course of the University of Oxford 2015 2 c Solution 2026-10-25
First classify nonzero polynomial solutions of the differential equation itself. If has degree and leading coefficient , the coefficient of is . Hence is necessary.
An analytic solution at zero belongs to the exponent-zero Frobenius branch. Its odd-power coefficients vanish, because and the recurrence relation preserves parity. For the even-power coefficients,All denominators are nonzero for . With , the coefficients through are nonzero when , the next coefficient vanishes, and every subsequent coefficient vanishes. This proves sufficiency as well as the restriction to even polynomial degree:For example, setting gives when , when , and when . A polynomial cannot instead begin with a positive integer power: its lowest power must have an indicial exponent, and the only integer indicial exponent is zero. This also proves that no odd-degree family was missed. The finite-series mechanism is a terminating Frobenius series.
If the additional endpoint conditions from part (b) are imposed on this part too, there is no nonzero polynomial solution: every nonzero polynomial just classified has . The displayed family and degree answer therefore concern the differential equation without those extra endpoint conditions.
Past exam of the differential equations 2 course of the University of Oxford 2017 3 a ii Solution 2026-10-31
Substitute a Frobenius series into the transformed equation. For , equating the coefficient of gives the recurrence relationAt the larger indicial root , the coefficient of is , so a Frobenius solution always exists. At the smaller indicial root , the first two equations areSince , the exceptional equation is consistent exactly whenThese are both admissible values, including the zero value; the singular wording of the question does not remove either. This is the undetermined coefficient at Frobenius resonance: at either value is free, whereas otherwise the second independent solution requires a Logarithmic Frobenius solution.
Explicit pairs demonstrate sufficiency and linear independence. In the variable one may takeBoth displayed have leading term , while . They therefore give independent Frobenius solutions with the two indicial exponents, and direct differentiation verifies the equation. The point is an apparent regular singular point in these two cases.
Past exam of the differential equations 2 course of the University of Oxford 2021 2 b Solution 2026-10-25
For the first Frobenius solution, take the larger indicial root and normalize the first coefficient to one:Substitution and comparison of the coefficient of giveEvery denominator is nonzero because .
For , the recurrence relation is , soFor , and all odd coefficients vanish; the even coefficients satisfy . HenceFor any positive integer , induction in the recurrence relation shows that only indices divisible by survive:The empty product for equals one. Successive terms in the power series factor have ratio of magnitudesThus the ratio test gives convergence for every finite ; a nonintegral still requires a chosen side of zero or a complex branch for the factor .
Past exam of the differential equations 2 course of the University of Oxford 2021 2 c Solution 2026-10-25
For a putative second Frobenius solution with the smaller indicial root , set , with and for . Its recurrence relation isThe Frobenius case classification concerns the gap between the indicial roots. In the course convention, Case IIIa is the obstructed recurrence requiring a Logarithmic Frobenius solution; Case IIIb permits two pure Frobenius series.
If and , this is Case I: no denominator vanishes. There are two linearly independent pure Frobenius solutions, withTheir different leading powers establish linear independence.
If , this is Case II, with a repeated indicial root. There is only one pure Frobenius series with a nonzero leading coefficient. To see the second solution's form, reduction of order givesHere , so the integrand is . ConsequentlyThe logarithm has a nonzero coefficient and cannot be removed by adding a multiple of .
If is a positive integer, the only potentially obstructed coefficient is . Below that index, unless divides . At the exceptional index the equation readsIf for some positive integer , all coefficients are nonzero because . The exceptional equation is inconsistent. This is Case IIIa, and the independent second solution has the formThe Frobenius resonance for an Euler equation with monomial potential explains why divisibility, rather than the integer gap alone, decides this outcome. For example, with , applying the original differential operator to gives . Cancellation of the coefficient of requires .
If does not divide , then ; this includes through the negative-index convention. The exceptional equation is , so is free. This is Case IIIb: set to select an independent pure Frobenius series starting with . Subsequent coefficients again follow the recurrence relation. Changing simply adds a multiple of , the undetermined coefficient at Frobenius resonance.
The complete answer is thereforeIn particular, for every positive integer gap gives Case IIIa. For , positive integer gives Case IIIa, while gives Case IIIb; the remaining positive give Case I. The condition matters: at the two Cauchy-Euler equation powers already give independent solutions whenever .
Past exam of the differential equations 2 course of the University of Oxford 2021 2 d Solution 2026-10-25
Normalize both leading coefficients to one. For the indicial root , the recurrence relation from part (b) givesRecognizing the Taylor series of the sine gives the first Frobenius solutionFor the smaller indicial root , . The equation at is ; choose the free coefficient to avoid adding the first Frobenius solution. The remaining coefficients areThus the Taylor series of the cosine givesTheir leading terms are and , as required for Case IIIb. A direct check uses : the differential equation becomes , so these two functions solve it on . Their Wronskian is , proving linear independence. The general solution is .
Past exam of the mathematical methods I course of the University of Oxford 2018 8 b Solution 2026-10-25
Substitute the power series and its termwise derivatives into the ordinary differential equation. The coefficient of , for , isThe bracket factors as , so the power-series solution of a differential equation satisfiesThe odd and even recurrence relations terminate: , , and , , . Thus the full solution is . The two polynomials have independent initial data at zero, and the leading coefficient never vanishes on the real axis, so every real solution of a differential equation for this equation is their linear combination on the entire real axis. The given initial data select , :
Past exam of the mathematics course of the University of Cambridge 2003 ib Paper 3 16B b Solution Created 2026-09-24 Updated 2026-10-14
Differentiating the Rodrigues representation directly gives the identityWe prove simultaneously by induction that for . It holds for , . Suppose it holds at . Differentiating the preceding identity and using the same identity at givesThe induction is complete. Substituting the derivative identity into the first formula proves the Hermite polynomial three-term recurrence relationThe initial step supplies the recurrence at without needing to define .
Be careful about the index: the probability density function already contains a factor , so . The recurrence relation at yields . Therefore linearity of expectation givesThus is an unbiased estimator.
The recurrence relation at gives . ConsequentlyBy variance additivity for independent random variables, the variance of their sample mean is
Rewrite the recurrence relation asSince and , a positive gives a positive . Mathematical induction therefore proves , and also shows that every division in the recurrence relation is defined.
The tail is a monotone sequence bounded below by zero. The bounded monotone sequence theorem therefore gives . Taking the limit of a sequence in yields , so . The reciprocal rule from part (a) permits passage to the limit of a sequence in the recurrence relation:Multiplication by givesThis proves existence of the positive square root without assuming that existence when constructing the sequence.
Write . Suppose, for a contradiction, that only finitely many sign changes occur. Since every , the sign is then constant for . Set on that tail. Multiplying the recurrence relation by this constant sign givesConsequently for , and by comparison with a geometric sequence. But positivity of requires at every step, which is incompatible with . Thus the negative-parameter square-root iteration changes sign infinitely often.
Only (ii) is necessarily true. Every real satisfies , so (ii) holds automatically. For a single counterexample to (i) and (iii), choose and . The recurrence relation then gives the nonzero periodic sequenceHere , disproving (i), and , disproving (iii). This counterexample satisfies the requirement that no iterate is zero.
