Algorithm Efficiency and Summation Reference

Posted by Anonymous and classified in Mathematics

Written on in English with a size of 561.4 KB

wEy5LO+xoY6eQAAAABJRU5ErkJggg==

ImokF9JhuUMxHZRjawPwLhoDlpdrWDyv8Pf+Ed+4PJuWIAAAAASUVORK5CYII=

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

TypeSummationClosed Form / ResultOrder
Basicsum_{i=1..n} (a*i + b)a*n*(n+1)/2 + b*nTheta(n^2)
Basicsum_{i=a..b} i(a+b)*(b-a+1)/2Theta(b^2)
Geometricsum_{i=0..n} r^i(r^(n+1) - 1)/(r - 1)Theta(r^n)
Geometricsum_{i=1..n} r^i(r^(n+1) - r)/(r - 1)Theta(r^n)
Geometricsum_{i=0..n-1} r^i(r^n - 1)/(r - 1)Theta(r^n)
Commonsum_{i=0..n} 2^i2^(n+1) - 1Theta(2^n)
Commonsum_{i=1..n} 2^i2^(n+1) - 2Theta(2^n)
Commonsum_{i=0..k} 2^(n-i)2^(n+1) - 2^(n-k)Theta(2^n)
Commonsum_{i=1..n-1} i(n-1)*n/2Theta(n^2)
Commonsum_{i=0..n-1} i(n-1)*n/2Theta(n^2)
Commonsum_{i=1..n} (i+1)n*(n+3)/2Theta(n^2)
Commonsum_{i=1..n} (i-1)n*(n-1)/2Theta(n^2)
Commonsum_{i=a..b} (i+c)sum i + c*(b-a+1)Theta(b^2)
Doublesum_{i=1..n} sum_{j=1..n} 1n^2Theta(n^2)
Doublesum_{i=1..n} sum_{j=1..i} 1n*(n+1)/2Theta(n^2)
Doublesum_{i=1..n} sum_{j=i..n} 1n*(n+1)/2Theta(n^2)
Growthsum_{i=1..n} i^kTheta(n^(k+1))
Growthsum_{i=1..n} log(i)Theta(n*log(n))
Growthsum_{i=1..n} (i^2 + 1)Dominated by i^2Theta(n^3)

Related entries: