Algorithm Efficiency Last
Algorithm Efficiency Last
Algorithm Efficiency Last
Efficiency of Algorithms
Space Efficiency
For large quantities of data space/memory used should be
analyzed.
instruction space
data space
run-time stack space
Analysis of Time Complexity
Running time depends upon:
Compiler used
R/w speed to Memory and Disk
Machine Architecture : 32 bit vs 64
Input size (rate of growth of time)
When analyzing for time complexity we can take two approaches:
list_sum (A, n)
{
Cost # of times
Sum = 0 1 1
for i = 1 to n-1 2 n+1
sum = sum + A(i) 2 n
return sum 1 1
T(list_sum) = 4n + 4
RAM model is not realistic:
• Not all memory accesses take the same time (cache, main
memory, disk).
2n3+7n2+2000=Θ(n3)
Dropping lower order terms is always Ok since there will always be a n 0
after which Θ(n3) has higher values than Θn2) regardless of the constant.
Function Big-O Name
1 O(1) Constant
log n O(log n) logarithmic
n 1/2 O(n 1/2) Square Root
n O(n) linear
n log n O(n log n) n log n
n2 O(n2) quadratic
n3 O(n3) cubic
2n O(2n) exponential
nc O( n c) Polynomial
n! O(n!) factorial