Learn about 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.
The time required for executing a code depends on several factors, such as:
- The number of operations performed in the program,
- The speed of the device, and also
- The speed of data transfer if being executed on an online platform.
So how can we determine which one is efficient? The answer is the use of asymptotic notation.
The following 3 asymptotic notations are mostly used to represent the time complexity of algorithms:
Big-O Notation (Ο) – Big-O notation specifically describes the worst-case scenario.
Omega Notation (Ω) – Omega(Ω) notation specifically describes the best-case scenario.
Theta Notation (θ) – This notation represents the average complexity of an algorithm.
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)
Below are the running Time complexity in terms of Big-O O(f(n))
O(n!) : Worst
O(nlogn) : Bad
O(n) : Fair
O(logn) : Good
O(1) : Best
No comments:
Post a Comment