Time Complexities of all Sorting Algorithms
The efficiency of an algorithm depends on two parameters:
- Time Complexity
- Space Complexity
Time Complexity:
Time Complexity is defined as the number of times a particular instruction set is executed rather than the total time taken. It is because the total time taken also depends on some external factors like the compiler used, the processor’s speed, etc.
Space Complexity:
Space Complexity is the total memory space required by the program for its execution.
Both are calculated as the function of input size(n). One important thing here is that despite these parameters, the efficiency of an algorithm also depends upon the nature and size of the input.
Types of Time Complexity :
- Best Time Complexity: Define the input for which the algorithm takes less time or minimum time. In the best case calculate the lower bound of an algorithm. Example: In the linear search when search data is present at the first location of large data then the best case occurs.
- Average Time Complexity: In the average case take all random inputs and calculate the computation time for all inputs.
And then we divide it by the total number of inputs.
- Worst Time Complexity: Define the input for which algorithm takes a long time or maximum time. In the worst calculate the upper bound of an algorithm. Example: In the linear search when search data is present at the last location of large data then the worst case occurs.
Following is a quick revision sheet that you may refer to at the last minute:
Also, see:
Last Updated :
22 Feb, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...