03 Analysis of Algorithms

Updated 4 Oct 2026

Analysis Framework

  • “Analysis of algorithms” mean an investigation of an algorithm’s efficiency with respect to two resources: running time and memory space.
  • There are two kinds of efficiency:
    1. Time efficiency – how fast an algorithm runs.
    2. Space efficiency – how much memory an algorithm needs.

Measuring an input’s size

  • It is logical to investigate an algorithm’s efficiency as a function of some parameter nn indicating the algorithm’s input size
  • Selecting such a parameter is quite straightforward.
  • For example,
    • Sorting – An input size is the size of the list.
    • Find the largest element in the list of an array
    • Compute the sum of nn numbers.

Units for measuring running time

  • Units for measuring running time is to count the number of times the algorithm’s basic operations is executed.
  • The basic operation means the operation contributing the most to the total running time.
  • The basic operation is usually the most time-consuming operation in the algorithm’s innermost loop.
    • For example,
      • Sorting – the basic operation is key comparison.
T(n)≈copC(n)T(n)\approx c_{op}C(n)
  • TT = running time of an algorithm

  • nn = input size

  • copc_{op} = execution time of the basic operation

  • CC = number of times the basic operation is executed

  • How much longer will the algorithm run if we double its input size?

  • Assume that C(n)=12n(n−1)=12n2−12n≈12n2C(n)=\frac{1}{2}n(n-1)=\frac{1}{2}n^2-\frac{1}{2}n\approx\frac{1}{2}n^2

  • Therefore, T(2n)T(n)≈copC(2n)copC(n)≈12(2n)212n2=4\frac{T(2n)}{T(n)}\approx\frac{c_{op}C(2n)}{c_{op}C(n)}\approx\frac{\frac{1}{2}(2n)^2}{\frac{1}{2}n^2}=4

  • We were able to answer the question without actually knowing the value of copc_{op}

  • We concentrate on the count’s order of growth for large-size inputs.

Orders of growth

  • The magnitude of the numbers in the following table has a profound significance for the analysis of algorithms.
  • Algorithms that require an exponential number of operations are practical for solving only problems of very small size.
  • Basic asymptotic efficiency classes
ClassName
11constant
log⁡n\log nlogarithmic
nnlinear
nlog⁡nn \log nlinearithmic
n2n^2quadratic
n3n^3cubic
2n2^nexponential
n!n!factorial

Worst-case, best-case, and average-case

  • There are many algorithms for which running time depends not only on an input size but also on the specifics of a particular input.
  • The worst-case efficiency of an algorithm is its efficiency for the worst-case input of size nn, which is an input of size nn for which the algorithm runs the longest among all possible inputs of that size.
  • The best-case efficiency of an algorithm is its efficiency for the best-case input of size nn, which is an input of size nn for which the algorithm runs the fastest among all possible inputs of that size.
  • To analyze the algorithm’s average-case efficiency, we must make some assumptions about possible inputs of size nn.

Asymptotic notations

Analysis of Algorithms

Mathematical analysis of non-recursive algorithms

  • General plan for analyzing time efficiency of non-recursive algorithms:
    1. Decide on a parameter indicating an input’s size.
    2. Identify the algorithm’s basic operation.
    3. Check whether the number of times the basic operation is executed depends only on the size of an input.
      • How many times does the operation need to be executed.
    4. Set up a sum expressing the number of times the algorithm’s basic operation is executed.
    5. Using standard formulas and rules of sum manipulation, either find a closed form formula for the count or, at the very least, establish its order of growth.

Mathematical analysis of recursive algorithms