Algorithm Efficiency and Summation Reference
Posted by Anonymous and classified in Mathematics
Written on in
English with a size of 561.4 KB
Analyzing Algorithm Efficiency
Exponential Recursive Calls
return f(n-1) + f(n-1)
❌ Very bad algorithm
Why: It results in an exponential number of calls and massive recomputation.
Better: Use iterative multiplication or fast exponentiation.
Recursive vs. Iterative Practice
S(n) = S(n-1) + n*n*n
⚠️ Same asymptotic cost as iterative, but worse in practice
Why: Recursion adds significant stack overhead.
Better: Use a loop or a closed-form formula.
Efficient Linear Algorithms
return Q(n-1) + 2*n - 1
✅ Efficient linear algorithm
Multiplications: Θ(n), Additions: Θ(n).
Why: There is no redundant computation.
Optimal Element Inspection
temp = recursive call
if temp <= A[n-1]
✅ Optimal
Why: You must look at every element; therefore, Θ(n) is unavoidable.
Improving Summation Performance
for i = 1 to n:
S += i*i
Last question answer (Improvement):
✅ Use formula → Θ(1)
n(n+1)(2n+1)/6
Optimizing Min-Max Comparisons
if A[i] < min
if A[i] > max
Last question answer (Improvement):
⚡ Compare elements in pairs
Why: Reduces comparisons from approximately 2n to 1.5n.
Class: Still Θ(n), but faster in practice.
Matrix Symmetry Lower Bounds
if A[i][j] != A[j][i]
❌ No improvement possible.
Why: You must check approximately n²/2 elements, leading to a Θ(n²) lower bound.
Common Summation Formulas and Orders
| Type | Summation | Closed Form / Result | Order |
|---|---|---|---|
| Basic | sum_{i=1..n} (a*i + b) | a*n*(n+1)/2 + b*n | Theta(n^2) |
| Basic | sum_{i=a..b} i | (a+b)*(b-a+1)/2 | Theta(b^2) |
| Geometric | sum_{i=0..n} r^i | (r^(n+1) - 1)/(r - 1) | Theta(r^n) |
| Geometric | sum_{i=1..n} r^i | (r^(n+1) - r)/(r - 1) | Theta(r^n) |
| Geometric | sum_{i=0..n-1} r^i | (r^n - 1)/(r - 1) | Theta(r^n) |
| Common | sum_{i=0..n} 2^i | 2^(n+1) - 1 | Theta(2^n) |
| Common | sum_{i=1..n} 2^i | 2^(n+1) - 2 | Theta(2^n) |
| Common | sum_{i=0..k} 2^(n-i) | 2^(n+1) - 2^(n-k) | Theta(2^n) |
| Common | sum_{i=1..n-1} i | (n-1)*n/2 | Theta(n^2) |
| Common | sum_{i=0..n-1} i | (n-1)*n/2 | Theta(n^2) |
| Common | sum_{i=1..n} (i+1) | n*(n+3)/2 | Theta(n^2) |
| Common | sum_{i=1..n} (i-1) | n*(n-1)/2 | Theta(n^2) |
| Common | sum_{i=a..b} (i+c) | sum i + c*(b-a+1) | Theta(b^2) |
| Double | sum_{i=1..n} sum_{j=1..n} 1 | n^2 | Theta(n^2) |
| Double | sum_{i=1..n} sum_{j=1..i} 1 | n*(n+1)/2 | Theta(n^2) |
| Double | sum_{i=1..n} sum_{j=i..n} 1 | n*(n+1)/2 | Theta(n^2) |
| Growth | sum_{i=1..n} i^k | — | Theta(n^(k+1)) |
| Growth | sum_{i=1..n} log(i) | — | Theta(n*log(n)) |
| Growth | sum_{i=1..n} (i^2 + 1) | Dominated by i^2 | Theta(n^3) |