Complexities
The primary motive to use DSA is to solve a problem effectively and efficiently. How can you decide if a program written by you is efficient or not? This is measured by complexities. Complexity is of two types:
- Time complexity: Time complexity is used to measure the amount of time required to execute the code.
- Space complexity: Space complexity means the amount of space required to execute successfully the functionalities of the code.
Asymptotic notation is a mathematical tool that calculates the required time in terms of input size and does not require the execution of the code.
It neglects the system-dependent constants and is related to only the number of modular operations being performed.
The following three asymptotic notations are mostly used to represent the time complexity of algorithms:
, which describes the worst-case scenario,
Omega notation (Ω
), which describes the best-case scenario, and
Theta notation (θ
), which gives the average complexity of an algorithm.
The above figure shows an example of the rates of growth of algorithms.
The most used notation in the analysis of a code is the Big-O notation which gives an upper bound of the running time of the code (or the amount of memory used in terms of input size).