Definition
Runtime
Types
Wort-case Runtime
Definition
Link to originalWorst-Case Complexity
Worst-case complexity is the greatest possible runtime of a program for a given input size .
Average-case Runtime
Definition
Link to originalAverage-case Runtime
Best-case Runtime
Definition
Link to originalBest-case Runtime
Best-case runtime is the smallest possible runtime of a program for a given input size .
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:
Statement | Constant Cost | Execution 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: