we have some steps to construct an algorithms, In those steps analysis is the last one. But before start the Problem solving we need to study the analysis part very well then only we can see our algorithms works well or not.
To find optimized code we need two mater to consider.
- Time complexity
- Space Complexity
Our Target should be lesser Time complexity and lower space complexity. Nowadays Time is more important than space as we can configure extra space today. Time machine is not available now.
Asymptotic Notations:
- Big O -> Worst case scenario (Important
- Omega -> Best case scenario
- Theta -> Average case scenario
There are two types of analysis:
- A posterior Analysis - Depends on language, compiler and type of hardware used - Exact analysis
- A priory Analysis - Independent of language, compiler and type of hardware used - Approximate analysis - Big O
A priory Analysis:
Order of magnitude of a statement i.e A number of times any statement can run
Notes:
- A time complexity is loop only
- Not only loops, a single statement also considerable but we should consider always bigger numbers.
- If there is no loop, time complexity is O(1)
Complexity classes:
- Constant - O(1)
- Lograthemic - O(log n)
- Linear - O(n)
- Quadratic - O(n\square)
- Cubic - O(n3)
- Polynomial - O(nc)
- Exponential - O(Cn)