Skip to main content

Summary: Mathematical Background

Everything on one page, to review the appendix or to look up a formula.

Sums, logarithms and factorials​

From Sums, Logarithms and Factorials:

ResultFormula
Arithmetic series∑i=1ni=n(n+1)2∈Θ(n2)\sum_{i=1}^{n} i = \frac{n(n+1)}{2} \in \Theta(n^2)
Sums of powers∑i=1nik∈Θ(nk+1)\sum_{i=1}^{n} i^k \in \Theta(n^{k+1})
Geometric series, r>1r \gt 1Dominated by the last term
Geometric series, r<1r \lt 1Dominated by the first term
Harmonic numbersHn=∑i=1n1i≈ln⁡nH_n = \sum_{i=1}^{n} \frac{1}{i} \approx \ln n
Stirling's formulan!≈2πn(ne)nn! \approx \sqrt{2\pi n}\left(\frac{n}{e}\right)^n
Logarithm of the factoriallog⁡(n!)∈Θ(nlog⁡n)\log(n!) \in \Theta(n \log n)
  • log⁡2n\log_2 n counts how many times nn can be halved.
  • The base of a logarithm does not matter inside OO, but it does inside an exponent.

Induction, correctness and recurrences​

From Induction, Correctness and Recurrences:

  • Induction: base case plus inductive step. Strong induction may assume all smaller cases, which fits divide and conquer.
  • A recursive algorithm is correct if its base cases are correct, its combination is correct assuming the recursive calls are, and every call reaches a base case.
  • Loop invariants prove iterative algorithms: initialization, maintenance and termination.
  • Recurrences are solved by unrolling, the recursion tree, guess and verify (with explicit constants), or, for linear recurrences, characteristic roots.
Saved only in your browser
Was this lesson helpful?
Questions, or something wrong?

Errors, suggestions and public questions open a form on GitHub, visible to everyone.