Abstract
- Analysis space & time used, related with the input size and observing the trend when input size gets bigger
- The analysis isn’t limited to particular machine. It applies to all the machines
Asymptotic Analysis
Asymptotic
We only cares about what is the complexity when the input size is approaching Infinity (∞), that is where the name asymptotic comes from.
So when the actual input size in real world is small, the algorithms with worst time complexity may run fast!
- Asymptotic Analysis doesn’t return some good approximations of the time the program takes to run. We mean the time taken by the program bounded by some constant a function when the input size is bigger than a certain constant
- represents the upper bound
- represents the space in between upper bound and lower bound
- represents the lower bound
Determine tightest upper bound (in terms of )
- Take the most dominant term and drop the coefficients
- If 2 terms with multiplying each other, they are one piece
Use codes to find algorithm complexity analysis
We can write out the given program, then place a counter at the core part of the program. Then we can obtain the relationship by observing the value we substituted to the input and the value of the counter
Tricky ones to evaluate tightest upper bound!
- is wrong because isn’t a constant, is going to be a lower bound
- is the valid tightest upper bound. The next tightest upper bound is
, where ,
- Cant determine! Because the constant matters in the exponent here
- For example, when , then , when , then
- is significantly slower than !
- is wrong, because , the raises the complexity one magnitude. It isn’t same as in which we can ignore the constant
- The answer is , don’t have the math knowledge yet to further explain :(
Evaluate time complexity of if/else
Lets be the cost of first, and be the cost of second
Worst Space Complexity
- The Main Memory used relative to the input size
2 ways to count
Maximum space every allocated at one time
- The amount of space the algorithm needs to run
Total space ever allocated
- The total amount of space algorithm uses to run the algorithm. We need to consider this because memory allocation is an expensive operation
Worst Time Complexity
- The time it takes relative to the input size