0% found this document useful (0 votes)
25 views6 pages

Modelling Algorithm Growth Functions

The document discusses mathematical modeling of algorithm growth rates. It explains that algorithms can be modeled by functions that describe how resources like time increase with input size (n). Two examples are given: a linear search algorithm that runs in O(n) time, and an inversion counting algorithm that runs in O(n^2) time due to nested loops. Common growth rate functions are listed from constant to exponential. Graphs are used to visualize how different growth rates correspond to increasing algorithm complexity.

Uploaded by

Kutemwa Mithi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

Modelling Algorithm Growth Functions

The document discusses mathematical modeling of algorithm growth rates. It explains that algorithms can be modeled by functions that describe how resources like time increase with input size (n). Two examples are given: a linear search algorithm that runs in O(n) time, and an inversion counting algorithm that runs in O(n^2) time due to nested loops. Common growth rate functions are listed from constant to exponential. Graphs are used to visualize how different growth rates correspond to increasing algorithm complexity.

Uploaded by

Kutemwa Mithi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Modelling Algorith Growth

Functions
By
W.G. Gondwe
Lecturer, Computer Networks
CS&IT Department
Malawi University of Science & Technology
Mathematical Modelling & Fn Growth
rates
• Recall: Complexity (time), worst-case assumption
• Analysis of algorithms – predicting how much resources an
algorithm will consume
• Analysis of algorithms – rate of increase in complexity as a
function of input
• i.e. Need to model a function of the algorithm in terms of input
size (n)
Mathematical Modelling cont..
• Example 1:
Algorithm to search for item p in a list of n items:
Analysis:
Assuming step i takes ci time to execute,
for counter := 1 to n 1 then the total execution time is given by:
if list[counter] = p then 2
nc1 + nc2 + nc5 + k , where k is a constant
return counter 3
else 4 (ignoring the trivial steps)
counter := counter + 1 5
end if 6 = n(c1 + c2 + c5) + k
= c0n + k (where c0 = c1 + c2 + c5)
end for 7
i.e. the growth function for the algorithm
is given by c0n + k (linear function of n)
Mathematical Modelling cont..
• Example 2:
Counting number of inversions:
Given a list a of size n, the number of inversions is a measure
of how unsorted it is.
It is measured by counting all a[i] > a[j] where i < j

Brute force (simple) algorithm:

inv_count := 0 1
for i := 1 to n 2
for j := i+1 to n 3
if a[i] < a[j] then 4
inv_count := inv_count + 1 5
end if 6
end for 7
end for 8
Mathematical modeling – Growth rates
• Types of growth rates (functions)
Constant – f(n) = c
Linear - f(n) = cn
Log – f(n) = logb n
Log-linear - f(n) = n log n Increasing
Quadratic – f(n) = n2 + c complexity
Cubic – f(n) = n3 + c
Exponential – f(n) = cn
Factorial – f(n) = n!
Math modelling – growth rages

Graphical visualization of
algorithm complexities (growth
rates)

You might also like