Math for algorithms

Math basics for algorithm

A.1 求和公式及其性质

\(\sum_{k=1}^n k^2 = \frac {n(n+1)(2n+1)}{6}\)  \(\sum_{k=1}^n k^3 = \frac { n^2(n+1)^2}{4}\)

\(\sum_{k=1}^n (ca_k+b_k) = c\sum_{k=1}^n a_k + \sum_{k=1}^n b_k\) \(\sum_{k=1}^n \Theta\left(f(k)\right) = \Theta \left( \sum_{k=1}^n f(k) \right)\)

\[\sum_{k=0}^n x^k = 1 + x + x^2 + \ldots + x^n = \frac {x^{n+1} -1} {x-1}\] \[\sum_{k=0}^{\infty} x^k = \frac {1} {x-1}\] \[H_n = 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \ldots + \frac{1}{n} = \sum_{k=1}^n \frac{1}{n} = \ln{n} + O(1)\] \[\sum_{k=0}^{\infty} kx^k = \frac {x} {(1-x)^2}\] \[\sum_{k=1}^{n} (a_k - a_{k-1}) = a_n - a_0\]

\(\sum_{k=0}^{n-1} (a_{k-1} - a_k) = a_0 - a_n\) \(\sum_{k=1}^{n-1} \frac{1}{k(k+1)} = \sum_{k=1}^{n-1} (\frac{1}{k} - \frac{1}{k+1}) = 1- \frac{1}{n}\)

A.2 确定求和时间的界

\[H_n = \sum_{k=1}^n \frac{1}{n} = 1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \ldots + \frac{1}{n} \leq \ln{n} + 1\]

重点

PERM(A, k)
  if(k == n)
    PRINT(A)
  for i = 1 to n 
    SWAP(A, i, k)
    PERM(A, k+1)
    SWAP(A, i, k)


PERM(A, 1)