Advertisements

Time Complexity & Space Complexity of Algorithm

Advertisements

The efficiency of an algorithm depends on two parameters:

  1. Time Complexity
  2. 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.

Also Read: What is Big-Omege Notation (Ω) & Big-Theta Notation (Θ)?

Types Of Time Complexity :

  1. 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.
  2. 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.
  3. Worst Time Complexity: Define the input for which the 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.
AlgorithmTime Complexity
   BestAverageWorst
Selection SortΩ(n^2)θ(n^2)O(n^2)
Bubble SortΩ(n)θ(n^2)O(n^2)
Insertion SortΩ(n)θ(n^2)O(n^2)
Heap SortΩ(n log(n))θ(n log(n))O(n log(n))
Quick SortΩ(n log(n))θ(n log(n))O(n^2)
Merge SortΩ(n log(n))θ(n log(n))O(n log(n))
In the above table, we have discussed the time complexity (Best, Average, and Worst) of Selection Sort, Bubble Sort, Insertion Sort, Heap Sort, Quick Sort, and Merge Sort.

Also Read: What is Asymptotic Notation & Big-Oh Notation?

Scroll to Top