complexity-theory

Definition

Runtime

Runtime is the number of steps required to execute a program or algorithm and is describe by a function for an input size .

Types

Wort-case Runtime

Definition

Worst-Case Complexity

Worst-case complexity is the greatest possible runtime of a program for a given input size .

Link to original

Average-case Runtime

Definition

Average-case Runtime

Average-case runtime is the average runtime of a program for a given input size .

Determining the average-case runtime might be troublesome since it depends on the distribution of the input size.

Link to original

Best-case Runtime

Definition

Best-case Runtime

Best-case runtime is the smallest possible runtime of a program for a given input size .

Link to original

Examples

Simple Example

Given the following simple Sum program:

Sum(A, x):
    sum <- 0
    for i <- 0 to n-1:
        if A[i] > x:
            sum <- sum + A[i]
    print(sum)

The algorithm consists of multiple statements with different constant costs:

StatementConstant CostExecution Count
sum <- 0
for i <- 0 to n
if A[i] > x
sum <- sum + A[i] with
print(sum)

The total cost of the algorithm is the sum of the constant costs weighted by the execution counts:

The best-case runtime with is:

The worst-case runtime with is: