Professional Documents
Culture Documents
Algorithms
• It is more difficult to analyze the average case than the worst case
• In case of linear search, equal probabilities are assigned to all array slots i.e. the key is equally
likely in any array slot
• Assuming that key has equal probability 1/n of being in any position, and unit cost is c, the average
running time is given by
1c.1/n+2c.1/n+3c.1/n+….+nc.1/n=c/n(1+2+….+n)=cn(n+1)/2n= c(n+1)/2
Complexity Analysis (contd…)
• Average case analysis
A(n)=c(n+1)/2
Worst-case and average-case analysis are done much more often than best-
case analysis
Order of Growth
• We require some simplifying assumptions to ease our analysis
• For large inputs, the multiplicative constants and lower order terms are
dominated by effects of input size
• When we are looking at input sizes that are large enough to make only order of
growth of the running time relevant, we are studying asymptotic efficiency of
algorithms
• We are concerned with how running time of an algorithm increases with the size
of the input in the limit
Asymptotic
• Definition
• line that continually approaches a given
curve but does not meet it at any finite
distance.
• Example
• x is asymptotic with x + 1